Search in sources :

Example 26 with StudentProfileAttributes

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

the class StudentsLogicTest method testGetStudentProfile.

private void testGetStudentProfile() throws Exception {
    StudentAttributes student1InCourse1 = dataBundle.students.get("student1InCourse1");
    AccountAttributes student1 = dataBundle.accounts.get("student1InCourse1");
    ______TS("success: default profile");
    StudentProfileAttributes actualSpa = studentsLogic.getStudentProfile(student1InCourse1.googleId);
    StudentProfileAttributes expectedSpa = student1.studentProfile;
    // fill-in auto-generated and default values
    expectedSpa.institute = actualSpa.institute;
    expectedSpa.modifiedDate = actualSpa.modifiedDate;
    assertEquals(expectedSpa.toString(), actualSpa.toString());
    ______TS("success: edited profile");
    StudentProfileAttributes expectedStudentProfile = StudentProfileAttributes.builder(student1.googleId).build();
    expectedStudentProfile.shortName = "short";
    expectedStudentProfile.email = "personal@email.tmt";
    expectedStudentProfile.institute = "institute";
    expectedStudentProfile.nationality = "Angolan";
    expectedStudentProfile.gender = "female";
    expectedStudentProfile.moreInfo = "This sentence may sound sound but it cannot make actual sound... :P";
    student1.studentProfile = expectedStudentProfile;
    accountsLogic.updateAccount(student1, true);
    StudentProfileAttributes actualStudentProfile = studentsLogic.getStudentProfile(student1InCourse1.googleId);
    expectedStudentProfile.modifiedDate = actualStudentProfile.modifiedDate;
    assertEquals(expectedStudentProfile.toString(), actualStudentProfile.toString());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 27 with StudentProfileAttributes

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

the class CoursesLogicTest method testGetCourseSummaryWithoutStats.

private void testGetCourseSummaryWithoutStats() throws Exception {
    ______TS("typical case");
    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    CourseSummaryBundle courseSummary = coursesLogic.getCourseSummaryWithoutStats(course.getId());
    assertEquals(course.getId(), courseSummary.course.getId());
    assertEquals(course.getName(), courseSummary.course.getName());
    ______TS("course without students");
    StudentProfileAttributes spa = StudentProfileAttributes.builder("instructor1").build();
    AccountsLogic.inst().createAccount(AccountAttributes.builder().withGoogleId("instructor1").withName("Instructor 1").withEmail("instructor@email.tmt").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(spa).build());
    coursesLogic.createCourseAndInstructor("instructor1", "course1", "course 1", "America/Los_Angeles");
    courseSummary = coursesLogic.getCourseSummaryWithoutStats("course1");
    assertEquals("course1", courseSummary.course.getId());
    assertEquals("course 1", courseSummary.course.getName());
    assertEquals("America/Los_Angeles", courseSummary.course.getTimeZone().getId());
    coursesLogic.deleteCourseCascade("course1");
    accountsDb.deleteAccount("instructor1");
    ______TS("non-existent");
    try {
        coursesLogic.getCourseSummaryWithoutStats("non-existent-course");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("The course does not exist:", e.getMessage());
    }
    ______TS("null parameter");
    try {
        coursesLogic.getCourseSummaryWithoutStats((CourseAttributes) null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
    try {
        coursesLogic.getCourseSummaryWithoutStats((String) null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : CourseSummaryBundle(teammates.common.datatransfer.CourseSummaryBundle) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 28 with StudentProfileAttributes

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

the class CoursesLogicTest method testGetTeamsForCourse.

private void testGetTeamsForCourse() throws Exception {
    ______TS("typical case");
    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    List<TeamDetailsBundle> teams = coursesLogic.getTeamsForCourse(course.getId());
    assertEquals(2, teams.size());
    assertEquals("Team 1.1</td></div>'\"", teams.get(0).name);
    assertEquals("Team 1.2", teams.get(1).name);
    ______TS("course without students");
    StudentProfileAttributes spa = StudentProfileAttributes.builder("instructor1").build();
    AccountsLogic.inst().createAccount(AccountAttributes.builder().withGoogleId("instructor1").withName("Instructor 1").withEmail("instructor@email.tmt").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(spa).build());
    coursesLogic.createCourseAndInstructor("instructor1", "course1", "course 1", "UTC");
    teams = coursesLogic.getTeamsForCourse("course1");
    assertEquals(0, teams.size());
    coursesLogic.deleteCourseCascade("course1");
    accountsDb.deleteAccount("instructor1");
    ______TS("non-existent");
    try {
        coursesLogic.getTeamsForCourse("non-existent-course");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("does not exist", e.getMessage());
    }
    ______TS("null parameter");
    try {
        coursesLogic.getTeamsForCourse(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 29 with StudentProfileAttributes

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

the class AccountsDbTest method testCreateAccount.

@Test
public void testCreateAccount() throws Exception {
    ______TS("typical success case (legacy data)");
    AccountAttributes a = AccountAttributes.builder().withGoogleId("test.account").withName("Test account Name").withIsInstructor(false).withEmail("fresh-account@email.com").withInstitute("TEAMMATES Test Institute 1").build();
    a.studentProfile = null;
    accountsDb.createAccount(a);
    ______TS("success case: duplicate account");
    StudentProfileAttributes spa = StudentProfileAttributes.builder(a.googleId).build();
    spa.shortName = "test acc na";
    spa.email = "test@personal.com";
    spa.gender = Const.GenderTypes.MALE;
    spa.nationality = "American";
    spa.institute = "institute";
    spa.moreInfo = "this is more info";
    spa.googleId = a.googleId;
    a.studentProfile = spa;
    accountsDb.createAccount(a);
    ______TS("test persistence of latest entry");
    AccountAttributes accountDataTest = accountsDb.getAccount(a.googleId, true);
    assertEquals(spa.shortName, accountDataTest.studentProfile.shortName);
    assertEquals(spa.gender, accountDataTest.studentProfile.gender);
    assertEquals(spa.institute, accountDataTest.studentProfile.institute);
    assertEquals(a.institute, accountDataTest.institute);
    assertEquals(spa.email, accountDataTest.studentProfile.email);
    assertFalse(accountDataTest.isInstructor);
    // Change a field
    accountDataTest.isInstructor = true;
    accountDataTest.studentProfile.gender = Const.GenderTypes.FEMALE;
    accountsDb.createAccount(accountDataTest);
    // Re-retrieve
    accountDataTest = accountsDb.getAccount(a.googleId, true);
    assertTrue(accountDataTest.isInstructor);
    assertEquals(Const.GenderTypes.FEMALE, accountDataTest.studentProfile.gender);
    accountsDb.deleteAccount(a.googleId);
    // Should we not allow empty fields?
    ______TS("failure case: invalid parameter");
    a.email = "invalid email";
    try {
        accountsDb.createAccount(a);
        signalFailureToDetectException(" - InvalidParametersException");
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, "invalid email", FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH), e.getMessage());
    }
    ______TS("failure: null parameter");
    try {
        accountsDb.createAccount(null);
        signalFailureToDetectException(" - AssertionError");
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) Test(org.testng.annotations.Test)

Example 30 with StudentProfileAttributes

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

the class StudentProfileAttributesTest method testInvalidityInfoForInvalidProfile.

private void testInvalidityInfoForInvalidProfile() throws Exception {
    StudentProfileAttributes invalidProfile = getInvalidStudentProfileAttributes();
    ______TS("Failure case: invalid profile attributes");
    assertFalse("'invalidProfile' indicated as valid", invalidProfile.isValid());
    List<String> expectedErrorMessages = generatedExpectedErrorMessages(invalidProfile);
    AssertHelper.assertSameContentIgnoreOrder(expectedErrorMessages, invalidProfile.getInvalidityInfo());
}
Also used : 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