Enhance campaign detail template
This commit is contained in:
parent
e709009b99
commit
ef6c2b84ab
3 changed files with 201 additions and 46 deletions
|
|
@ -2,6 +2,7 @@ from datetime import timedelta
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.client import _MonkeyPatchedWSGIResponse
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
|
|
@ -60,3 +61,46 @@ class ChzzkDashboardViewTests(TestCase):
|
|||
|
||||
assert included in campaigns
|
||||
assert all(c.state != "TESTING" for c in campaigns)
|
||||
|
||||
def test_campaign_detail_view_renders_chzzk_campaign_and_rewards(self) -> None:
|
||||
"""Test that the campaign detail view correctly renders the details of a chzzk campaign and its rewards."""
|
||||
now: datetime = timezone.now()
|
||||
|
||||
campaign: ChzzkCampaign = ChzzkCampaign.objects.create(
|
||||
campaign_no=2001,
|
||||
title="Campaign Detail Test",
|
||||
description="Detailed campaign description",
|
||||
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",
|
||||
)
|
||||
|
||||
campaign.rewards.create( # pyright: ignore[reportAttributeAccessIssue]
|
||||
reward_no=10,
|
||||
title="Reward A",
|
||||
reward_type="ITEM",
|
||||
campaign_reward_type="Standard",
|
||||
condition_type="watch",
|
||||
condition_for_minutes=15,
|
||||
ios_based_reward=False,
|
||||
code_remaining_count=100,
|
||||
)
|
||||
|
||||
response: _MonkeyPatchedWSGIResponse = self.client.get(
|
||||
reverse("chzzk:campaign_detail", args=[campaign.campaign_no]),
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
content: str = response.content.decode()
|
||||
assert campaign.title in content
|
||||
assert "Reward A" in content
|
||||
assert "watch" in content
|
||||
assert "100" in content
|
||||
assert "No" in content # ios_based_reward=False
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.db.models.query import QuerySet
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
|
@ -62,7 +63,8 @@ def campaign_detail_view(request: HttpRequest, campaign_no: int) -> HttpResponse
|
|||
Returns:
|
||||
HttpResponse: The HTTP response containing the rendered campaign detail page.
|
||||
"""
|
||||
campaign: models.ChzzkCampaign = models.ChzzkCampaign.objects.get(
|
||||
campaign: models.ChzzkCampaign = get_object_or_404(
|
||||
models.ChzzkCampaign,
|
||||
campaign_no=campaign_no,
|
||||
)
|
||||
rewards: QuerySet[models.ChzzkReward, models.ChzzkReward] = campaign.rewards.all() # pyright: ignore[reportAttributeAccessIssue]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue