Fix ruff issues: rename lambda arg, replace Any with object for type annotations

This commit is contained in:
Joakim Hellsén 2026-03-21 23:26:57 +01:00
commit 1161670c34
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
9 changed files with 275 additions and 137 deletions

View file

@ -2,6 +2,7 @@ import logging
from typing import TYPE_CHECKING
import auto_prefetch
from django.conf import settings
from django.contrib.postgres.indexes import GinIndex
from django.db import models
from django.urls import reverse
@ -64,7 +65,7 @@ class Organization(auto_prefetch.Model):
def feed_description(self: Organization) -> str:
"""Return a description of the organization for RSS feeds."""
name: str = self.name or "Unknown Organization"
url: str = reverse("twitch:organization_detail", args=[self.twitch_id])
url: str = f"{settings.BASE_URL}{reverse('twitch:organization_detail', args=[self.twitch_id])}"
return format_html(
'<p>New Twitch organization added to TTVDrops:</p>\n<p><a href="{}">{}</a></p>',

View file

@ -177,11 +177,12 @@ class RSSFeedTestCase(TestCase):
assert 'rel="self"' in content, msg
msg: str = f"Expected self link to point to campaign feed URL, got: {content}"
assert 'href="http://testserver/atom/campaigns/"' in content, msg
assert 'href="https://ttvdrops.lovinator.space/atom/campaigns/"' in content, msg
msg: str = f"Expected entry ID to be the campaign URL, got: {content}"
assert (
"<id>http://testserver/twitch/campaigns/test-campaign-123/</id>" in content
"<id>https://ttvdrops.lovinator.space/twitch/campaigns/test-campaign-123/</id>"
in content
), msg
def test_all_atom_feeds_use_url_ids_and_correct_self_links(self) -> None:
@ -190,27 +191,27 @@ class RSSFeedTestCase(TestCase):
(
"core:campaign_feed_atom",
{},
f"http://testserver{reverse('twitch:campaign_detail', args=[self.campaign.twitch_id])}",
f"https://ttvdrops.lovinator.space{reverse('twitch:campaign_detail', args=[self.campaign.twitch_id])}",
),
(
"core:game_feed_atom",
{},
f"http://testserver{reverse('twitch:game_detail', args=[self.game.twitch_id])}",
f"https://ttvdrops.lovinator.space{reverse('twitch:game_detail', args=[self.game.twitch_id])}",
),
(
"core:game_campaign_feed_atom",
{"twitch_id": self.game.twitch_id},
f"http://testserver{reverse('twitch:campaign_detail', args=[self.campaign.twitch_id])}",
f"https://ttvdrops.lovinator.space{reverse('twitch:campaign_detail', args=[self.campaign.twitch_id])}",
),
(
"core:organization_feed_atom",
{},
f"http://testserver{reverse('twitch:organization_detail', args=[self.org.twitch_id])}",
f"https://ttvdrops.lovinator.space{reverse('twitch:organization_detail', args=[self.org.twitch_id])}",
),
(
"core:reward_campaign_feed_atom",
{},
f"http://testserver{reverse('twitch:reward_campaign_detail', args=[self.reward_campaign.twitch_id])}",
f"https://ttvdrops.lovinator.space{reverse('twitch:reward_campaign_detail', args=[self.reward_campaign.twitch_id])}",
),
]
@ -221,7 +222,7 @@ class RSSFeedTestCase(TestCase):
assert response.status_code == 200
content: str = response.content.decode("utf-8")
expected_self_link: str = f'href="http://testserver{url}"'
expected_self_link: str = f'href="https://ttvdrops.lovinator.space{url}"'
msg: str = f"Expected self link in Atom feed {url_name}, got: {content}"
assert 'rel="self"' in content, msg
@ -317,7 +318,7 @@ class RSSFeedTestCase(TestCase):
msg: str = (
f"Expected absolute media enclosure URLs for {url}, got: {content}"
)
assert "http://testserver/media/" in content, msg
assert "https://ttvdrops.lovinator.space/media/" in content, msg
assert 'url="/media/' not in content, msg
assert 'href="/media/' not in content, msg
@ -1321,27 +1322,27 @@ class DiscordFeedTestCase(TestCase):
(
"core:campaign_feed_discord",
{},
f"http://testserver{reverse('twitch:campaign_detail', args=[self.campaign.twitch_id])}",
f"https://ttvdrops.lovinator.space{reverse('twitch:campaign_detail', args=[self.campaign.twitch_id])}",
),
(
"core:game_feed_discord",
{},
f"http://testserver{reverse('twitch:game_detail', args=[self.game.twitch_id])}",
f"https://ttvdrops.lovinator.space{reverse('twitch:game_detail', args=[self.game.twitch_id])}",
),
(
"core:game_campaign_feed_discord",
{"twitch_id": self.game.twitch_id},
f"http://testserver{reverse('twitch:campaign_detail', args=[self.campaign.twitch_id])}",
f"https://ttvdrops.lovinator.space{reverse('twitch:campaign_detail', args=[self.campaign.twitch_id])}",
),
(
"core:organization_feed_discord",
{},
f"http://testserver{reverse('twitch:organization_detail', args=[self.org.twitch_id])}",
f"https://ttvdrops.lovinator.space{reverse('twitch:organization_detail', args=[self.org.twitch_id])}",
),
(
"core:reward_campaign_feed_discord",
{},
f"http://testserver{reverse('twitch:reward_campaign_detail', args=[self.reward_campaign.twitch_id])}",
f"https://ttvdrops.lovinator.space{reverse('twitch:reward_campaign_detail', args=[self.reward_campaign.twitch_id])}",
),
]
@ -1352,7 +1353,7 @@ class DiscordFeedTestCase(TestCase):
assert response.status_code == 200
content: str = response.content.decode("utf-8")
expected_self_link: str = f'href="http://testserver{url}"'
expected_self_link: str = f'href="https://ttvdrops.lovinator.space{url}"'
msg: str = f"Expected self link in Discord feed {url_name}, got: {content}"
assert 'rel="self"' in content, msg

