def test_user_role_examiner_does_not_need_to_be_anonymized_assignment_semi_anonymous( self): testassignment = mommy.make_recipe( 'devilry.apps.core.assignment_activeperiod_start', anonymizationmode=core_models.Assignment. ANONYMIZATIONMODE_SEMI_ANONYMOUS) testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL) test_examineruser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Examiner', shortname='*****@*****.**') mommy.make('core.RelatedExaminer', user=test_examineruser, period=testassignment.parentnode, automatic_anonymous_id='Some anonymous name') group_user_lookup = GroupUserLookup( assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual( group_user_lookup.get_long_name_from_user(user=test_examineruser, user_role='examiner'), 'Test Examiner ([email protected])')
def test_user_role_student_user_is_student_and_examiner_is_not_anonymized_to_themselves( self): testassignment = mommy.make_recipe( 'devilry.apps.core.assignment_activeperiod_start', anonymizationmode=core_models.Assignment. ANONYMIZATIONMODE_SEMI_ANONYMOUS) testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Student', shortname='*****@*****.**') mommy.make( 'core.Candidate', assignment_group=testgroup, relatedstudent__user=testuser, relatedstudent__automatic_anonymous_id='Some anonymous name', relatedstudent__period=testassignment.parentnode) group_user_lookup = GroupUserLookup( assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual( group_user_lookup.get_long_name_from_user(user=testuser, user_role='student'), 'Test Student ([email protected])')
def test_user_role_student_get_anonymized_longname_for_assignment_uses_custom_candidate_ids( self): testassignment = mommy.make_recipe( 'devilry.apps.core.assignment_activeperiod_start', anonymizationmode=core_models.Assignment. ANONYMIZATIONMODE_SEMI_ANONYMOUS, uses_custom_candidate_ids=True) testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL) test_studentuser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Student', shortname='*****@*****.**') mommy.make('core.Candidate', assignment_group=testgroup, relatedstudent__user=test_studentuser, candidate_id='1234', relatedstudent__period=testassignment.parentnode) group_user_lookup = GroupUserLookup( assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual( group_user_lookup.get_long_name_from_user(user=test_studentuser, user_role='student'), '1234')
def test_user_role_examiner_get_unanonymized_longname(self): testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start') testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL) test_examineruser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Examiner', shortname='*****@*****.**') mommy.make('core.RelatedExaminer', user=test_examineruser, period=testassignment.parentnode) group_user_lookup = GroupUserLookup(assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual(group_user_lookup.get_long_name_from_user(user=test_examineruser, user_role='examiner'), 'Test Examiner ([email protected])')
def test_user_role_student_get_anonymized_longname_no_candidate_or_relatedstudent(self): testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start', anonymizationmode=core_models.Assignment.ANONYMIZATIONMODE_SEMI_ANONYMOUS) testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL) test_studentuser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Student', shortname='*****@*****.**') group_user_lookup = GroupUserLookup(assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual(group_user_lookup.get_long_name_from_user(user=test_studentuser, user_role='student'), 'User removed from semester')
def test_user_role_admin_get_unanonymized_longname_assignment_semi_anonymized(self): testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start', anonymizationmode=core_models.Assignment.ANONYMIZATIONMODE_SEMI_ANONYMOUS) testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL) test_adminuser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Admin', shortname='*****@*****.**') group_user_lookup = GroupUserLookup(assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual(group_user_lookup.get_long_name_from_user(user=test_adminuser, user_role='admin'), 'Test Admin ([email protected])')
def test_user_role_examiner_get_anonymized_longname(self): testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start', anonymizationmode=core_models.Assignment.ANONYMIZATIONMODE_SEMI_ANONYMOUS) testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL) test_examineruser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Examiner', shortname='*****@*****.**') mommy.make('core.RelatedExaminer', user=test_examineruser, period=testassignment.parentnode, automatic_anonymous_id='Some anonymous name') group_user_lookup = GroupUserLookup(assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual(group_user_lookup.get_long_name_from_user(user=test_examineruser, user_role='examiner'), 'Some anonymous name')
def test_user_role_student_does_not_need_to_be_anonymized_for_other_students_assignment_semi_anonymous(self): testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start', anonymizationmode=core_models.Assignment.ANONYMIZATIONMODE_SEMI_ANONYMOUS) testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL) test_studentuser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Student', shortname='*****@*****.**') mommy.make('core.Candidate', assignment_group=testgroup, relatedstudent__user=test_studentuser) group_user_lookup = GroupUserLookup(assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual(group_user_lookup.get_long_name_from_user(user=test_studentuser, user_role='student'), 'Test Student ([email protected])')
def test_user_role_admin_get_unanonymized_longname(self): testassignment = mommy.make_recipe( 'devilry.apps.core.assignment_activeperiod_start') testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL) test_adminuser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Admin', shortname='*****@*****.**') group_user_lookup = GroupUserLookup( assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual( group_user_lookup.get_long_name_from_user(user=test_adminuser, user_role='admin'), 'Test Admin ([email protected])')
def test_user_role_examiner_get_anonymized_longname_relatedexaminer_does_not_exist( self): testassignment = mommy.make_recipe( 'devilry.apps.core.assignment_activeperiod_start', anonymizationmode=core_models.Assignment. ANONYMIZATIONMODE_SEMI_ANONYMOUS) testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL) test_examineruser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Examiner', shortname='*****@*****.**') group_user_lookup = GroupUserLookup( assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual( group_user_lookup.get_long_name_from_user(user=test_examineruser, user_role='examiner'), 'User removed from semester')
def test_user_role_student_get_unanonymized_longname(self): testassignment = mommy.make_recipe( 'devilry.apps.core.assignment_activeperiod_start') testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment) testuser = mommy.make(settings.AUTH_USER_MODEL) test_studentuser = mommy.make(settings.AUTH_USER_MODEL, fullname='Test Student', shortname='*****@*****.**') mommy.make('core.Candidate', assignment_group=testgroup, relatedstudent__user=test_studentuser, relatedstudent__period=testassignment.parentnode) group_user_lookup = GroupUserLookup( assignment=testassignment, group=testgroup, requestuser=testuser, requestuser_devilryrole=self.viewrole) self.assertEqual( group_user_lookup.get_long_name_from_user(user=test_studentuser, user_role='student'), 'Test Student ([email protected])')