Skip to content

Commit

Permalink
moved match serializer tests to view tests since filter moved there a…
Browse files Browse the repository at this point in the history
…nd modified tournmaent queryset to make it work for external private id
  • Loading branch information
nour-massri committed Jan 20, 2025
1 parent fc1a3b9 commit f1a10ab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 113 deletions.
139 changes: 28 additions & 111 deletions backend/siarnaq/api/compete/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,65 +669,6 @@ def test_not_admin_has_self_no_staff_team_tournament_participants(self):
},
)

def test_not_admin_has_self_no_staff_team_tournament_hidden(self):
serializer = MatchSerializer(
context={
"episode_id": self.e1.pk,
"team_id": self.teams[0],
"user_id": self.users[0].pk,
"user_is_staff": False,
"team_is_staff": False,
}
)
match = Match.objects.create(
episode=self.e1,
tournament_round=self.r_hidden,
alternate_order=True,
is_ranked=False,
)
red = MatchParticipant.objects.create( # noqa: F841
team=self.teams[0],
submission=self.submissions[0],
match=match,
player_index=0,
score=0,
rating=Rating.objects.create(),
)
blue = MatchParticipant.objects.create( # noqa: F841
team=self.teams[1],
submission=self.submissions[1],
match=match,
player_index=1,
score=1,
rating=Rating.objects.create(),
)
match.maps.add(self.map)
data = serializer.to_representation(match)
self.assertEqual(
data,
{
"id": match.pk,
"status": str(match.status),
"episode": match.episode.pk,
"tournament_round": {
"id": self.r_hidden.pk,
"tournament": self.r_hidden.tournament.pk,
"external_id": self.r_hidden.external_id,
"name": self.r_hidden.name,
"maps": None,
"release_status": self.r_hidden.release_status,
"display_order": self.r_hidden.display_order,
"in_progress": self.r_hidden.in_progress,
},
"participants": None,
"maps": None,
"alternate_order": match.alternate_order,
"created": match.created.isoformat().replace("+00:00", "Z"),
"is_ranked": match.is_ranked,
"replay_url": None,
},
)

def test_not_admin_has_self_no_staff_team_tournament_none(self):
serializer = MatchSerializer(
context={
Expand Down Expand Up @@ -870,58 +811,6 @@ def test_not_admin_no_self_has_staff_team(self):
},
)

def test_not_admin_no_self_has_invisible_team(self):
self.teams[-1].status = TeamStatus.INVISIBLE
self.teams[-1].save()
serializer = MatchSerializer(
context={
"episode_id": self.e1.pk,
"team_id": self.teams[0],
"user_id": self.users[0].pk,
"user_is_staff": False,
"team_is_staff": False,
}
)
match = Match.objects.create(
episode=self.e1,
tournament_round=None,
alternate_order=True,
is_ranked=False,
)
red = MatchParticipant.objects.create( # noqa: F841
team=self.teams[1],
submission=self.submissions[1],
match=match,
player_index=0,
score=1,
rating=Rating.objects.create(),
)
blue = MatchParticipant.objects.create( # noqa: F841
team=self.teams[-1],
submission=self.submissions[-1],
match=match,
player_index=1,
score=1,
rating=Rating.objects.create(),
)
match.maps.add(self.map)
data = serializer.to_representation(match)
self.assertEqual(
data,
{
"id": match.pk,
"status": str(match.status),
"episode": match.episode.pk,
"tournament_round": None,
"participants": None,
"maps": None,
"alternate_order": match.alternate_order,
"created": match.created.isoformat().replace("+00:00", "Z"),
"is_ranked": match.is_ranked,
"replay_url": None,
},
)

def test_not_admin_no_self_no_staff_team(self):
serializer = MatchSerializer(
context={
Expand Down Expand Up @@ -1249,6 +1138,34 @@ def test_my_none(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.json()["results"]), 1)

def test_not_admin_has_self_no_staff_team_tournament_hidden(self):
match = Match.objects.create(
episode=self.e1,
tournament_round=self.r_public_hidden,
alternate_order=True,
is_ranked=False,
)
match.maps.add(self.map)
response = self.client.get(
reverse("match-scrimmage", kwargs={"episode_id": "e1"})
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.json()["results"]), 0)

def test_not_admin_no_self_has_invisible_team(self):
match = Match.objects.create(
episode=self.e1,
tournament_round=None,
alternate_order=True,
is_ranked=False,
)
match.maps.add(self.map)
response = self.client.get(
reverse("match-scrimmage", kwargs={"episode_id": "e1"})
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.json()["results"]), 1)


class ScrimmageRequestViewSetTestCase(APITransactionTestCase):
"""Test suite for the Scrimmage Requests API."""
Expand Down
8 changes: 6 additions & 2 deletions backend/siarnaq/api/compete/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@ def tournament(self, request, *, episode_id):
Passing the external_id_private of a tournament allows match lookup for the
tournament, even if it's private. Client uses the external_id_private parameter
"""
queryset = self.get_queryset()
queryset = (
Match.objects.filter(episode=self.kwargs["episode_id"]).select_related(
"tournament_round__tournament"
)
).order_by("-pk")

external_id_private = self.request.query_params.get("external_id_private")
tournaments = None
Expand All @@ -361,7 +365,7 @@ def tournament(self, request, *, episode_id):
tournaments = tournaments.filter(pk=tournament_id)
if not tournaments.exists():
return Response(None, status=status.HTTP_404_NOT_FOUND)
queryset = self.get_queryset().filter(
queryset = queryset.filter(
tournament_round__tournament__in=Subquery(tournaments.values("pk"))
)

Expand Down

0 comments on commit f1a10ab

Please sign in to comment.