This commit is contained in:
parent
4d53a46850
commit
415dd12fd9
16 changed files with 843 additions and 379 deletions
|
|
@ -1,7 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import json
|
||||
from datetime import timedelta
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.test import Client
|
||||
from django.test import TestCase
|
||||
|
|
@ -11,6 +13,9 @@ from twitch.models import DropCampaign
|
|||
from twitch.models import Game
|
||||
from twitch.models import Organization
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.test.client import _MonkeyPatchedWSGIResponse
|
||||
|
||||
|
||||
class ExportViewsTestCase(TestCase):
|
||||
"""Test export views for CSV and JSON formats."""
|
||||
|
|
@ -20,13 +25,13 @@ class ExportViewsTestCase(TestCase):
|
|||
self.client = Client()
|
||||
|
||||
# Create test organization
|
||||
self.org = Organization.objects.create(
|
||||
self.org: Organization = Organization.objects.create(
|
||||
twitch_id="org123",
|
||||
name="Test Organization",
|
||||
)
|
||||
|
||||
# Create test game
|
||||
self.game = Game.objects.create(
|
||||
self.game: Game = Game.objects.create(
|
||||
twitch_id="game123",
|
||||
name="Test Game",
|
||||
display_name="Test Game Display",
|
||||
|
|
@ -34,8 +39,8 @@ class ExportViewsTestCase(TestCase):
|
|||
self.game.owners.add(self.org)
|
||||
|
||||
# Create test campaign
|
||||
now = timezone.now()
|
||||
self.campaign = DropCampaign.objects.create(
|
||||
now: datetime.datetime = timezone.now()
|
||||
self.campaign: DropCampaign = DropCampaign.objects.create(
|
||||
twitch_id="campaign123",
|
||||
name="Test Campaign",
|
||||
description="A test campaign description",
|
||||
|
|
@ -46,7 +51,7 @@ class ExportViewsTestCase(TestCase):
|
|||
|
||||
def test_export_campaigns_csv(self) -> None:
|
||||
"""Test CSV export of campaigns."""
|
||||
response = self.client.get("/export/campaigns/csv/")
|
||||
response: _MonkeyPatchedWSGIResponse = self.client.get("/export/campaigns/csv/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "text/csv"
|
||||
assert b"Twitch ID" in response.content
|
||||
|
|
@ -55,7 +60,7 @@ class ExportViewsTestCase(TestCase):
|
|||
|
||||
def test_export_campaigns_json(self) -> None:
|
||||
"""Test JSON export of campaigns."""
|
||||
response = self.client.get("/export/campaigns/json/")
|
||||
response: _MonkeyPatchedWSGIResponse = self.client.get("/export/campaigns/json/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "application/json"
|
||||
|
||||
|
|
@ -68,7 +73,7 @@ class ExportViewsTestCase(TestCase):
|
|||
|
||||
def test_export_games_csv(self) -> None:
|
||||
"""Test CSV export of games."""
|
||||
response = self.client.get("/export/games/csv/")
|
||||
response: _MonkeyPatchedWSGIResponse = self.client.get("/export/games/csv/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "text/csv"
|
||||
assert b"Twitch ID" in response.content
|
||||
|
|
@ -77,7 +82,7 @@ class ExportViewsTestCase(TestCase):
|
|||
|
||||
def test_export_games_json(self) -> None:
|
||||
"""Test JSON export of games."""
|
||||
response = self.client.get("/export/games/json/")
|
||||
response: _MonkeyPatchedWSGIResponse = self.client.get("/export/games/json/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "application/json"
|
||||
|
||||
|
|
@ -89,7 +94,7 @@ class ExportViewsTestCase(TestCase):
|
|||
|
||||
def test_export_organizations_csv(self) -> None:
|
||||
"""Test CSV export of organizations."""
|
||||
response = self.client.get("/export/organizations/csv/")
|
||||
response: _MonkeyPatchedWSGIResponse = self.client.get("/export/organizations/csv/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "text/csv"
|
||||
assert b"Twitch ID" in response.content
|
||||
|
|
@ -98,7 +103,7 @@ class ExportViewsTestCase(TestCase):
|
|||
|
||||
def test_export_organizations_json(self) -> None:
|
||||
"""Test JSON export of organizations."""
|
||||
response = self.client.get("/export/organizations/json/")
|
||||
response: _MonkeyPatchedWSGIResponse = self.client.get("/export/organizations/json/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "application/json"
|
||||
|
||||
|
|
@ -110,13 +115,13 @@ class ExportViewsTestCase(TestCase):
|
|||
|
||||
def test_export_campaigns_csv_with_filters(self) -> None:
|
||||
"""Test CSV export of campaigns with status filter."""
|
||||
response = self.client.get("/export/campaigns/csv/?status=active")
|
||||
response: _MonkeyPatchedWSGIResponse = self.client.get("/export/campaigns/csv/?status=active")
|
||||
assert response.status_code == 200
|
||||
assert b"campaign123" in response.content
|
||||
|
||||
def test_export_campaigns_json_with_filters(self) -> None:
|
||||
"""Test JSON export of campaigns with status filter."""
|
||||
response = self.client.get("/export/campaigns/json/?status=active")
|
||||
response: _MonkeyPatchedWSGIResponse = self.client.get("/export/campaigns/json/?status=active")
|
||||
assert response.status_code == 200
|
||||
|
||||
data = json.loads(response.content)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue