Example #1
0
 def test_join_finished_trial(self):
     "Should raise"
     owner = models.User(pk=1)
     user = models.User(pk=2)
     trial = models.Trial(owner=owner, finish_date=self.yesterday)
     with self.assertRaises(exceptions.TrialFinishedError):
         trial.join(user)
Example #2
0
 def test_join_finished_trial(self):
     "Should raise"
     owner = models.User(pk=1)
     user = models.User(pk=2)
     trial = models.Trial(owner=owner, stopped=True)
     with self.assertRaises(exceptions.TrialFinishedError):
         trial.join(user)
Example #3
0
 def test_join_too_many_participants(self, pset):
     "should raise"
     owner = models.User(pk=1)
     trial = models.Trial(owner=owner,
                          max_participants=2,
                          finish_date=self.tomorrow)
     pset.count.return_value = 2
     with self.assertRaises(exceptions.TooManyParticipantsError):
         trial.join(models.User())
Example #4
0
 def test_join_second_time(self):
     "should raise"
     owner = models.User(pk=1)
     with patch.object(models.Participant.objects, 'filter') as pfilt:
         pfilt.return_value.count.return_value = 1
         trial = models.Trial(owner=owner)
         user = models.User()
         with self.assertRaises(exceptions.AlreadyJoinedError):
             trial.join(user)
         pfilt.assert_called_once_with(trial=trial, user=user)
Example #5
0
 def test_join(self):
     "Should create participant"
     owner = models.User(pk=1)
     trial = models.Trial(owner=owner, min_participants=2)
     trial.save()
     user = models.User(pk=2)
     with patch.object(models, 'Participant') as ppart:
         ppart.objects.filter.return_value.count.return_value = 0
         trial.join(user)
         ppart.objects.filter.assert_called_once_with(trial=trial, user=user)
         ppart.objects.filter.return_value.count.assert_called_once_with()
         ppart.assert_called_once_with(trial=trial, user=user)
Example #6
0
 def setUp(self):
     super(ParticipantTestCase, self).setUp()
     self.user = models.User(email='*****@*****.**')
     self.trial = models.Trial(pk=1, title='This', group_a='Do it')
     self.group = models.Group(trial=self.trial, name='A')
     self.participant = models.Participant(user=self.user,
                                           trial=self.trial,
                                           group=self.group)
Example #7
0
 def test_join_is_owner(self):
     "Should raise"
     user = models.User(pk=2, email='*****@*****.**')
     trial = models.Trial(owner=user, min_participants=20)
     trial.save()
     variable = models.Variable(question="Why", trial=trial)
     variable.save()
     trial.join(user)
     self.assertEqual(1, trial.participant_set.filter(user=user).count())
Example #8
0
 def setUp(self):
     super(ParticipantTestCase, self).setUp()
     self.user = models.User(email='*****@*****.**', pk=1)
     self.trial = models.Trial(pk=1, title='This', group_a='Do it', min_participants=20, owner=self.user)
     self.trial.save()
     self.variable = models.Variable(question='Why?', trial=self.trial)
     self.variable.save()
     self.group = models.Group(trial=self.trial, name='A')
     self.participant = models.Participant(user=self.user,
                                           trial=self.trial,
                                           group=self.group)
Example #9
0
 def test_join_is_owner(self):
     "Should raise"
     user = models.User()
     trial = models.Trial(owner=user)
     with self.assertRaises(exceptions.TrialOwnerError):
         trial.join(user)