Exemple #1
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)
Exemple #2
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')
Exemple #3
0
 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([])
Exemple #4
0
 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='******')])
Exemple #5
0
 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]))
Exemple #6
0
    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]))
Exemple #7
0
 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