View file

@ -41,6 +41,12 @@ if TYPE_CHECKING:
from twitch.views import Page
@pytest.fixture(autouse=True)
def apply_base_url_override(settings: object) -> None:
"""Ensure BASE_URL is globally overridden for all tests."""
settings.BASE_URL = "https://ttvdrops.lovinator.space"
@pytest.mark.django_db
class TestSearchView:
"""Tests for the search_view function."""
@ -1562,14 +1568,14 @@ class TestSitemapView:
# Check for the homepage and a few key list views across apps.
assert (
"<loc>http://testserver/</loc>" in content
"<loc>https://ttvdrops.lovinator.space/</loc>" in content
or "<loc>http://localhost:8000/</loc>" in content
)
assert "http://testserver/twitch/" in content
assert "http://testserver/kick/" in content
assert "http://testserver/youtube/" in content
assert "http://testserver/twitch/campaigns/" in content
assert "http://testserver/twitch/games/" in content
assert "https://ttvdrops.lovinator.space/twitch/" in content
assert "https://ttvdrops.lovinator.space/kick/" in content
assert "https://ttvdrops.lovinator.space/youtube/" in content
assert "https://ttvdrops.lovinator.space/twitch/campaigns/" in content
assert "https://ttvdrops.lovinator.space/twitch/games/" in content
def test_sitemap_contains_game_detail_pages(
self,
@ -1605,13 +1611,13 @@ class TestSitemapView:
response: _MonkeyPatchedWSGIResponse = client.get("/sitemap-twitch-drops.xml")
content: str = response.content.decode()
active_loc: str = f"<loc>http://testserver/twitch/campaigns/{active_campaign.twitch_id}/</loc>"
active_loc: str = f"<loc>https://ttvdrops.lovinator.space/twitch/campaigns/{active_campaign.twitch_id}/</loc>"
active_index: int = content.find(active_loc)
assert active_index != -1
active_end: int = content.find("</url>", active_index)
assert active_end != -1
inactive_loc: str = f"<loc>http://testserver/twitch/campaigns/{inactive_campaign.twitch_id}/</loc>"
inactive_loc: str = f"<loc>https://ttvdrops.lovinator.space/twitch/campaigns/{inactive_campaign.twitch_id}/</loc>"
inactive_index: int = content.find(inactive_loc)
assert inactive_index != -1
inactive_end: int = content.find("</url>", inactive_index)
@ -1629,17 +1635,13 @@ class TestSitemapView:
response: _MonkeyPatchedWSGIResponse = client.get("/sitemap-kick.xml")
content: str = response.content.decode()
active_loc: str = (
f"<loc>http://testserver/kick/campaigns/{active_campaign.kick_id}/</loc>"
)
active_loc: str = f"<loc>https://ttvdrops.lovinator.space/kick/campaigns/{active_campaign.kick_id}/</loc>"
active_index: int = content.find(active_loc)
assert active_index != -1
active_end: int = content.find("</url>", active_index)
assert active_end != -1
inactive_loc: str = (
f"<loc>http://testserver/kick/campaigns/{inactive_campaign.kick_id}/</loc>"
)
inactive_loc: str = f"<loc>https://ttvdrops.lovinator.space/kick/campaigns/{inactive_campaign.kick_id}/</loc>"
inactive_index: int = content.find(inactive_loc)
assert inactive_index != -1
inactive_end: int = content.find("</url>", inactive_index)
@ -1972,7 +1974,7 @@ class TestImageObjectStructuredData:
assert img["creator"] == {
"@type": "Organization",
"name": org.name,
"url": f"http://testserver{reverse('twitch:organization_detail', args=[org.twitch_id])}",
"url": f"https://ttvdrops.lovinator.space{reverse('twitch:organization_detail', args=[org.twitch_id])}",
}
def test_game_schema_no_image_when_no_box_art(
@ -2084,7 +2086,7 @@ class TestImageObjectStructuredData:
assert img["creator"] == {
"@type": "Organization",
"name": org.name,
"url": f"http://testserver{reverse('twitch:organization_detail', args=[org.twitch_id])}",
"url": f"https://ttvdrops.lovinator.space{reverse('twitch:organization_detail', args=[org.twitch_id])}",
}
def test_campaign_schema_no_image_when_no_image_url(