Exemplo n.º 1
0
    def test_all_games_from_same_group(self, mock_has_perm):
        mock_has_perm.return_value = True

        event = EventFactory()
        user = UserFactory()
        other_group = GroupFactory()
        games_user_group = GameFactory.create_batch(
            3, group=user.group, creator=user, event=event
        )
        games_other_group = GameFactory.create_batch(
            3, group=other_group, creator=user, event=event
        )
        self.client.force_login(user)
        response = self.client.get(
            reverse(
                "booking:event_games_group",
                kwargs={
                    "event_slug": event.slug,
                    "group_slug": user.group.slug,
                },
            ),
        )
        self.assertEqual(response.context["current_group"], user.group)
        for game in games_other_group:
            self.assertNotIn(
                game,
                response.context["games"][game.day][game.part_of_day],
                "game from other group is part of context",
            )
        for game in games_user_group:
            self.assertIn(
                game,
                response.context["games"][game.day][game.part_of_day],
                "game from own group is not part of context",
            )
        # Now check with reversed groups
        response = self.client.get(
            reverse(
                "booking:event_games_group",
                kwargs={
                    "event_slug": event.slug,
                    "group_slug": other_group.slug,
                },
            ),
        )
        self.assertEqual(response.context["current_group"], other_group)
        for game in games_other_group:
            self.assertIn(
                game,
                response.context["games"][game.day][game.part_of_day],
                "game from other group is not part of context",
            )
        for game in games_user_group:
            self.assertNotIn(
                game,
                response.context["games"][game.day][game.part_of_day],
                "game from own group is part of context",
            )
        mock_has_perm.assert_any_call(user, "booking.view_others_groups_bookings", None)
Exemplo n.º 2
0
 def test_filtered_bookings_not_in_context(self):
     game = GameFactory()
     bookings_gm = BookingFactory.create_batch(3,
                                               game=game,
                                               material__gm=True)
     bookings_no_gm = BookingFactory.create_batch(2,
                                                  game=game,
                                                  material__gm=False)
     self.client.force_login(game.creator)
     response = self.client.get(
         reverse(
             "booking:event_list_group",
             kwargs={
                 "event_slug": game.event.slug,
                 "group_slug": game.creator.group.slug,
             },
         ) + "?gm=True", )
     # There are no ListViewFilters, hence all bookings should be part of the
     #  leftover ListView.
     lv, lv_bookings = response.context["list_views"][game.day][
         game.part_of_day][0]
     for booking in bookings_gm:
         self.assertIn(booking, lv_bookings,
                       "filtered booking is not in listview")
     for booking in bookings_no_gm:
         self.assertNotIn(booking, lv_bookings,
                          "excluded booking is part of listview")
     self.assertTemplateUsed(response, "booking/event/list-view.html")
Exemplo n.º 3
0
def _get_sibling_games(n=5, part_of_day="AF", **kwargs):
    if "event" not in kwargs.keys():
        kwargs["event"] = EventFactory()
    if "group" not in kwargs.keys():
        kwargs["group"] = GroupFactory()
    return GameFactory.create_batch(
        n,
        day=kwargs["event"].event_start,
        part_of_day=part_of_day,
        **kwargs,
    )
Exemplo n.º 4
0
 def test_other_event_game_not_in_context(self):
     game = GameFactory()
     other_game = GameFactory(
         creator=game.creator,
         event__event_start=game.event.event_start,
         event__event_end=game.event.event_end,
     )  # has other event but with same dates
     self.client.force_login(game.creator)
     response = self.client.get(
         reverse(
             "booking:event_games_group",
             kwargs={
                 "event_slug": game.event.slug,
                 "group_slug": game.creator.group.slug,
             },
         ),
     )
     self.assertNotIn(
         other_game,
         response.context["games"][other_game.day][other_game.part_of_day],
         "game from other event is part of context",
     )
Exemplo n.º 5
0
 def test_cannot_export_excel_not_allowed(self):
     other_group = GroupFactory()
     game = GameFactory(group=other_group)
     bookings = BookingFactory.create_batch(5, game=game)
     self.client.force_login(UserFactory())  # not from 'other_group'
     response = self.client.get(
         reverse(
             "booking:api:excel_event",
             kwargs={
                 "event_slug": game.event.slug,
                 "group_slug": game.creator.group.slug,
             },
         )
     )
     self.assertEqual(response.status_code, 403)
Exemplo n.º 6
0
 def test_game_in_context(self):
     game = GameFactory()
     self.client.force_login(game.creator)
     response = self.client.get(
         reverse(
             "booking:event_games_group",
             kwargs={
                 "event_slug": game.event.slug,
                 "group_slug": game.creator.group.slug,
             },
         ),
     )
     self.assertIn(
         game,
         response.context["games"][game.day][game.part_of_day],
         "game is not part of context",
     )
Exemplo n.º 7
0
 def test_can_export_excel(self):
     game = GameFactory()
     bookings = BookingFactory.create_batch(5, game=game)
     self.client.force_login(game.creator)
     response = self.client.get(
         reverse(
             "booking:api:excel_event",
             kwargs={
                 "event_slug": game.event.slug,
                 "group_slug": game.creator.group.slug,
             },
         )
     )
     self.assertEqual(
         response["content-type"],
         "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
     )
Exemplo n.º 8
0
 def test_lists_and_bookings_in_context(self):
     game = GameFactory()
     bookings = BookingFactory.create_batch(5, game=game)
     self.client.force_login(game.creator)
     response = self.client.get(
         reverse(
             "booking:event_list_group",
             kwargs={
                 "event_slug": game.event.slug,
                 "group_slug": game.creator.group.slug,
             },
         ), )
     # There are no ListViewFilters, hence all bookings should be part of the
     #  leftover ListView.
     lv, lv_bookings = response.context["list_views"][game.day][
         game.part_of_day][0]
     self.assertCountEqual(
         bookings, lv_bookings,
         "not all bookings are part of the leftover listview")
     self.assertTemplateUsed(response, "booking/event/list-view.html")
Exemplo n.º 9
0
 def test_delete_user_with_games_keeps_games(self):
     # User 1 and 2 are from the same group
     # User 3 is from a different group
     user = UserFactory()
     game = GameFactory(creator=user)
     group = user.group
     user2 = UserFactory(group=group)
     game2 = GameFactory(creator=user2)
     user3 = UserFactory()
     game3 = GameFactory(creator=user3)
     self.assertEqual(
         group,
         game.creator.group,
         "game1 not associated with creator group",
     )
     self.assertEqual(
         group,
         game2.creator.group,
         "game2 not associated with creator group",
     )
     self.assertNotEqual(
         game.creator,
         game2.creator,
         "games are associated with same creator",
     )
     user.delete()
     game.refresh_from_db()
     user2.delete()
     game2.refresh_from_db()
     user3.delete()
     game3.refresh_from_db()
     # User 1 and 2 should be replaced by the same sentinel user
     # User 3 should be replaced by another sentinel user
     # User count should be 2 now as user 1 and 2 are 'merged'.
     self.assertEqual(
         get_user_model().objects.count(),
         2,
         "users were not replaced",
     )
     self.assertEqual(Game.objects.count(), 3, "game was deleted")
     self.assertEqual(group, game.creator.group, "game1 changed group")
     self.assertEqual(group, game2.creator.group, "game2 changed group")
     self.assertEqual(
         game.creator.email,
         f"deleted_user@{group}",
         "creator was not replaced with sentinel user",
     )
     self.assertEqual(
         game2.creator.email,
         f"deleted_user@{group}",
         "creator was not replaced with sentinel user",
     )
     self.assertEqual(
         game.creator,
         game2.creator,
         "different sentinel users were used for the same group",
     )
     self.assertNotEqual(
         game.creator,
         game3.creator,
         "same sentinel user was used for different groups",
     )