Search in sources :

Example 21 with AccountAttributes

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

the class CoursesLogicTest method testCreateCourseAndInstructor.

private void testCreateCourseAndInstructor() throws Exception {
    /* Explanation: SUT has 5 paths. They are,
         * path 1 - exit because the account doesn't' exist.
         * path 2 - exit because the account exists but doesn't have instructor privileges.
         * path 3 - exit because course creation failed.
         * path 4 - exit because instructor creation failed.
         * path 5 - success.
         * Accordingly, we have 5 test cases.
         */
    ______TS("fails: account doesn't exist");
    CourseAttributes c = CourseAttributes.builder("fresh-course-tccai", "Fresh course for tccai", ZoneId.of("America/Los_Angeles")).build();
    @SuppressWarnings("deprecation") InstructorAttributes i = InstructorAttributes.builder("instructor-for-tccai", c.getId(), "Instructor for tccai", "ins.for.iccai@gmail.tmt").build();
    try {
        coursesLogic.createCourseAndInstructor(i.googleId, c.getId(), c.getName(), c.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("for a non-existent instructor", e.getMessage());
    }
    verifyAbsentInDatastore(c);
    verifyAbsentInDatastore(i);
    ______TS("fails: account doesn't have instructor privileges");
    AccountAttributes a = AccountAttributes.builder().withGoogleId(i.googleId).withName(i.name).withIsInstructor(false).withEmail(i.email).withInstitute("TEAMMATES Test Institute 5").withDefaultStudentProfileAttributes(i.googleId).build();
    accountsDb.createAccount(a);
    try {
        coursesLogic.createCourseAndInstructor(i.googleId, c.getId(), c.getName(), c.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("doesn't have instructor privileges", e.getMessage());
    }
    verifyAbsentInDatastore(c);
    verifyAbsentInDatastore(i);
    ______TS("fails: error during course creation");
    a.isInstructor = true;
    accountsDb.updateAccount(a);
    CourseAttributes invalidCourse = CourseAttributes.builder("invalid id", "Fresh course for tccai", ZoneId.of("UTC")).build();
    String expectedError = "\"" + invalidCourse.getId() + "\" is not acceptable to TEAMMATES as a/an course ID because" + " it is not in the correct format. " + "A course ID can contain letters, numbers, fullstops, hyphens, underscores, and dollar signs. " + "It cannot be longer than 40 characters, cannot be empty and cannot contain spaces.";
    try {
        coursesLogic.createCourseAndInstructor(i.googleId, invalidCourse.getId(), invalidCourse.getName(), invalidCourse.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        assertEquals(expectedError, e.getMessage());
    }
    verifyAbsentInDatastore(invalidCourse);
    verifyAbsentInDatastore(i);
    ______TS("fails: error during instructor creation due to duplicate instructor");
    CourseAttributes courseWithDuplicateInstructor = CourseAttributes.builder("fresh-course-tccai", "Fresh course for tccai", ZoneId.of("UTC")).build();
    // create a duplicate instructor
    instructorsDb.createEntity(i);
    try {
        coursesLogic.createCourseAndInstructor(i.googleId, courseWithDuplicateInstructor.getId(), courseWithDuplicateInstructor.getName(), courseWithDuplicateInstructor.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("Unexpected exception while trying to create instructor for a new course", e.getMessage());
    }
    verifyAbsentInDatastore(courseWithDuplicateInstructor);
    ______TS("fails: error during instructor creation due to invalid parameters");
    i.email = "ins.for.iccai.gmail.tmt";
    try {
        coursesLogic.createCourseAndInstructor(i.googleId, courseWithDuplicateInstructor.getId(), courseWithDuplicateInstructor.getName(), courseWithDuplicateInstructor.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("Unexpected exception while trying to create instructor for a new course", e.getMessage());
    }
    verifyAbsentInDatastore(courseWithDuplicateInstructor);
    ______TS("success: typical case");
    i.email = "ins.for.iccai@gmail.tmt";
    // remove the duplicate instructor object from the datastore.
    instructorsDb.deleteInstructor(i.courseId, i.email);
    coursesLogic.createCourseAndInstructor(i.googleId, courseWithDuplicateInstructor.getId(), courseWithDuplicateInstructor.getName(), courseWithDuplicateInstructor.getTimeZone().getId());
    verifyPresentInDatastore(courseWithDuplicateInstructor);
    verifyPresentInDatastore(i);
    ______TS("Null parameter");
    try {
        coursesLogic.createCourseAndInstructor(null, courseWithDuplicateInstructor.getId(), courseWithDuplicateInstructor.getName(), courseWithDuplicateInstructor.getTimeZone().getId());
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 22 with AccountAttributes

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

the class EmailGeneratorTest method testGenerateInstructorJoinEmail_testSanitization.

@Test
public void testGenerateInstructorJoinEmail_testSanitization() throws IOException {
    ______TS("instructor new account email: sanitization required");
    InstructorAttributes instructor1 = instructorsLogic.getInstructorForEmail("idOfTestingSanitizationCourse", "instructor1@sanitization.tmt");
    String joinLink = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN).withRegistrationKey(StringHelper.encrypt(instructor1.key)).withInstructorInstitution("Test Institute").toAbsoluteString();
    EmailWrapper email = new EmailGenerator().generateNewInstructorAccountJoinEmail(instructor1.email, instructor1.name, joinLink);
    // InstructorAttributes sanitizes name before saving
    String subject = String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), SanitizationHelper.sanitizeForHtml(instructor1.name));
    verifyEmail(email, instructor1.email, subject, "/instructorNewAccountEmailTestingSanitization.html");
    assertEquals(email.getBcc(), Config.SUPPORT_EMAIL);
    ______TS("instructor course join email: sanitization required");
    AccountAttributes inviter = dataBundle.accounts.get("instructor1OfTestingSanitizationCourse");
    CourseAttributes course = coursesLogic.getCourse("idOfTestingSanitizationCourse");
    email = new EmailGenerator().generateInstructorCourseJoinEmail(inviter, instructor1, course);
    subject = String.format(EmailType.INSTRUCTOR_COURSE_JOIN.getSubject(), course.getName(), course.getId());
    verifyEmail(email, instructor1.email, subject, "/instructorCourseJoinEmailTestingSanitization.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 23 with AccountAttributes

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

the class EmailGeneratorTest method testGenerateInstructorJoinEmail.

@Test
public void testGenerateInstructorJoinEmail() throws IOException {
    ______TS("instructor new account email");
    String instructorEmail = "instructor@email.tmt";
    String instructorName = "Instr";
    String regkey = "skxxxxxxxxxks";
    @SuppressWarnings("deprecation") InstructorAttributes instructor = InstructorAttributes.builder("googleId", "courseId", "Instructor Name", instructorEmail).withKey(regkey).build();
    AccountAttributes inviter = AccountAttributes.builder().withEmail("instructor-joe@gmail.com").withName("Joe Wilson").build();
    String joinLink = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN).withRegistrationKey(StringHelper.encrypt(regkey)).withInstructorInstitution("Test Institute").toAbsoluteString();
    EmailWrapper email = new EmailGenerator().generateNewInstructorAccountJoinEmail(instructorEmail, instructorName, joinLink);
    String subject = String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), instructorName);
    verifyEmail(email, instructorEmail, subject, "/instructorNewAccountEmail.html");
    assertEquals(email.getBcc(), Config.SUPPORT_EMAIL);
    ______TS("instructor course join email");
    CourseAttributes course = CourseAttributes.builder("course-id", "Course Name", ZoneId.of("UTC")).build();
    email = new EmailGenerator().generateInstructorCourseJoinEmail(inviter, instructor, course);
    subject = String.format(EmailType.INSTRUCTOR_COURSE_JOIN.getSubject(), course.getName(), course.getId());
    verifyEmail(email, instructor.email, subject, "/instructorCourseJoinEmail.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 24 with AccountAttributes

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

the class AdminHomePageDataTest method createData.

private void createData() {
    AccountAttributes admin = dataBundle.accounts.get("instructor1OfCourse1");
    pageData = new AdminHomePageData(admin, dummySessionToken);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) AdminHomePageData(teammates.ui.pagedata.AdminHomePageData)

Example 25 with AccountAttributes

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

the class AccountsDbTest method testDeleteAccount.

@Test
public void testDeleteAccount() throws Exception {
    AccountAttributes a = createNewAccount();
    a.studentProfile.pictureKey = writeFileToGcs(a.googleId, "src/test/resources/images/profile_pic_default.png");
    profilesDb.updateStudentProfilePicture(a.googleId, a.studentProfile.pictureKey);
    ______TS("typical success case");
    AccountAttributes newAccount = accountsDb.getAccount(a.googleId);
    assertNotNull(newAccount);
    accountsDb.deleteAccount(a.googleId);
    AccountAttributes newAccountdeleted = accountsDb.getAccount(a.googleId);
    assertNull(newAccountdeleted);
    StudentProfileAttributes deletedProfile = profilesDb.getStudentProfile(a.googleId);
    assertNull(deletedProfile);
    assertFalse(doesFileExistInGcs(new BlobKey(a.studentProfile.pictureKey)));
    ______TS("silent deletion of same account");
    accountsDb.deleteAccount(a.googleId);
    ______TS("failure null paramter");
    try {
        accountsDb.deleteAccount(null);
        signalFailureToDetectException(" - AssertionError");
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
}
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)

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