From c9522f9d3dc1da6236af74261db630bae4a5b988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Wed, 1 Apr 2026 14:20:24 +0200 Subject: [PATCH] Fix typo in dashboard_view to exclude campaigns with state "TESTING" --- chzzk/tests/test_views.py | 62 +++++++++++++++++++++++++++++++++++++++ chzzk/views.py | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 chzzk/tests/test_views.py diff --git a/chzzk/tests/test_views.py b/chzzk/tests/test_views.py new file mode 100644 index 0000000..4e036f9 --- /dev/null +++ b/chzzk/tests/test_views.py @@ -0,0 +1,62 @@ +from datetime import timedelta +from typing import TYPE_CHECKING + +from django.test import TestCase +from django.urls import reverse +from django.utils import timezone + +from chzzk.models import ChzzkCampaign + +if TYPE_CHECKING: + from datetime import datetime + + from django.test.client import _MonkeyPatchedWSGIResponse + + +class ChzzkDashboardViewTests(TestCase): + """Test cases for the dashboard view of the chzzk app.""" + + def test_dashboard_view_excludes_testing_state_campaigns(self) -> None: + """Test that the dashboard view excludes campaigns in the TESTING state.""" + now: datetime = timezone.now() + + ChzzkCampaign.objects.create( + campaign_no=1001, + title="Testing campaign", + description="Should be excluded", + category_type="game", + category_id="1", + category_value="TestGame", + service_id="chzzk", + state="TESTING", + start_date=now - timedelta(days=1), + end_date=now + timedelta(days=1), + has_ios_based_reward=False, + drops_campaign_not_started=False, + source_api="unit-test", + ) + + included: ChzzkCampaign = ChzzkCampaign.objects.create( + campaign_no=1002, + title="Active campaign", + description="Should be included", + category_type="game", + category_id="1", + category_value="TestGame", + service_id="chzzk", + state="ACTIVE", + start_date=now - timedelta(days=1), + end_date=now + timedelta(days=1), + has_ios_based_reward=False, + drops_campaign_not_started=False, + source_api="unit-test", + ) + + response: _MonkeyPatchedWSGIResponse = self.client.get( + reverse("chzzk:dashboard"), + ) + assert response.status_code == 200 + campaigns: list[ChzzkCampaign] = list(response.context["active_campaigns"]) + + assert included in campaigns + assert all(c.state != "TESTING" for c in campaigns) diff --git a/chzzk/views.py b/chzzk/views.py index 48dc8c1..7687c43 100644 --- a/chzzk/views.py +++ b/chzzk/views.py @@ -31,7 +31,7 @@ def dashboard_view(request: HttpRequest) -> HttpResponse: active_campaigns: QuerySet[models.ChzzkCampaign, models.ChzzkCampaign] = ( models.ChzzkCampaign.objects .filter(end_date__gte=timezone.now()) - .exclude(status="TESTING") + .exclude(state="TESTING") .order_by("-start_date") ) return render(