Search in sources :

Example 1 with StudentProfileAttributes

use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.

the class InstructorStudentRecordsPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor3OfCourse1");
    StudentAttributes student = typicalBundle.students.get("student2InCourse1");
    String instructorId = instructor.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Invalid parameters");
    // no params
    verifyAssumptionFailure();
    // null courseId
    String[] invalidParams = new String[] { Const.ParamsNames.STUDENT_EMAIL, student.email };
    verifyAssumptionFailure(invalidParams);
    // null student email
    invalidParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId };
    verifyAssumptionFailure(invalidParams);
    // student not in course
    String studentEmailOfStudent1InCourse2 = typicalBundle.students.get("student1InCourse2").email;
    invalidParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.STUDENT_EMAIL, studentEmailOfStudent1InCourse2 };
    RedirectResult redirect = getRedirectResult(getAction(invalidParams));
    AssertHelper.assertContains(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, redirect.getDestinationWithParams());
    AssertHelper.assertContains(Const.StatusMessages.STUDENT_NOT_FOUND_FOR_RECORDS, redirect.getStatusMessage());
    ______TS("Typical case: student has some records and has profile");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.STUDENT_EMAIL, student.email };
    InstructorStudentRecordsPageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS, false, "idOfInstructor3"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    InstructorStudentRecordsPageData actualData = (InstructorStudentRecordsPageData) r.data;
    StudentProfileAttributes expectedProfile = StudentProfileAttributes.builder(student.googleId).build();
    expectedProfile.modifiedDate = actualData.spa.modifiedDate;
    expectedProfile.pictureKey = actualData.spa.pictureKey;
    assertEquals(instructorId, actualData.account.googleId);
    assertEquals(instructor.courseId, actualData.getCourseId());
    assertEquals(6, actualData.getSessionNames().size());
    assertEquals(student.googleId, actualData.spa.googleId);
    String expectedLogMessage = "TEAMMATESLOG|||instructorStudentRecordsPage|||instructorStudentRecordsPage" + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3" + "|||instr3@course1n2.tmt|||instructorStudentRecords Page Load<br>" + "Viewing <span class=\"bold\">" + student.email + "'s</span> records " + "for Course <span class=\"bold\">[" + instructor.courseId + "]</span><br>" + "Number of sessions: 6<br>" + "Student Profile: " + SanitizationHelper.sanitizeForHtmlTag(expectedProfile.toString()) + "|||/page/instructorStudentRecordsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("Typical case: instructor cannot view sections");
    instructor = typicalBundle.instructors.get("helperOfCourse1");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.STUDENT_EMAIL, student.email };
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS, false, "idOfHelperOfCourse1"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("Normally, we would show the student’s profile here. " + "However, you do not have access to view this student's profile<br>" + "No records were found for this student", r.getStatusMessage());
    ______TS("Typical case: student has no records, no profiles");
    String instructor4Id = typicalBundle.instructors.get("instructor4").googleId;
    // re-login as another instructor for new test
    gaeSimulation.loginAsInstructor(instructor4Id);
    String courseIdWithNoSession = "idOfCourseNoEvals";
    StudentAttributes testStudent = createStudentInTypicalDataBundleForCourseWithNoSession();
    String[] submissionParamsWithNoSession = new String[] { Const.ParamsNames.COURSE_ID, courseIdWithNoSession, Const.ParamsNames.STUDENT_EMAIL, "emailTemp@gmail.tmt" };
    InstructorStudentRecordsPageAction aWithNoSession = getAction(submissionParamsWithNoSession);
    ShowPageResult rWithNoSession = getShowPageResult(aWithNoSession);
    List<String> expectedMessages = new ArrayList<>();
    expectedMessages.add("No records were found for this student");
    expectedMessages.add(Const.StatusMessages.STUDENT_NOT_JOINED_YET_FOR_RECORDS);
    AssertHelper.assertContains(expectedMessages, rWithNoSession.getStatusMessage());
    ______TS("Typical case: student has profile but no records");
    testStudent.googleId = "valid.no.sessions";
    StudentsLogic.inst().updateStudentCascadeWithoutDocument(testStudent.email, testStudent);
    logic.createAccount(testStudent.googleId, testStudent.name, false, testStudent.email, "valid institute");
    a = getAction(submissionParamsWithNoSession);
    r = getShowPageResult(a);
    AssertHelper.assertContains("No records were found for this student", r.getStatusMessage());
    ______TS("Typical case: student has profile with script injection");
    instructor = typicalBundle.instructors.get("instructor1OfTestingSanitizationCourse");
    instructorId = instructor.googleId;
    String studentId = "student1InTestingSanitizationCourse";
    student = typicalBundle.students.get(studentId);
    expectedProfile = typicalBundle.accounts.get(studentId).studentProfile;
    gaeSimulation.loginAsInstructor(instructorId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.STUDENT_EMAIL, student.email };
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    actualData = (InstructorStudentRecordsPageData) r.data;
    expectedProfile.modifiedDate = actualData.spa.modifiedDate;
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS, false, instructorId), r.getDestinationWithParams());
    assertFalse(r.isError);
    expectedLogMessage = "TEAMMATESLOG|||instructorStudentRecordsPage|||instructorStudentRecordsPage" + "|||true|||Instructor|||Instructor&lt;script&gt; alert(&#39;hi!&#39;); &lt;&#x2f;script&gt;" + "|||" + instructorId + "|||instructor1@sanitization.tmt|||instructorStudentRecords Page Load<br>" + "Viewing <span class=\"bold\">" + student.email + "'s</span> records " + "for Course <span class=\"bold\">[" + instructor.courseId + "]</span><br>" + "Number of sessions: 1<br>" + "Student Profile: " + SanitizationHelper.sanitizeForHtmlTag(expectedProfile.toString()) + "|||/page/instructorStudentRecordsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) InstructorStudentRecordsPageAction(teammates.ui.controller.InstructorStudentRecordsPageAction) RedirectResult(teammates.ui.controller.RedirectResult) ArrayList(java.util.ArrayList) InstructorStudentRecordsPageData(teammates.ui.pagedata.InstructorStudentRecordsPageData) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 2 with StudentProfileAttributes

use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.

the class AccountAttributesTest method createInvalidAccountAttributesObject.

private AccountAttributes createInvalidAccountAttributesObject() {
    String googleId = "invalid google id";
    // invalid name
    String name = "";
    boolean isInstructor = false;
    String email = "invalid@email@com";
    String institute = StringHelperExtension.generateStringOfLength(FieldValidator.INSTITUTE_NAME_MAX_LENGTH + 1);
    StudentProfileAttributes studentProfile = StudentProfileAttributes.builder(googleId).build();
    return AccountAttributes.builder().withGoogleId(googleId).withName(name).withEmail(email).withInstitute(institute).withIsInstructor(isInstructor).withStudentProfileAttributes(studentProfile).build();
}
Also used : StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Example 3 with StudentProfileAttributes

use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.

the class StudentProfilePageUiTest method testActions.

private void testActions() {
    // assumes it is run after NavLinks Test
    // (ie already logged in as studentWithExistingProfile
    String studentGoogleId = testData.accounts.get("studentWithExistingProfile").googleId;
    ______TS("Typical case: no picture");
    profilePage.editProfileThroughUi("short.name", "e@email.tmt", "inst", "Singaporean", "male", "this is enough!$%&*</>");
    profilePage.ensureProfileContains("short.name", "e@email.tmt", "inst", "Singaporean", "male", "this is enough!$%&*</>");
    profilePage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.STUDENT_PROFILE_EDITED);
    ______TS("Typical case: attempted script injection");
    StudentProfileAttributes spa = StudentProfileAttributes.builder("valid.id").withShortName("name<script>alert(\"Hello world!\");</script>").withEmail("e@email.tmt").withGender("male").withMoreInfo("this is enough!$%&*</><script>alert(\"Hello world!\");</script>").withInstitute("inst<script>alert(\"Hello world!\");</script>").withNationality("American").build();
    profilePage.editProfileThroughUi(spa.shortName, spa.email, spa.institute, spa.nationality, spa.gender, spa.moreInfo);
    profilePage.ensureProfileContains("name<script>alert(\"Hello world!\");</script>", "e@email.tmt", "inst<script>alert(\"Hello world!\");</script>", "American", "male", "this is enough!$%&*</><script>alert(\"Hello world!\");</script>");
    profilePage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.STUDENT_PROFILE_EDITED);
    ______TS("Typical case: changing genders for complete coverage");
    profilePage.editProfileThroughUi("short.name", "e@email.tmt", "inst", "American", "other", "this is enough!$%&*</>");
    profilePage.ensureProfileContains("short.name", "e@email.tmt", "inst", "American", "other", "this is enough!$%&*</>");
    profilePage.editProfileThroughUi("short.name", "e@email.tmt", "inst", "American", "female", "this is enough!$%&*</>");
    profilePage.ensureProfileContains("short.name", "e@email.tmt", "inst", "American", "female", "this is enough!$%&*</>");
    ______TS("Failure case: invalid institute with attempted script injection");
    spa = StudentProfileAttributes.builder("valid.id").withShortName("short.name").withEmail("e@email.tmt").withGender("male").withMoreInfo("this is enough!$%&*</>").withInstitute("<script>alert(\"Hello world!\");</script>").withNationality("American").build();
    profilePage.editProfileThroughUi(spa.shortName, spa.email, spa.institute, spa.nationality, spa.gender, spa.moreInfo);
    profilePage.ensureProfileContains("short.name", "e@email.tmt", "inst", "American", "female", "this is enough!$%&*</>");
    profilePage.waitForTextsForAllStatusMessagesToUserEquals(StringHelper.toString(spa.getInvalidityInfo(), " ").replace("&lt;", "<").replace("&gt;", ">").replace("&quot;", "\"").replace("&#x2f;", "/"));
    ______TS("Failure case: invalid data");
    spa = StudentProfileAttributes.builder("valid.id").withShortName("$$short.name").withEmail("e@email.tmt").withGender("male").withMoreInfo("this is enough!$%&*</>").withInstitute(" inst  ").withNationality("American").build();
    profilePage.editProfileThroughUi(spa.shortName, spa.email, spa.institute, spa.nationality, spa.gender, spa.moreInfo);
    profilePage.ensureProfileContains("short.name", "e@email.tmt", "inst", "American", "female", "this is enough!$%&*</>");
    profilePage.waitForTextsForAllStatusMessagesToUserEquals(StringHelper.toString(spa.getInvalidityInfo(), " "));
    ______TS("Typical case: picture upload and edit");
    profilePage.fillProfilePic("src/test/resources/images/profile_pic.png");
    profilePage.uploadPicture();
    profilePage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.STUDENT_PROFILE_PICTURE_SAVED);
    profilePage.waitForUploadEditModalVisible();
    profilePage.editProfilePhoto();
    profilePage.ensureProfileContains("short.name", "e@email.tmt", "inst", "American", "female", "this is enough!$%&*</>");
    profilePage.verifyPhotoSize(150, 150);
    String prevPictureKey = BackDoor.getStudentProfile(studentGoogleId).pictureKey;
    verifyPictureIsPresent(prevPictureKey);
    ______TS("Typical case: repeated edit");
    profilePage.showPictureEditor();
    profilePage.editProfilePhoto();
    profilePage.ensureProfileContains("short.name", "e@email.tmt", "inst", "American", "female", "this is enough!$%&*</>");
    profilePage.verifyPhotoSize(150, 150);
    prevPictureKey = BackDoor.getStudentProfile(studentGoogleId).pictureKey;
    verifyPictureIsPresent(prevPictureKey);
    ______TS("Failure case: not a picture");
    profilePage.fillProfilePic("src/test/resources/images/not_a_picture.txt");
    profilePage.uploadPicture();
    profilePage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.STUDENT_PROFILE_NOT_A_PICTURE);
    verifyPictureIsPresent(prevPictureKey);
    ______TS("Failure case: picture too large");
    profilePage.fillProfilePic("src/test/resources/images/profile_pic_too_large.jpg");
    profilePage.uploadPicture();
    profilePage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.STUDENT_PROFILE_PIC_TOO_LARGE);
    verifyPictureIsPresent(prevPictureKey);
    ______TS("Typical case: update picture (too tall)");
    profilePage.fillProfilePic("src/test/resources/images/image_tall.jpg");
    profilePage.uploadPicture();
    profilePage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.STUDENT_PROFILE_PICTURE_SAVED);
    profilePage.waitForUploadEditModalVisible();
    profilePage.verifyPhotoSize(3074, 156);
    String currentPictureKey = BackDoor.getStudentProfile(studentGoogleId).pictureKey;
    verifyPictureIsPresent(currentPictureKey);
}
Also used : StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Example 4 with StudentProfileAttributes

use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.

the class StudentProfileEditSaveActionTest method getProfileAttributesFrom.

private StudentProfileAttributes getProfileAttributesFrom(String googleId, String[] submissionParams) {
    StudentProfileAttributes spa = StudentProfileAttributes.builder(googleId).build();
    spa.shortName = StringHelper.trimIfNotNull(submissionParams[1]);
    spa.email = StringHelper.trimIfNotNull(submissionParams[3]);
    spa.institute = StringHelper.trimIfNotNull(submissionParams[5]);
    spa.nationality = StringHelper.trimIfNotNull(submissionParams[7]);
    spa.gender = StringHelper.trimIfNotNull(submissionParams[9]);
    spa.moreInfo = StringHelper.trimIfNotNull(submissionParams[11]);
    spa.modifiedDate = null;
    return spa;
}
Also used : StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Example 5 with StudentProfileAttributes

use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.

the class StudentProfileEditSaveActionTest method testActionInMasqueradeMode.

private void testActionInMasqueradeMode(AccountAttributes student) {
    ______TS("Typical case: masquerade mode");
    gaeSimulation.loginAsAdmin("admin.user");
    String[] submissionParams = createValidParamsForProfile();
    StudentProfileAttributes expectedProfile = getProfileAttributesFrom(student.googleId, submissionParams);
    expectedProfile.googleId = student.googleId;
    StudentProfileEditSaveAction action = getAction(addUserIdToParams(student.googleId, submissionParams));
    RedirectResult result = getRedirectResult(action);
    assertFalse(result.isError);
    assertEquals(Const.StatusMessages.STUDENT_PROFILE_EDITED, result.getStatusMessage());
    AssertHelper.assertContains(getPageResultDestination(Const.ActionURIs.STUDENT_PROFILE_PAGE, false, student.googleId), result.getDestinationWithParams());
    verifyLogMessage(student, action, expectedProfile, true);
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) StudentProfileEditSaveAction(teammates.ui.controller.StudentProfileEditSaveAction) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Aggregations

StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)45 Test (org.testng.annotations.Test)15 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)11 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)7 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)6 BlobKey (com.google.appengine.api.blobstore.BlobKey)5 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)5 RedirectResult (teammates.ui.controller.RedirectResult)5 ArrayList (java.util.ArrayList)4 InvalidParametersException (teammates.common.exception.InvalidParametersException)4 StatusMessage (teammates.common.util.StatusMessage)4 StudentProfile (teammates.storage.entity.StudentProfile)4 StudentProfileEditSaveAction (teammates.ui.controller.StudentProfileEditSaveAction)4 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)3 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)3 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)3 Text (com.google.appengine.api.datastore.Text)2 ShowPageResult (teammates.ui.controller.ShowPageResult)2 InstructorStudentRecordsPageData (teammates.ui.pagedata.InstructorStudentRecordsPageData)2 Key (com.googlecode.objectify.Key)1