Search in sources :

Example 51 with AccountAttributes

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

the class ProfilesLogicTest method testStudentProfileFunctions.

@Test
public void testStudentProfileFunctions() throws Exception {
    // 4 functions are tested together as:
    // => The functions are very simple (one-liners)
    // => They are fundamentally related and easily tested together
    // => It saves time during tests
    ______TS("get SP");
    StudentProfileAttributes expectedSpa = StudentProfileAttributes.builder("id").withShortName("shortName").withEmail("personal@email.com").withInstitute("institute").withNationality("American").withGender("female").withMoreInfo("moreInfo").build();
    AccountAttributes accountWithStudentProfile = AccountAttributes.builder().withGoogleId("id").withName("name").withEmail("test@email.come").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(expectedSpa).build();
    accountsLogic.createAccount(accountWithStudentProfile);
    StudentProfileAttributes actualSpa = profilesLogic.getStudentProfile(accountWithStudentProfile.googleId);
    expectedSpa.modifiedDate = actualSpa.modifiedDate;
    assertEquals(expectedSpa.toString(), actualSpa.toString());
    ______TS("update SP");
    expectedSpa.pictureKey = "non-empty";
    accountWithStudentProfile.studentProfile.pictureKey = expectedSpa.pictureKey;
    profilesLogic.updateStudentProfile(accountWithStudentProfile.studentProfile);
    actualSpa = profilesLogic.getStudentProfile(accountWithStudentProfile.googleId);
    expectedSpa.modifiedDate = actualSpa.modifiedDate;
    assertEquals(expectedSpa.toString(), actualSpa.toString());
    ______TS("update picture");
    expectedSpa.pictureKey = writeFileToGcs(expectedSpa.googleId, "src/test/resources/images/profile_pic.png");
    profilesLogic.updateStudentProfilePicture(expectedSpa.googleId, expectedSpa.pictureKey);
    actualSpa = profilesLogic.getStudentProfile(accountWithStudentProfile.googleId);
    expectedSpa.modifiedDate = actualSpa.modifiedDate;
    assertEquals(expectedSpa.toString(), actualSpa.toString());
    ______TS("delete profile picture");
    profilesLogic.deleteStudentProfilePicture(expectedSpa.googleId);
    assertFalse(doesFileExistInGcs(new BlobKey(expectedSpa.pictureKey)));
    actualSpa = profilesLogic.getStudentProfile(accountWithStudentProfile.googleId);
    expectedSpa.modifiedDate = actualSpa.modifiedDate;
    expectedSpa.pictureKey = "";
    assertEquals(expectedSpa.toString(), actualSpa.toString());
    // remove the account that was created
    accountsLogic.deleteAccountCascade("id");
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) BlobKey(com.google.appengine.api.blobstore.BlobKey) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) Test(org.testng.annotations.Test)

Example 52 with AccountAttributes

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

the class StudentsLogicTest method testEnrollStudents.

