def test_game_in_the_past(client): game = mixer.blend('games.Game', datetime=datetime.utcnow() - timedelta(1)) list_url = reverse('game-list') res = client.get(list_url) assert res.status_code == status.HTTP_200_OK, 'Request should succeed' assert res.data['results'] == [], 'The game should not be in the results' res = client.get(list_url, {'all': 'true'}) assert res.data['count'] == 1, 'Unless `all` param is supplied' retrive_url = reverse('game-detail', (game.id, )) res = client.get(retrive_url) assert res.status_code == status.HTTP_200_OK, \ 'Game should be retrievable without additional parameters' mixer.blend('games.RsvpStatus', game=game, player=client.user, status=RsvpStatus.GOING) my_url = reverse('game-my') res = client.get(my_url, {'all': 'true'}) assert res.data['count'] == 1, '`all` param should work for my games'
def test_current_user_view(client): res = client.get(reverse('current-user')) assert res.status_code == status.HTTP_200_OK, \ 'Current user request should succeed when user is authenticated' assert res.data['id'] == client.user.id, \ 'users/me should return data info about the logged in user'
def test_pickup_games(client): mixer.cycle(5).blend('games.Game') url = reverse('game-list') res = client.get(url) assert res.status_code == status.HTTP_200_OK, 'Request should succeed' assert res.data['count'] == 5, 'Should be 5 games'
def test_team_games(client): team = mixer.blend('teams.Team') mixer.cycle(5).blend('games.Game', teams=[team]) url = reverse('team-games-list', (team.id, )) res = client.get(url) assert res.status_code == status.HTTP_200_OK, 'Request should succeed' assert res.data['count'] == 5, 'User should have 5 invites'
def test_game_invites(client): mixer.cycle(5).blend('games.RsvpStatus', status=RsvpStatus.INVITED, player=client.user) url = reverse('game-invites') res = client.get(url) assert res.status_code == status.HTTP_200_OK, 'Request should succeed' assert res.data['count'] == 5, 'User should have 5 invites'
def test_my_games(): user = mixer.blend('users.User') mixer.cycle(5).blend('games.RsvpStatus', status=RsvpStatus.GOING, player=user) client = APIClient() url = reverse('game-my') res = client.get(url) assert res.status_code == status.HTTP_401_UNAUTHORIZED, \ 'Should not be accessable when not authenticated' client.force_authenticate(user=user) res = client.get(url) assert res.status_code == status.HTTP_200_OK, 'Request should succeed' assert res.data['count'] == 5, 'User should have 5 games'
def test_team_retrieve(): user = mixer.blend('users.User') client = APIClient() client.force_authenticate(user=user) team = mixer.blend('teams.Team') url = reverse('team-detail', (team.id, )) res = client.get(url) assert res.status_code == status.HTTP_200_OK, \ 'Should be able to retrieve team info'
def test_my_teams(): user = mixer.blend('users.User') client = APIClient() client.force_authenticate(user=user) team = mixer.blend('teams.Team', managers=[user]) url = reverse('team-managed') res = client.get(url) assert res.status_code == status.HTTP_200_OK, \ 'Should be able to retrieve managed teams' assert res.data['count'] == 1, \ 'Should be exactly one'
def test_user_has_game_invites(): user = mixer.blend('users.User') rsvp = mixer.blend('games.RsvpStatus', player=user, status=RsvpStatus.INVITED) role = mixer.blend('teams.Role', player=user, status=Role.INVITED) client = APIClient() client.force_authenticate(user=user) res = client.get(reverse('current-user')) assert 'invites' in res.data, 'Sould have invites' assert res.data['invites'] == {'total': 2, 'teams': 1, 'games': 1}, \ 'Sould have two invites total, one for games and one for teams'
def test_rsvps_annotation(): user = mixer.blend('users.User') game = mixer.blend('games.Game') RsvpStatus(player=user, game=game, status=RsvpStatus.GOING).save() RsvpStatus(player=mixer.blend('users.User'), game=game, status=RsvpStatus.GOING).save() annotated_game = Game.objects.with_rsvps(user)[0] assert annotated_game.rsvp == RsvpStatus.GOING client = APIClient() client.force_authenticate(user) res = client.get(reverse('game-list')) assert res.data['results'][0]['rsvp'] == RsvpStatus.GOING
def test_rsvp_retreive(client): rsvp = mixer.blend('games.RsvpStatus') res = client.get(reverse('rsvp-detail', (rsvp.game.id, rsvp.id))) assert res.status_code == status.HTTP_200_OK, \ 'RsvpStatus can be accessed by any user'
def test_rsvp_list(client): game = mixer.blend('games.Game') rsvps = mixer.cycle(5).blend('games.RsvpStatus', game=game) res = client.get(reverse('rsvp-list', (game.id, ))) assert res.data['count'] == 5, 'Should have 5 rsvps'