Fix owners not getting imported correctly
This commit is contained in:
parent
026bc57f77
commit
df2941cdbc
7 changed files with 138 additions and 9 deletions
|
|
@ -35,6 +35,7 @@ class RSSFeedTestCase(TestCase):
|
|||
game=self.game,
|
||||
start_at=timezone.now(),
|
||||
end_at=timezone.now() + timedelta(days=7),
|
||||
operation_name="DropCampaignDetails",
|
||||
)
|
||||
|
||||
def test_organization_feed(self) -> None:
|
||||
|
|
@ -94,6 +95,7 @@ class RSSFeedTestCase(TestCase):
|
|||
game=other_game,
|
||||
start_at=timezone.now(),
|
||||
end_at=timezone.now() + timedelta(days=7),
|
||||
operation_name="DropCampaignDetails",
|
||||
)
|
||||
|
||||
# Get feed for first game
|
||||
|
|
@ -126,6 +128,7 @@ class RSSFeedTestCase(TestCase):
|
|||
game=other_game,
|
||||
start_at=timezone.now(),
|
||||
end_at=timezone.now() + timedelta(days=7),
|
||||
operation_name="DropCampaignDetails",
|
||||
)
|
||||
|
||||
# Get feed for first organization
|
||||
|
|
|
|||
75
twitch/tests/test_game_owner_organization.py
Normal file
75
twitch/tests/test_game_owner_organization.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from twitch.management.commands.better_import_drops import Command
|
||||
from twitch.models import Game
|
||||
from twitch.models import Organization
|
||||
|
||||
|
||||
class GameOwnerOrganizationTests(TestCase):
|
||||
"""Tests for correct precedence of game owner organization during import."""
|
||||
|
||||
def test_game_owner_organization_precedence(self) -> None:
|
||||
"""If both owner and ownerOrganization are present, game owner should be ownerOrganization."""
|
||||
command = Command()
|
||||
command.pre_fill_cache()
|
||||
|
||||
payload = {
|
||||
"data": {
|
||||
"user": {
|
||||
"id": "17658559",
|
||||
"dropCampaign": {
|
||||
"id": "test-campaign-1",
|
||||
"name": "Rustmas 2025",
|
||||
"description": "Test campaign desc",
|
||||
"startAt": "2025-12-08T18:00:00Z",
|
||||
"endAt": "2026-01-01T07:59:59.999Z",
|
||||
"accountLinkURL": "https://www.twitch.tv/",
|
||||
"detailsURL": "https://help.twitch.tv/s/article/twitch-chat-badges-guide",
|
||||
"imageURL": "https://static-cdn.jtvnw.net/twitch-quests-assets/CAMPAIGN/495ebb6b-8134-4e51-b9d0-1f4a221b4f8d.png",
|
||||
"status": "ACTIVE",
|
||||
"self": {"isAccountConnected": True, "__typename": "DropCampaignSelfEdge"},
|
||||
"game": {
|
||||
"id": "263490",
|
||||
"slug": "rust",
|
||||
"displayName": "Rust",
|
||||
"__typename": "Game",
|
||||
"ownerOrganization": {
|
||||
"id": "d32de13d-937e-4196-8198-1a7f875f295a",
|
||||
"name": "Twitch Gaming",
|
||||
"__typename": "Organization",
|
||||
},
|
||||
},
|
||||
"owner": {"id": "other-org-id", "name": "Other Org", "__typename": "Organization"},
|
||||
"timeBasedDrops": [],
|
||||
"eventBasedDrops": [],
|
||||
"allow": {"channels": None, "isEnabled": False, "__typename": "DropCampaignACL"},
|
||||
"__typename": "DropCampaign",
|
||||
},
|
||||
"__typename": "User",
|
||||
},
|
||||
},
|
||||
"extensions": {"operationName": "DropCampaignDetails"},
|
||||
}
|
||||
|
||||
# Run import logic
|
||||
success, broken_dir = command.process_responses(
|
||||
responses=[payload],
|
||||
file_path=Path("test_owner_org.json"),
|
||||
options={},
|
||||
)
|
||||
assert success is True
|
||||
assert broken_dir is None
|
||||
|
||||
# Check game owner is Twitch Gaming, not Other Org
|
||||
game: Game = Game.objects.get(twitch_id="263490")
|
||||
org: Organization = Organization.objects.get(twitch_id="d32de13d-937e-4196-8198-1a7f875f295a")
|
||||
assert game.owner == org
|
||||
assert game.owner
|
||||
assert game.owner.name == "Twitch Gaming"
|
||||
|
||||
# Check both organizations exist
|
||||
Organization.objects.get(twitch_id="other-org-id")
|
||||
|
|
@ -42,6 +42,7 @@ class TestSearchView:
|
|||
name="Test Campaign",
|
||||
description="A test campaign",
|
||||
game=game,
|
||||
operation_name="DropCampaignDetails",
|
||||
)
|
||||
drop: TimeBasedDrop = TimeBasedDrop.objects.create(
|
||||
twitch_id="1011",
|
||||
|
|
@ -262,6 +263,7 @@ class TestChannelListView:
|
|||
twitch_id=f"campaign{i}",
|
||||
name=f"Campaign {i}",
|
||||
game=game,
|
||||
operation_name="DropCampaignDetails",
|
||||
)
|
||||
campaign.allow_channels.add(channel)
|
||||
campaigns.append(campaign)
|
||||
|
|
@ -350,6 +352,7 @@ class TestChannelListView:
|
|||
twitch_id=f"campaign_ch2_{i}",
|
||||
name=f"Campaign Ch2 {i}",
|
||||
game=game,
|
||||
operation_name="DropCampaignDetails",
|
||||
)
|
||||
campaign.allow_channels.add(channel2)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue