Search in sources :

Example 31 with StudentProfileAttributes

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

the class StudentProfileAttributesTest method testSanitizeForSaving.

@Test
public void testSanitizeForSaving() {
    StudentProfileAttributes profileToSanitize = getStudentProfileAttributesToSanitize();
    StudentProfileAttributes profileToSanitizeExpected = getStudentProfileAttributesToSanitize();
    profileToSanitize.sanitizeForSaving();
    assertEquals(SanitizationHelper.sanitizeGoogleId(profileToSanitizeExpected.googleId), profileToSanitize.googleId);
    assertEquals(profileToSanitizeExpected.shortName, profileToSanitize.shortName);
    assertEquals(profileToSanitizeExpected.institute, profileToSanitize.institute);
    assertEquals(profileToSanitizeExpected.email, profileToSanitize.email);
    assertEquals(profileToSanitizeExpected.nationality, profileToSanitize.nationality);
    assertEquals(profileToSanitizeExpected.gender, profileToSanitize.gender);
    assertEquals(profileToSanitizeExpected.moreInfo, profileToSanitize.moreInfo);
    assertEquals(profileToSanitizeExpected.pictureKey, profileToSanitize.pictureKey);
}
Also used : StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) Test(org.testng.annotations.Test)

Example 32 with StudentProfileAttributes

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

the class StudentProfileAttributesTest method testBuilderWithDefaultOptionalValues.

@Test
public void testBuilderWithDefaultOptionalValues() {
    StudentProfileAttributes profileAttributes = StudentProfileAttributes.builder(VALID_GOOGLE_ID).build();
    assertIsDefaultValues(profileAttributes);
}
Also used : StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) Test(org.testng.annotations.Test)

Example 33 with StudentProfileAttributes

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

the class StudentProfileAttributesTest method testGetInvalidityInfoForValidProfileWithValues.

private void testGetInvalidityInfoForValidProfileWithValues() {
    StudentProfileAttributes validProfile = profile.getCopy();
    ______TS("Typical case: valid profile attributes");
    assertTrue("'validProfile' indicated as invalid", validProfile.isValid());
    assertEquals(new ArrayList<String>(), validProfile.getInvalidityInfo());
}
Also used : StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Example 34 with StudentProfileAttributes

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

the class StudentProfileAttributesTest method testValueOf.

@Test
public void testValueOf() {
    StudentProfile studentProfile = new StudentProfile("id", "Joe", "joe@gmail.com", "Teammates Institute", "American", "male", new Text("hello"), new BlobKey("key"));
    StudentProfileAttributes profileAttributes = StudentProfileAttributes.valueOf(studentProfile);
    assertEquals(studentProfile.getGoogleId(), profileAttributes.googleId);
    assertEquals(studentProfile.getShortName(), profileAttributes.shortName);
    assertEquals(studentProfile.getEmail(), profileAttributes.email);
    assertEquals(studentProfile.getInstitute(), profileAttributes.institute);
    assertEquals(studentProfile.getNationality(), profileAttributes.nationality);
    assertEquals(studentProfile.getGender(), profileAttributes.gender);
    assertEquals(studentProfile.getMoreInfo().getValue(), profileAttributes.moreInfo);
    assertEquals(studentProfile.getPictureKey().getKeyString(), profileAttributes.pictureKey);
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) BlobKey(com.google.appengine.api.blobstore.BlobKey) Text(com.google.appengine.api.datastore.Text) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) Test(org.testng.annotations.Test)

Example 35 with StudentProfileAttributes

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

the class AccountsLogicTest method testJoinCourseForStudent.

@Test
public void testJoinCourseForStudent() throws Exception {
    String correctStudentId = "correctStudentId";
    String courseId = "idOfTypicalCourse1";
    String originalEmail = "original@email.com";
    // Create correct student with original@email.com
    StudentAttributes studentData = StudentAttributes.builder(courseId, "name", originalEmail).withSection("sectionName").withTeam("teamName").withComments("").build();
    studentsLogic.createStudentCascadeWithoutDocument(studentData);
    studentData = StudentsLogic.inst().getStudentForEmail(courseId, originalEmail);
    verifyPresentInDatastore(studentData);
    ______TS("failure: wrong key");
    try {
        accountsLogic.joinCourseForStudent(StringHelper.encrypt("wrongkey"), correctStudentId);
        signalFailureToDetectException();
    } catch (JoinCourseException e) {
        assertEquals("You have used an invalid join link: %s", e.getMessage());
    }
    ______TS("failure: invalid parameters");
    try {
        accountsLogic.joinCourseForStudent(StringHelper.encrypt(studentData.key), "wrong student");
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains(FieldValidator.REASON_INCORRECT_FORMAT, e.getMessage());
    }
    ______TS("failure: googleID belongs to an existing student in the course");
    String existingId = "AccLogicT.existing.studentId";
    StudentAttributes existingStudent = StudentAttributes.builder(courseId, "name", "differentEmail@email.com").withSection("sectionName").withTeam("teamName").withComments("").withGoogleId(existingId).build();
    studentsLogic.createStudentCascadeWithoutDocument(existingStudent);
    try {
        accountsLogic.joinCourseForStudent(StringHelper.encrypt(studentData.key), existingId);
        signalFailureToDetectException();
    } catch (JoinCourseException e) {
        assertEquals(String.format(Const.StatusMessages.JOIN_COURSE_GOOGLE_ID_BELONGS_TO_DIFFERENT_USER, existingId), e.getMessage());
    }
    ______TS("success: without encryption and account already exists");
    StudentProfileAttributes spa = StudentProfileAttributes.builder(correctStudentId).withInstitute("TEAMMATES Test Institute 1").build();
    AccountAttributes accountData = AccountAttributes.builder().withGoogleId(correctStudentId).withName("nameABC").withEmail("real@gmail.com").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(spa).build();
    accountsLogic.createAccount(accountData);
    accountsLogic.joinCourseForStudent(StringHelper.encrypt(studentData.key), correctStudentId);
    studentData.googleId = accountData.googleId;
    verifyPresentInDatastore(studentData);
    assertEquals(correctStudentId, logic.getStudentForEmail(studentData.course, studentData.email).googleId);
    ______TS("failure: already joined");
    try {
        accountsLogic.joinCourseForStudent(StringHelper.encrypt(studentData.key), correctStudentId);
        signalFailureToDetectException();
    } catch (JoinCourseException e) {
        assertEquals("You (" + correctStudentId + ") have already joined this course", e.getMessage());
    }
    ______TS("failure: valid key belongs to a different user");
    try {
        accountsLogic.joinCourseForStudent(StringHelper.encrypt(studentData.key), "wrongstudent");
        signalFailureToDetectException();
    } catch (JoinCourseException e) {
        assertEquals("The join link used belongs to a different user whose " + "Google ID is corre..dentId (only part of the Google ID is " + "shown to protect privacy). If that Google ID is owned by you, " + "please logout and re-login using that Google account. " + "If it doesn’t belong to you, please " + "<a href=\"mailto:" + Config.SUPPORT_EMAIL + "?" + "body=Your name:%0AYour course:%0AYour university:\">" + "contact us</a> so that we can investigate.", e.getMessage());
    }
    ______TS("success: with encryption and new account to be created");
    logic.deleteAccount(correctStudentId);
    originalEmail = "email2@gmail.com";
    studentData = StudentAttributes.builder(courseId, "name", originalEmail).withSection("sectionName").withTeam("teamName").withComments("").build();
    studentsLogic.createStudentCascadeWithoutDocument(studentData);
    studentData = StudentsLogic.inst().getStudentForEmail(courseId, originalEmail);
    String encryptedKey = StringHelper.encrypt(studentData.key);
    accountsLogic.joinCourseForStudent(encryptedKey, correctStudentId);
    studentData.googleId = correctStudentId;
    verifyPresentInDatastore(studentData);
    assertEquals(correctStudentId, logic.getStudentForEmail(studentData.course, studentData.email).googleId);
    // check that we have the corresponding new account created.
    accountData.googleId = correctStudentId;
    accountData.email = originalEmail;
    accountData.name = "name";
    accountData.isInstructor = false;
    verifyPresentInDatastore(accountData);
    ______TS("success: join course as student does not revoke instructor status");
    // promote account to instructor
    accountsLogic.makeAccountInstructor(correctStudentId);
    // make the student 'unregistered' again
    studentData.googleId = "";
    studentsLogic.updateStudentCascadeWithoutDocument(studentData.email, studentData);
    assertEquals("", logic.getStudentForEmail(studentData.course, studentData.email).googleId);
    // rejoin
    logic.joinCourseForStudent(encryptedKey, correctStudentId);
    assertEquals(correctStudentId, logic.getStudentForEmail(studentData.course, studentData.email).googleId);
    // check if still instructor
    assertTrue(logic.isInstructor(correctStudentId));
    accountsLogic.deleteAccountCascade(correctStudentId);
    accountsLogic.deleteAccountCascade(existingId);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) JoinCourseException(teammates.common.exception.JoinCourseException) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) Test(org.testng.annotations.Test)

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