Refactor GameFeed and GameDetailView to use 'owners' instead of 'owner'; update related tests
All checks were successful
Deploy to Server / deploy (push) Successful in 10s
All checks were successful
Deploy to Server / deploy (push) Successful in 10s
This commit is contained in:
parent
6b936f4cf7
commit
77d9d448d7
4 changed files with 65 additions and 13 deletions
|
|
@ -64,6 +64,14 @@ class RSSFeedTestCase(TestCase):
|
|||
response: _MonkeyPatchedWSGIResponse = self.client.get(url)
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "application/rss+xml; charset=utf-8"
|
||||
content: str = response.content.decode("utf-8")
|
||||
assert "Test Game by Test Organization" in content
|
||||
|
||||
expected_rss_link: str = reverse(
|
||||
"twitch:game_campaign_feed",
|
||||
args=[self.game.twitch_id],
|
||||
)
|
||||
assert expected_rss_link in content
|
||||
|
||||
def test_campaign_feed(self) -> None:
|
||||
"""Test campaign feed returns 200."""
|
||||
|
|
@ -392,7 +400,8 @@ def test_game_feed_queries_bounded(
|
|||
game.owners.add(org)
|
||||
|
||||
url: str = reverse("twitch:game_feed")
|
||||
with django_assert_num_queries(1, exact=True):
|
||||
# One query for games + one prefetch query for owners.
|
||||
with django_assert_num_queries(2, exact=True):
|
||||
response: _MonkeyPatchedWSGIResponse = client.get(url)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
|
|
|||
|
|
@ -930,6 +930,36 @@ class TestChannelListView:
|
|||
assert response.status_code == 200
|
||||
assert "game" in response.context
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_game_detail_view_serializes_owners_field(
|
||||
self,
|
||||
client: Client,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Game detail JSON payload should use `owners` (M2M), not stale `owner`."""
|
||||
org: Organization = Organization.objects.create(
|
||||
twitch_id="org-game-detail",
|
||||
name="Org Game Detail",
|
||||
)
|
||||
game: Game = Game.objects.create(
|
||||
twitch_id="g2-owners",
|
||||
name="Game2 Owners",
|
||||
display_name="Game2 Owners",
|
||||
)
|
||||
game.owners.add(org)
|
||||
|
||||
monkeypatch.setattr("twitch.views.format_and_color_json", lambda data: data)
|
||||
|
||||
url: str = reverse("twitch:game_detail", args=[game.twitch_id])
|
||||
response: _MonkeyPatchedWSGIResponse = client.get(url)
|
||||
assert response.status_code == 200
|
||||
|
||||
game_data: dict[str, Any] = response.context["game_data"]
|
||||
fields: dict[str, Any] = game_data["fields"]
|
||||
assert "owners" in fields
|
||||
assert fields["owners"] == [org.pk]
|
||||
assert "owner" not in fields
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_org_list_view(self, client: Client) -> None:
|
||||
"""Test org list view returns 200 and has orgs in context."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue