def test_update_examiners_delete(self): manager = GroupManager(self.a1id) manager.group.save() manager.group.examiners.create(user=self.testhelper.user1) manager.group.examiners.create(user=self.testhelper.user2) manager.update_examiners([]) examiners = manager.get_group_from_db().examiners.all() self.assertEquals(len(examiners), 0)
def test_update_candidates_delete(self): manager = GroupManager(self.a1id) manager.group.save() manager.group.candidates.create(student=self.testhelper.user1) manager.group.candidates.create(student=self.testhelper.user2) manager.update_candidates([]) candidates = manager.get_group_from_db().candidates.all() self.assertEquals(len(candidates), 0)
def test_update_candidates_create_candidate_id(self): manager = GroupManager(self.a1id) manager.group.save() manager.update_candidates([self.create_candidatedict(username='******', candidate_id='secret')]) candidates = manager.get_group_from_db().candidates.all() created = candidates[0] self.assertEquals(created.candidate_id, 'secret')
def test_update_candidates_delete_as_nobody(self): nobody = self.testhelper.create_user('nobody') manager = GroupManager(nobody, self.a1id) manager.group.save() manager.group.candidates.create(student=self.testhelper.user1) manager.group.candidates.create(student=self.testhelper.user2) with self.assertRaises(PermissionDeniedError): manager.update_candidates([])
def test_update_group(self): self.assertEquals(AssignmentGroup.objects.all().count(), 0) manager = GroupManager(self.a1id) self.assertEquals(manager.group.id, None) manager.update_group(name='Nametest', is_open=False) self.assertIsNotNone(manager.group.id) self.assertEquals(manager.group.name, 'Nametest') self.assertEquals(manager.group.is_open, False) self.assertEquals(AssignmentGroup.objects.all().count(), 1)
def test_update_candidates_create_duplicate_allowed(self): manager = GroupManager(self.testhelper.notusedforanything, self.a1id) manager.group.save() created = manager.group.candidates.create(student=self.testhelper.user1) # Does not raise exception, event if they are the same user manager.update_candidates([self.create_candidatedict(id=created.id, candidate_id=created.candidate_id, username='******'), self.create_candidatedict(username='******')])
def test_create_first_deadline(self): self.testhelper.add_to_path('uni;sub.p1.a1.g1') g1 = self.testhelper.sub_p1_a1_g1 g1.parentnode.first_deadline = datetime(2005, 1, 1) g1.parentnode.save() manager = GroupManager(self.testhelper.notusedforanything, self.a1id, g1.id) self.assertEquals(manager.group.id, self.testhelper.sub_p1_a1_g1.id) manager.create_first_deadline_if_available() self.assertEquals(manager.group.deadlines.count(), 1) self.assertEquals(manager.group.deadlines.all()[0].deadline, datetime(2005, 1, 1))
def test_update_candidates_complex(self): manager = GroupManager(self.a1id) manager.group.save() manager.group.candidates.create(student=self.testhelper.user1) manager.group.candidates.create(student=self.testhelper.user2) manager.update_candidates([self.create_candidatedict(id=self.testhelper.user1.id), # keep user1 # ... delete user2 self.create_candidatedict(username='******')]) # create user3 candidates = manager.get_group_from_db().candidates.all() self.assertEquals(len(candidates), 2) ids = [candidate.id for candidate in candidates] self.assertEquals(set(ids), set([self.testhelper.user1.id, self.testhelper.user3.id]))
def test_update_examiners_complex(self): manager = GroupManager(self.a1id) manager.group.save() manager.group.examiners.create(user=self.testhelper.user1) manager.group.examiners.create(user=self.testhelper.user2) manager.update_examiners([self.create_examinerdict(id=self.testhelper.user1.id), # keep user1 # ... delete user2 self.create_examinerdict(username='******')]) # create user3 examiners = manager.get_group_from_db().examiners.all() self.assertEquals(len(examiners), 2) ids = [examiner.id for examiner in examiners] self.assertEquals(set(ids), set([self.testhelper.user1.id, self.testhelper.user3.id]))
def test_update_tags(self): manager = GroupManager(self.a1id) manager.group.save() manager.update_tags([self.create_tagdict('mytag')]) tags = manager.get_group_from_db().tags.all() self.assertEquals(len(tags), 1) created = tags[0] self.assertEquals(created.tag, 'mytag') manager.update_tags([self.create_tagdict('tag1'), self.create_tagdict('tag2')]) tagsObjs = manager.get_group_from_db().tags.all() self.assertEquals(len(tagsObjs), 2) tags = [tagObj.tag for tagObj in tagsObjs] self.assertEquals(set(tags), set(['tag1', 'tag2']))
def test_update_examiners_create(self): manager = GroupManager(self.a1id) manager.group.save() manager.update_examiners([self.create_examinerdict(username='******')]) examiners = manager.get_group_from_db().examiners.all() self.assertEquals(len(examiners), 1) created = examiners[0] self.assertEquals(created.user.id, self.testhelper.user1.id) manager.update_examiners([self.create_examinerdict(id=created.id), self.create_examinerdict(username='******')]) examiners = manager.get_group_from_db().examiners.all() self.assertEquals(len(examiners), 2) ids = [examiner.id for examiner in examiners] self.assertEquals(set(ids), set([self.testhelper.user1.id, self.testhelper.user2.id]))
def test_update_candidates_create(self): manager = GroupManager(self.a1id) manager.group.save() manager.update_candidates([self.create_candidatedict(username='******')]) candidates = manager.get_group_from_db().candidates.all() self.assertEquals(len(candidates), 1) created = candidates[0] self.assertEquals(created.student.id, self.testhelper.user1.id) self.assertEquals(created.candidate_id, None) manager.update_candidates([self.create_candidatedict(id=created.id), self.create_candidatedict(username='******')]) candidates = manager.get_group_from_db().candidates.all() self.assertEquals(len(candidates), 2) ids = [candidate.id for candidate in candidates] self.assertEquals(set(ids), set([self.testhelper.user1.id, self.testhelper.user2.id]))
def test_update_candidates_create_duplicate_allowed(self): manager = GroupManager(self.a1id) manager.group.save() manager.group.candidates.create(student=self.testhelper.user1) manager.update_candidates([self.create_candidatedict(username='******')]) # Does not raise exception
def test_update_examiners_create_duplicate(self): manager = GroupManager(self.a1id) manager.group.save() manager.group.examiners.create(user=self.testhelper.user1) with self.assertRaises(ValidationError): manager.update_examiners([self.create_examinerdict(username='******')])
def test_create_first_deadline_not_available(self): self.testhelper.add_to_path('uni;sub.p1.a1.g1') manager = GroupManager(self.testhelper.notusedforanything, self.a1id, self.testhelper.sub_p1_a1_g1.id) self.assertEquals(manager.group.id, self.testhelper.sub_p1_a1_g1.id) manager.create_first_deadline_if_available() self.assertEquals(manager.group.deadlines.count(), 0)