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());
}
}
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");
}
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");
}
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);
}
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());
}
}
Aggregations