Search in sources :

Example 36 with AccountAttributes

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

the class StudentCourseDetailsPageDataTest method test.

@Test
public void test() {
    ______TS("typical success case");
    AccountAttributes account = dataBundle.accounts.get("student1InCourse1");
    StudentCourseDetailsPageData pageData = new StudentCourseDetailsPageData(account, dummySessionToken);
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    CourseDetailsBundle courseDetails = new CourseDetailsBundle(course);
    List<InstructorAttributes> instructors = new ArrayList<>();
    instructors.add(dataBundle.instructors.get("instructor1OfCourse1"));
    instructors.add(dataBundle.instructors.get("instructor2OfCourse1"));
    instructors.add(dataBundle.instructors.get("helperOfCourse1"));
    TeamDetailsBundle team = new TeamDetailsBundle();
    team.name = student.team;
    // Get team members of student
    for (Entry<String, StudentAttributes> entry : dataBundle.students.entrySet()) {
        StudentAttributes currStudent = entry.getValue();
        if (currStudent.team.equals(team.name)) {
            team.students.add(currStudent);
        }
    }
    pageData.init(courseDetails, instructors, student, team);
    List<InstructorAttributes> courseInstructors = pageData.getStudentCourseDetailsPanel().getInstructors();
    List<StudentAttributes> teammates = pageData.getStudentCourseDetailsPanel().getTeammates();
    assertEquals(courseDetails.course.getName(), pageData.getStudentCourseDetailsPanel().getCourseName());
    assertEquals(courseDetails.course.getId(), pageData.getStudentCourseDetailsPanel().getCourseId());
    assertFalse(courseInstructors.isEmpty());
    assertFalse(teammates.isEmpty());
    assertEquals(student.email, pageData.getStudentCourseDetailsPanel().getStudentEmail());
    assertEquals(student.name, pageData.getStudentCourseDetailsPanel().getStudentName());
    assertEquals(team.name, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    assertEquals(instructors.size(), courseInstructors.size());
    assertEquals(instructors.get(0).name, courseInstructors.get(0).name);
    assertEquals(instructors.get(1).name, courseInstructors.get(1).name);
    assertEquals(instructors.get(2).name, courseInstructors.get(2).name);
    assertEquals(instructors.get(0).displayedName, courseInstructors.get(0).displayedName);
    assertEquals(instructors.get(1).displayedName, courseInstructors.get(1).displayedName);
    assertEquals(instructors.get(2).displayedName, courseInstructors.get(2).displayedName);
    assertEquals(team.students.size(), teammates.size());
    ______TS("student in unregistered course");
    student = dataBundle.students.get("student1InUnregisteredCourse");
    course = dataBundle.courses.get("unregisteredCourse");
    courseDetails = new CourseDetailsBundle(course);
    instructors = new ArrayList<>();
    instructors.add(dataBundle.instructors.get("instructor5"));
    team = new TeamDetailsBundle();
    team.name = student.team;
    // Get team members of student
    for (Entry<String, StudentAttributes> entry : dataBundle.students.entrySet()) {
        StudentAttributes currStudent = entry.getValue();
        if (currStudent.team.equals(team.name)) {
            team.students.add(currStudent);
        }
    }
    pageData.init(courseDetails, instructors, student, team);
    courseInstructors = pageData.getStudentCourseDetailsPanel().getInstructors();
    teammates = pageData.getStudentCourseDetailsPanel().getTeammates();
    assertEquals(courseDetails.course.getName(), pageData.getStudentCourseDetailsPanel().getCourseName());
    assertEquals(courseDetails.course.getId(), pageData.getStudentCourseDetailsPanel().getCourseId());
    assertFalse(courseInstructors.isEmpty());
    assertFalse(teammates.isEmpty());
    assertEquals(student.email, pageData.getStudentCourseDetailsPanel().getStudentEmail());
    assertEquals(student.name, pageData.getStudentCourseDetailsPanel().getStudentName());
    assertEquals(team.name, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    assertEquals(instructors.size(), courseInstructors.size());
    assertEquals(instructors.get(0).name, courseInstructors.get(0).name);
    assertEquals(instructors.get(0).displayedName, courseInstructors.get(0).displayedName);
    assertEquals(team.students.size(), teammates.size());
    ______TS("student in archived course");
    student = dataBundle.students.get("student1InArchivedCourse");
    course = dataBundle.courses.get("archivedCourse");
    courseDetails = new CourseDetailsBundle(course);
    instructors = new ArrayList<>();
    instructors.add(dataBundle.instructors.get("instructorOfArchivedCourse"));
    team = new TeamDetailsBundle();
    team.name = student.team;
    // Get team members of student
    for (Entry<String, StudentAttributes> entry : dataBundle.students.entrySet()) {
        StudentAttributes currStudent = entry.getValue();
        if (currStudent.team.equals(team.name)) {
            team.students.add(currStudent);
        }
    }
    pageData.init(courseDetails, instructors, student, team);
    courseInstructors = pageData.getStudentCourseDetailsPanel().getInstructors();
    teammates = pageData.getStudentCourseDetailsPanel().getTeammates();
    assertEquals(courseDetails.course.getName(), pageData.getStudentCourseDetailsPanel().getCourseName());
    assertEquals(courseDetails.course.getId(), pageData.getStudentCourseDetailsPanel().getCourseId());
    assertFalse(courseInstructors.isEmpty());
    assertFalse(teammates.isEmpty());
    assertEquals(student.email, pageData.getStudentCourseDetailsPanel().getStudentEmail());
    assertEquals(student.name, pageData.getStudentCourseDetailsPanel().getStudentName());
    assertEquals(team.name, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    assertEquals(instructors.size(), courseInstructors.size());
    assertEquals(instructors.get(0).name, courseInstructors.get(0).name);
    assertEquals(instructors.get(0).displayedName, courseInstructors.get(0).displayedName);
    assertEquals(team.students.size(), teammates.size());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ArrayList(java.util.ArrayList) StudentCourseDetailsPageData(teammates.ui.pagedata.StudentCourseDetailsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 37 with AccountAttributes

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

the class AccountsLogicTest method testCreateAccount.

@Test
public void testCreateAccount() throws Exception {
    ______TS("typical success case");
    StudentProfileAttributes spa = StudentProfileAttributes.builder("id").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";
    AccountAttributes accountToCreate = AccountAttributes.builder().withGoogleId("id").withName("name").withEmail("test@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
    accountsLogic.createAccount(accountToCreate);
    verifyPresentInDatastore(accountToCreate);
    accountsLogic.deleteAccountCascade("id");
    ______TS("invalid parameters exception case");
    accountToCreate = AccountAttributes.builder().withGoogleId("").withName("name").withEmail("test@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
    try {
        accountsLogic.createAccount(accountToCreate);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        ignoreExpectedException();
    }
}
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 38 with AccountAttributes

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

the class AccountsLogicTest method testDeleteAccountCascade.

@Test
public void testDeleteAccountCascade() throws Exception {
    ______TS("typical success case");
    InstructorAttributes instructor = dataBundle.instructors.get("instructor5");
    AccountAttributes account = dataBundle.accounts.get("instructor5");
    // Make instructor account id a student too.
    StudentAttributes student = StudentAttributes.builder(instructor.courseId, instructor.name, "email@com").withSection("section").withTeam("team").withComments("").withGoogleId(instructor.googleId).build();
    studentsLogic.createStudentCascadeWithoutDocument(student);
    verifyPresentInDatastore(account);
    verifyPresentInDatastore(instructor);
    verifyPresentInDatastore(student);
    accountsLogic.deleteAccountCascade(instructor.googleId);
    verifyAbsentInDatastore(account);
    verifyAbsentInDatastore(instructor);
    verifyAbsentInDatastore(student);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 39 with AccountAttributes

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

the class AccountsLogicTest method testAccountFunctions.

@Priority(-1)
@Test
public void testAccountFunctions() throws Exception {
    ______TS("test isAccountPresent");
    assertTrue(accountsLogic.isAccountPresent("idOfInstructor1OfCourse1"));
    assertTrue(accountsLogic.isAccountPresent("student1InCourse1"));
    assertFalse(accountsLogic.isAccountPresent("id-does-not-exist"));
    ______TS("test isAccountAnInstructor");
    assertTrue(accountsLogic.isAccountAnInstructor("idOfInstructor1OfCourse1"));
    assertFalse(accountsLogic.isAccountAnInstructor("student1InCourse1"));
    assertFalse(accountsLogic.isAccountAnInstructor("id-does-not-exist"));
    ______TS("test getInstructorAccounts");
    for (AccountAttributes aa : accountsLogic.getInstructorAccounts()) {
        ______TS(aa.toString());
    }
    assertEquals(12, accountsLogic.getInstructorAccounts().size());
    ______TS("test updateAccount");
    StudentProfileAttributes spa = StudentProfileAttributes.builder("idOfInstructor1OfCourse1").build();
    spa.institute = "dev";
    spa.shortName = "nam";
    AccountAttributes expectedAccount = AccountAttributes.builder().withGoogleId("idOfInstructor1OfCourse1").withName("name").withEmail("test2@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
    // updates the profile
    accountsLogic.updateAccount(expectedAccount, true);
    AccountAttributes actualAccount = accountsLogic.getAccount(expectedAccount.googleId, true);
    expectedAccount.studentProfile.modifiedDate = actualAccount.studentProfile.modifiedDate;
    expectedAccount.createdAt = actualAccount.createdAt;
    assertEquals(expectedAccount.toString(), actualAccount.toString());
    // does not update the profile
    expectedAccount.studentProfile.shortName = "newNam";
    accountsLogic.updateAccount(expectedAccount);
    actualAccount = accountsLogic.getAccount(expectedAccount.googleId, true);
    // no change in the name
    assertEquals("nam", actualAccount.studentProfile.shortName);
    expectedAccount = AccountAttributes.builder().withGoogleId("id-does-not-exist").withName("name").withEmail("test2@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
    try {
        accountsLogic.updateAccount(expectedAccount);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException edne) {
        AssertHelper.assertContains(AccountsDb.ERROR_UPDATE_NON_EXISTENT_ACCOUNT, edne.getMessage());
    }
    ______TS("test downgradeInstructorToStudentCascade");
    accountsLogic.downgradeInstructorToStudentCascade("idOfInstructor2OfCourse1");
    assertFalse(accountsLogic.isAccountAnInstructor("idOfInstructor2OfCourse1"));
    accountsLogic.downgradeInstructorToStudentCascade("student1InCourse1");
    assertFalse(accountsLogic.isAccountAnInstructor("student1InCourse1"));
    accountsLogic.downgradeInstructorToStudentCascade("id-does-not-exist");
    assertFalse(accountsLogic.isAccountPresent("id-does-not-exist"));
    ______TS("test makeAccountInstructor");
    accountsLogic.makeAccountInstructor("student2InCourse1");
    assertTrue(accountsLogic.isAccountAnInstructor("student2InCourse1"));
    accountsLogic.downgradeInstructorToStudentCascade("student2InCourse1");
    accountsLogic.makeAccountInstructor("id-does-not-exist");
    assertFalse(accountsLogic.isAccountPresent("id-does-not-exist"));
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test) Priority(teammates.test.driver.Priority)

Example 40 with AccountAttributes

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

the class ProfilesDbTest method testDeleteProfilePicture.

@Test
public void testDeleteProfilePicture() throws Exception {
    AccountAttributes a = createNewAccount();
    a.studentProfile.pictureKey = uploadDefaultPictureForProfile(a.googleId);
    testDeletePictureSuccess(a);
    testDeleteProfilePictureForProfileWithNoPicture(a);
}
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