private void testEnrollStudents() throws Exception {
    String instructorId = "instructorForEnrollTesting";
    String courseIdForEnrollTest = "courseForEnrollTest";
    String instructorEmail = "instructor@email.tmt";
    StudentProfileAttributes profileAttributes = StudentProfileAttributes.builder(instructorId).withShortName("Ins1").withGender("male").build();
    AccountAttributes accountToAdd = AccountAttributes.builder().withGoogleId(instructorId).withName("Instructor 1").withEmail(instructorEmail).withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(profileAttributes).build();
    accountsLogic.createAccount(accountToAdd);
    coursesLogic.createCourseAndInstructor(instructorId, courseIdForEnrollTest, "Course for Enroll Testing", "UTC");
    FeedbackSessionsLogic fsLogic = FeedbackSessionsLogic.inst();
    FeedbackSessionAttributes fsAttr = FeedbackSessionAttributes.builder("newFeedbackSessionName", courseIdForEnrollTest, instructorEmail).withInstructions(new Text("default instructions")).withCreatedTime(Instant.now()).withStartTime(TimeHelperExtension.getInstantHoursOffsetFromNow(2)).withEndTime(TimeHelperExtension.getInstantHoursOffsetFromNow(5)).withSessionVisibleFromTime(TimeHelperExtension.getInstantHoursOffsetFromNow(1)).withResultsVisibleFromTime(TimeHelperExtension.getInstantHoursOffsetFromNow(6)).withTimeZone(ZoneId.of("Asia/Singapore")).withGracePeriodMinutes(0).withFeedbackSessionType(FeedbackSessionType.PRIVATE).withOpeningEmailEnabled(false).withClosingEmailEnabled(false).withPublishedEmailEnabled(false).build();
    fsLogic.createFeedbackSession(fsAttr);
    ______TS("all valid students, but contains blank lines and trailing spaces");
    String headerLine = "team | name | email | comment";
    String line0 = "t1   |  n1   |   e1@g  |   c1";
    String line1 = " t2|  n2|  e2@g|  c2";
    String line2 = "\u00A0t3  |n3|  e3@g|c3  ";
    String line3 = "t4|n4|  e4@g|c4";
    String line4 = "t5|  n5|e5@g  |c5";
    String lines = headerLine + System.lineSeparator() + line0 + System.lineSeparator() + line1 + System.lineSeparator() + line2 + System.lineSeparator() + "  \t \t \t \t           " + System.lineSeparator() + line3 + System.lineSeparator() + System.lineSeparator() + line4 + System.lineSeparator() + "    " + System.lineSeparator() + System.lineSeparator();
    CourseEnrollmentResult enrollResults = studentsLogic.enrollStudentsWithoutDocument(lines, courseIdForEnrollTest);
    StudentAttributesFactory saf = new StudentAttributesFactory(headerLine);
    assertEquals(5, enrollResults.studentList.size());
    assertEquals(5, studentsLogic.getStudentsForCourse(courseIdForEnrollTest).size());
    // Test enroll result
    line0 = "t1|n1|e1@g|c1";
    verifyEnrollmentResultForStudent(saf.makeStudent(line0, courseIdForEnrollTest), enrollResults.studentList.get(0), StudentUpdateStatus.NEW);
    verifyEnrollmentResultForStudent(saf.makeStudent(line1, courseIdForEnrollTest), enrollResults.studentList.get(1), StudentUpdateStatus.NEW);
    verifyEnrollmentResultForStudent(saf.makeStudent(line4, courseIdForEnrollTest), enrollResults.studentList.get(4), StudentUpdateStatus.NEW);
    CourseDetailsBundle courseDetails = coursesLogic.getCourseSummary(courseIdForEnrollTest);
    assertEquals(5, courseDetails.stats.unregisteredTotal);
    ______TS("includes a mix of unmodified, modified, and new");
    String modifiedLine2 = "t3|modified name|e3@g|c3";
    String line5 = "t6|n6|e6@g|c6";
    lines = headerLine + System.lineSeparator() + line0 + System.lineSeparator() + modifiedLine2 + System.lineSeparator() + line1 + System.lineSeparator() + line5;
    enrollResults = studentsLogic.enrollStudentsWithoutDocument(lines, courseIdForEnrollTest);
    assertEquals(6, enrollResults.studentList.size());
    assertEquals(6, studentsLogic.getStudentsForCourse(courseIdForEnrollTest).size());
    verifyEnrollmentResultForStudent(saf.makeStudent(line0, courseIdForEnrollTest), enrollResults.studentList.get(0), StudentUpdateStatus.UNMODIFIED);
    verifyEnrollmentResultForStudent(saf.makeStudent(modifiedLine2, courseIdForEnrollTest), enrollResults.studentList.get(1), StudentUpdateStatus.MODIFIED);
    verifyEnrollmentResultForStudent(saf.makeStudent(line1, courseIdForEnrollTest), enrollResults.studentList.get(2), StudentUpdateStatus.UNMODIFIED);
    verifyEnrollmentResultForStudent(saf.makeStudent(line5, courseIdForEnrollTest), enrollResults.studentList.get(3), StudentUpdateStatus.NEW);
    assertEquals(StudentUpdateStatus.NOT_IN_ENROLL_LIST, enrollResults.studentList.get(4).updateStatus);
    assertEquals(StudentUpdateStatus.NOT_IN_ENROLL_LIST, enrollResults.studentList.get(5).updateStatus);
    ______TS("includes an incorrect line");
    // no changes should be done to the database
    String incorrectLine = "incorrectly formatted line";
    lines = headerLine + System.lineSeparator() + "t7|n7|e7@g|c7" + System.lineSeparator() + incorrectLine + System.lineSeparator() + line2 + System.lineSeparator() + line3;
    try {
        enrollResults = studentsLogic.enrollStudentsWithoutDocument(lines, courseIdForEnrollTest);
        signalFailureToDetectException("Did not throw exception for incorrectly formatted line");
    } catch (EnrollException e) {
        assertTrue(e.getMessage().contains(incorrectLine));
    }
    assertEquals(6, studentsLogic.getStudentsForCourse(courseIdForEnrollTest).size());
    ______TS("null parameters");
    try {
        studentsLogic.enrollStudentsWithoutDocument("a|b|c|d", null);
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
    ______TS("same student added, modified and unmodified");
    StudentProfileAttributes studentAttributes = StudentProfileAttributes.builder("tes.instructor").withShortName("Ins 1").withGender("male").build();
    accountToAdd = AccountAttributes.builder().withGoogleId("tes.instructor").withName("Instructor 1").withEmail("instructor@email.tmt").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(studentAttributes).build();
    accountsLogic.createAccount(accountToAdd);
    coursesLogic.createCourseAndInstructor("tes.instructor", "tes.course", "TES Course", "UTC");
    String line = headerLine + System.lineSeparator() + "t8|n8|e8@g|c1";
    enrollResults = studentsLogic.enrollStudentsWithoutDocument(line, "tes.course");
    assertEquals(1, enrollResults.studentList.size());
    assertEquals(StudentUpdateStatus.NEW, enrollResults.studentList.get(0).updateStatus);
    line = headerLine + System.lineSeparator() + "t8|n8a|e8@g|c1";
    enrollResults = studentsLogic.enrollStudentsWithoutDocument(line, "tes.course");
    assertEquals(1, enrollResults.studentList.size());
    assertEquals(StudentUpdateStatus.MODIFIED, enrollResults.studentList.get(0).updateStatus);
    line = headerLine + System.lineSeparator() + "t8|n8a|e8@g|c1";
    enrollResults = studentsLogic.enrollStudentsWithoutDocument(line, "tes.course");
    assertEquals(1, enrollResults.studentList.size());
    assertEquals(StudentUpdateStatus.UNMODIFIED, enrollResults.studentList.get(0).updateStatus);
    ______TS("duplicated emails");
    String lineT9 = "t9|n9|e9@g|c9";
    String lineT10 = "t10|n10|e9@g|c10";
    lines = headerLine + System.lineSeparator() + lineT9 + System.lineSeparator() + lineT10;
    try {
        studentsLogic.enrollStudentsWithoutDocument(lines, "tes.course");
    } catch (EnrollException e) {
        assertTrue(e.getMessage().contains(lineT10));
        AssertHelper.assertContains("Same email address as the student in line \"" + lineT9 + "\"", e.getMessage());
    }
    ______TS("invalid course id");
    String enrollLines = headerLine + System.lineSeparator();
    String invalidCourseId = "invalidCourseId";
    try {
        studentsLogic.enrollStudentsWithoutDocument(enrollLines, invalidCourseId);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        ignoreExpectedException();
    }
    ______TS("empty enroll line");
    try {
        studentsLogic.enrollStudentsWithoutDocument("", courseIdForEnrollTest);
        signalFailureToDetectException();
    } catch (EnrollException e) {
        ignoreExpectedException();
    }
    ______TS("invalidity info in enroll line");
    enrollLines = headerLine + System.lineSeparator() + "invalidline0\ninvalidline1\n";
    try {
        studentsLogic.enrollStudentsWithoutDocument(enrollLines, courseIdForEnrollTest);
        signalFailureToDetectException();
    } catch (EnrollException e) {
        ignoreExpectedException();
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) EnrollException(teammates.common.exception.EnrollException) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) FeedbackSessionsLogic(teammates.logic.core.FeedbackSessionsLogic) CourseEnrollmentResult(teammates.common.datatransfer.CourseEnrollmentResult) Text(com.google.appengine.api.datastore.Text) StudentAttributesFactory(teammates.common.datatransfer.StudentAttributesFactory) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 53 with AccountAttributes

use of teammates.common.datatransfer.attributes.AccountAttributes 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 54 with AccountAttributes

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

the class FeedbackSubmissionEditPageDataTest method testAll.

@Test
public void testAll() {
    ______TS("test typical case");
    AccountAttributes studentAccount = dataBundle.accounts.get("student1InCourse1");
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    pageData = new FeedbackSubmissionEditPageData(studentAccount, student, dummySessionToken);
    createData(student);
    pageData.init(student.key, student.email, student.course);
    assertEquals("You are submitting feedback as <span class='text-danger text-bold text-large'>" + "student1 In Course1</td></div>'\"</span>. " + "You may submit feedback for sessions that are currently open " + "and view results without logging in. " + "To access other features you need <a href='/page/studentCourseJoinAuthentication?" + "studentemail=student1InCourse1%40gmail.tmt&courseid=idOfTypicalCourse1' class='link'>" + "to login using a Google account</a> (recommended).", pageData.getRegisterMessage());
    assertNull(pageData.getSubmitAction());
    assertFalse(pageData.isModeration());
    assertFalse(pageData.isSessionOpenForSubmission());
    assertFalse(pageData.isSubmittable());
    testQuestionAttributes();
    ______TS("student in unregistered course");
    student = dataBundle.students.get("student1InUnregisteredCourse");
    pageData = new FeedbackSubmissionEditPageData(studentAccount, student, dummySessionToken);
    createData(student);
    pageData.init(student.key, student.email, student.course);
    assertEquals("You are submitting feedback as <span class='text-danger text-bold text-large'>student1 " + "In unregisteredCourse</span>. You may submit feedback for sessions that are currently open " + "and view results without logging in. " + "To access other features you need <a href='/page/studentCourseJoinAuthentication?" + "key=regKeyForStuNotYetJoinCourse&studentemail=student1InUnregisteredCourse%40gmail.tmt&" + "courseid=idOfUnregisteredCourse' class='link'>to login using a Google account</a> " + "(recommended).", pageData.getRegisterMessage());
    assertNull(pageData.getSubmitAction());
    assertFalse(pageData.isModeration());
    assertFalse(pageData.isSessionOpenForSubmission());
    assertFalse(pageData.isSubmittable());
    testQuestionAttributes();
    ______TS("student in archived course");
    student = dataBundle.students.get("student1InArchivedCourse");
    pageData = new FeedbackSubmissionEditPageData(studentAccount, student, dummySessionToken);
    createData(student);
    pageData.init(student.key, student.email, student.course);
    assertEquals("You are submitting feedback as <span class='text-danger text-bold text-large'>student1 In Course1" + "</span>. You may submit feedback for sessions that are currently open " + "and view results without logging in. To access other features " + "you need <a href='/page/studentCourseJoinAuthentication?studentemail=student1InArchivedCourse%40" + "gmail.tmt&courseid=idOfArchivedCourse' class='link'>to login using a Google account</a> " + "(recommended).", pageData.getRegisterMessage());
    assertNull(pageData.getSubmitAction());
    assertFalse(pageData.isModeration());
    assertFalse(pageData.isSessionOpenForSubmission());
    assertFalse(pageData.isSubmittable());
    testQuestionAttributes();
    ______TS("student submission open");
    student = dataBundle.students.get("student1InCourse1");
    pageData = new FeedbackSubmissionEditPageData(studentAccount, student, dummySessionToken);
    createData(student);
    pageData.setSessionOpenForSubmission(true);
    pageData.init(student.key, student.email, student.course);
    assertEquals("You are submitting feedback as <span class='text-danger text-bold text-large'>" + "student1 In Course1</td></div>'\"</span>. " + "You may submit feedback for sessions that are currently open " + "and view results without logging in. " + "To access other features you need <a href='/page/studentCourseJoinAuthentication?" + "studentemail=student1InCourse1%40gmail.tmt&courseid=idOfTypicalCourse1' class='link'>" + "to login using a Google account</a> (recommended).", pageData.getRegisterMessage());
    assertNull(pageData.getSubmitAction());
    assertFalse(pageData.isModeration());
    assertTrue(pageData.isSessionOpenForSubmission());
    assertTrue(pageData.isSubmittable());
    ______TS("instructor moderating a response - closed for submission");
    AccountAttributes instructorAccount = dataBundle.accounts.get("instructor1OfCourse1");
    InstructorAttributes instructor = dataBundle.instructors.get("instructor1OfCourse1");
    student = dataBundle.students.get("student1InCourse1");
    pageData = new FeedbackSubmissionEditPageData(instructorAccount, student, dummySessionToken);
    createData(student);
    pageData.setModeration(true);
    pageData.init("", student.email, student.course);
    assertNull(pageData.getSubmitAction());
    assertTrue(pageData.isModeration());
    assertFalse(pageData.isSessionOpenForSubmission());
    assertTrue(pageData.isSubmittable());
    testQuestionAttributes();
    ______TS("instructor moderating a response - open for submission");
    student = dataBundle.students.get("student1InCourse1");
    pageData = new FeedbackSubmissionEditPageData(instructorAccount, student, dummySessionToken);
    createData(student);
    pageData.setModeration(true);
    pageData.setSessionOpenForSubmission(true);
    pageData.init("", student.email, student.course);
    assertNull(pageData.getSubmitAction());
    assertTrue(pageData.isModeration());
    assertTrue(pageData.isSessionOpenForSubmission());
    assertTrue(pageData.isSubmittable());
    testQuestionAttributes();
    ______TS("instructor previewing a response");
    pageData = new FeedbackSubmissionEditPageData(instructorAccount, student, dummySessionToken);
    createData(student);
    pageData.setPreview(true);
    pageData.setPreviewInstructor(instructor);
    pageData.init("", student.email, student.course);
    assertNull(pageData.getSubmitAction());
    assertFalse(pageData.isModeration());
    assertFalse(pageData.isSessionOpenForSubmission());
    assertFalse(pageData.isSubmittable());
    testQuestionAttributes();
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) FeedbackSubmissionEditPageData(teammates.ui.pagedata.FeedbackSubmissionEditPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 55 with AccountAttributes

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

the class AccountsDbTest method testGetAccount.

@Test
public void testGetAccount() throws Exception {
    AccountAttributes a = createNewAccount();
    ______TS("typical success case without");
    AccountAttributes retrieved = accountsDb.getAccount(a.googleId);
    assertNotNull(retrieved);
    assertNull(retrieved.studentProfile);
    ______TS("typical success with student profile");
    retrieved = accountsDb.getAccount(a.googleId, true);
    assertNotNull(retrieved);
    assertNotNull(a.studentProfile);
    ______TS("expect null for non-existent account");
    retrieved = accountsDb.getAccount("non.existent");
    assertNull(retrieved);
    ______TS("failure: null parameter");
    try {
        accountsDb.getAccount(null);
        signalFailureToDetectException(" - AssertionError");
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Test(org.testng.annotations.Test)

Aggregations

AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)84 Test (org.testng.annotations.Test)53 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)28 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)16 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)15 ArrayList (java.util.ArrayList)13 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)11 HashMap (java.util.HashMap)7 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)6 InvalidParametersException (teammates.common.exception.InvalidParametersException)6 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)5 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)4 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)4 EmailWrapper (teammates.common.util.EmailWrapper)4 RedirectResult (teammates.ui.controller.RedirectResult)4 List (java.util.List)3 EmailGenerator (teammates.logic.api.EmailGenerator)3 AccountsDb (teammates.storage.api.AccountsDb)3 Account (teammates.storage.entity.Account)3 ShowPageResult (teammates.ui.controller.ShowPageResult)3