Refactor HTML
This commit is contained in:
parent
a12b34a665
commit
05eb0d92e3
27 changed files with 776 additions and 393 deletions
|
|
@ -126,27 +126,20 @@ class TestBackupCommand:
|
|||
assert output_dir.exists()
|
||||
assert len(list(output_dir.glob("test-*.sql.zst"))) == 1
|
||||
|
||||
def test_backup_uses_default_directory(self) -> None:
|
||||
def test_backup_uses_default_directory(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Test that backup uses DATA_DIR/datasets by default."""
|
||||
# Create test data so tables exist
|
||||
Organization.objects.create(twitch_id="test004", name="Test Org")
|
||||
|
||||
datasets_dir = settings.DATA_DIR / "datasets"
|
||||
monkeypatch.setattr(settings, "DATA_DIR", tmp_path)
|
||||
datasets_dir = tmp_path / "datasets"
|
||||
datasets_dir.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
# Clean up any existing test backups
|
||||
for old_backup in datasets_dir.glob("ttvdrops-*.sql.zst"):
|
||||
old_backup.unlink()
|
||||
|
||||
call_command("backup_db")
|
||||
|
||||
backup_files = list(datasets_dir.glob("ttvdrops-*.sql.zst"))
|
||||
assert len(backup_files) >= 1
|
||||
|
||||
# Clean up
|
||||
for backup in backup_files:
|
||||
backup.unlink()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestBackupHelperFunctions:
|
||||
|
|
|
|||
|
|
@ -118,7 +118,6 @@ class TestBadgeSetDetailView:
|
|||
content = response.content.decode()
|
||||
|
||||
assert "vip" in content
|
||||
assert "Total Versions:" in content
|
||||
assert "1" in content
|
||||
|
||||
def test_badge_set_detail_json_data(self, client: Client) -> None:
|
||||
|
|
|
|||
125
twitch/tests/test_exports.py
Normal file
125
twitch/tests/test_exports.py
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from datetime import timedelta
|
||||
|
||||
from django.test import Client
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
|
||||
from twitch.models import DropCampaign
|
||||
from twitch.models import Game
|
||||
from twitch.models import Organization
|
||||
|
||||
|
||||
class ExportViewsTestCase(TestCase):
|
||||
"""Test export views for CSV and JSON formats."""
|
||||
|
||||
def setUp(self) -> None:
|
||||
"""Set up test data."""
|
||||
self.client = Client()
|
||||
|
||||
# Create test organization
|
||||
self.org = Organization.objects.create(
|
||||
twitch_id="org123",
|
||||
name="Test Organization",
|
||||
)
|
||||
|
||||
# Create test game
|
||||
self.game = Game.objects.create(
|
||||
twitch_id="game123",
|
||||
name="Test Game",
|
||||
display_name="Test Game Display",
|
||||
)
|
||||
self.game.owners.add(self.org)
|
||||
|
||||
# Create test campaign
|
||||
now = timezone.now()
|
||||
self.campaign = DropCampaign.objects.create(
|
||||
twitch_id="campaign123",
|
||||
name="Test Campaign",
|
||||
description="A test campaign description",
|
||||
game=self.game,
|
||||
start_at=now - timedelta(days=1),
|
||||
end_at=now + timedelta(days=1),
|
||||
)
|
||||
|
||||
def test_export_campaigns_csv(self) -> None:
|
||||
"""Test CSV export of campaigns."""
|
||||
response = self.client.get("/export/campaigns/csv/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "text/csv"
|
||||
assert b"Twitch ID" in response.content
|
||||
assert b"campaign123" in response.content
|
||||
assert b"Test Campaign" in response.content
|
||||
|
||||
def test_export_campaigns_json(self) -> None:
|
||||
"""Test JSON export of campaigns."""
|
||||
response = self.client.get("/export/campaigns/json/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "application/json"
|
||||
|
||||
data = json.loads(response.content)
|
||||
assert isinstance(data, list)
|
||||
assert len(data) == 1
|
||||
assert data[0]["twitch_id"] == "campaign123"
|
||||
assert data[0]["name"] == "Test Campaign"
|
||||
assert data[0]["status"] == "Active"
|
||||
|
||||
def test_export_games_csv(self) -> None:
|
||||
"""Test CSV export of games."""
|
||||
response = self.client.get("/export/games/csv/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "text/csv"
|
||||
assert b"Twitch ID" in response.content
|
||||
assert b"game123" in response.content
|
||||
assert b"Test Game Display" in response.content
|
||||
|
||||
def test_export_games_json(self) -> None:
|
||||
"""Test JSON export of games."""
|
||||
response = self.client.get("/export/games/json/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "application/json"
|
||||
|
||||
data = json.loads(response.content)
|
||||
assert isinstance(data, list)
|
||||
assert len(data) == 1
|
||||
assert data[0]["twitch_id"] == "game123"
|
||||
assert data[0]["display_name"] == "Test Game Display"
|
||||
|
||||
def test_export_organizations_csv(self) -> None:
|
||||
"""Test CSV export of organizations."""
|
||||
response = self.client.get("/export/organizations/csv/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "text/csv"
|
||||
assert b"Twitch ID" in response.content
|
||||
assert b"org123" in response.content
|
||||
assert b"Test Organization" in response.content
|
||||
|
||||
def test_export_organizations_json(self) -> None:
|
||||
"""Test JSON export of organizations."""
|
||||
response = self.client.get("/export/organizations/json/")
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == "application/json"
|
||||
|
||||
data = json.loads(response.content)
|
||||
assert isinstance(data, list)
|
||||
assert len(data) == 1
|
||||
assert data[0]["twitch_id"] == "org123"
|
||||
assert data[0]["name"] == "Test Organization"
|
||||
|
||||
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")
|
||||
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")
|
||||
assert response.status_code == 200
|
||||
|
||||
data = json.loads(response.content)
|
||||
assert isinstance(data, list)
|
||||
assert len(data) == 1
|
||||
assert data[0]["status"] == "Active"
|
||||
|
|
@ -442,8 +442,8 @@ URL_NAMES: list[tuple[str, dict[str, str]]] = [
|
|||
("twitch:debug", {}),
|
||||
("twitch:docs_rss", {}),
|
||||
("twitch:emote_gallery", {}),
|
||||
("twitch:game_list", {}),
|
||||
("twitch:game_list_simple", {}),
|
||||
("twitch:games_grid", {}),
|
||||
("twitch:games_list", {}),
|
||||
("twitch:game_detail", {"twitch_id": "test-game-123"}),
|
||||
("twitch:org_list", {}),
|
||||
("twitch:organization_detail", {"twitch_id": "test-org-123"}),
|
||||
|
|
|
|||
|
|
@ -522,14 +522,14 @@ class TestChannelListView:
|
|||
@pytest.mark.django_db
|
||||
def test_games_grid_view(self, client: Client) -> None:
|
||||
"""Test games grid view returns 200 and has games in context."""
|
||||
response: _MonkeyPatchedWSGIResponse = client.get(reverse("twitch:game_list"))
|
||||
response: _MonkeyPatchedWSGIResponse = client.get(reverse("twitch:games_grid"))
|
||||
assert response.status_code == 200
|
||||
assert "games" in response.context
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_games_list_view(self, client: Client) -> None:
|
||||
"""Test games list view returns 200 and has games in context."""
|
||||
response: _MonkeyPatchedWSGIResponse = client.get(reverse("twitch:game_list_simple"))
|
||||
response: _MonkeyPatchedWSGIResponse = client.get(reverse("twitch:games_list"))
|
||||
assert response.status_code == 200
|
||||
assert "games" in response.context
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue