Esempio 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)
Esempio n. 2
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,
    )