示例#1
0
    def test_single_wimp(self):
        wimp_par = factories.ParticipantFactory.create()
        wimp_group = Group.objects.get(name='WIMP')
        self.assertFalse(wimp_group.user_set.exists())

        wimp_group.user_set.add(wimp_par.user)
        self.assertCountEqual(wimp.active_wimps(), [wimp_par])
        self.assertEqual(wimp_par, wimp.current_wimp())
示例#2
0
    def test_handle_edge_case_of_user_without_participant(self):
        no_par_user = factories.UserFactory.create()
        self.assertFalse(
            models.Participant.objects.filter(user_id=no_par_user.pk).exists())

        wimp_par = factories.ParticipantFactory.create()

        wimp_group = Group.objects.get(name='WIMP')
        wimp_group.user_set.add(no_par_user)
        wimp_group.user_set.add(wimp_par.user)
        self.assertCountEqual(wimp.active_wimps(), [wimp_par])
        self.assertEqual(wimp_par, wimp.current_wimp())
示例#3
0
    def test_wimps_sorted_by_time_made_wimp(self):
        wimp_group = Group.objects.get(name='WIMP')

        # Participants are created in different orders
        second_wimp = factories.ParticipantFactory.create()
        first_wimp = factories.ParticipantFactory.create()
        third_wimp = factories.ParticipantFactory.create()

        wimp_group.user_set.add(first_wimp.user)
        wimp_group.user_set.add(second_wimp.user)
        wimp_group.user_set.add(third_wimp.user)

        self.assertEqual(list(wimp.active_wimps()),
                         [third_wimp, second_wimp, first_wimp])
        self.assertEqual(third_wimp, wimp.current_wimp())
示例#4
0
 def test_no_active_wimps(self):
     self.assertFalse(Group.objects.get(name='WIMP').user_set.exists())
     self.assertCountEqual(wimp.active_wimps(), [])
     self.assertIsNone(wimp.current_wimp())
示例#5
0
 def get_context_data(self, **kwargs):
     context_data = super().get_context_data(**kwargs)
     context_data['wimps'] = wimp.active_wimps()
     return context_data