Compare commits

..

No commits in common. "60ac907163a23db669c94501e48f38d1e53c8d3a" and "e044506e4c1192f1bcb6c5b3e371fa5268a7947a" have entirely different histories.

3 changed files with 33 additions and 147 deletions

View file

@ -1,6 +1,6 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block title %} {% block title %}
{{ page_title }} YouTube channels with rewards
{% endblock title %} {% endblock title %}
{% block content %} {% block content %}
<main> <main>
@ -14,17 +14,17 @@
<thead> <thead>
<tr> <tr>
<th>Channel</th> <th>Channel</th>
<th>Organization</th> <th>Partner</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for group in organization_groups %} {% for group in partner_groups %}
{% for item in group.channels %} {% for item in group.channels %}
<tr> <tr>
<td> <td>
<a href="{{ item.url }}" rel="noopener" target="_blank">{{ item.channel }}</a> <a href="{{ item.url }}" rel="noopener" target="_blank">{{ item.channel }}</a>
</td> </td>
<td>{{ group.organization }}</td> <td>{{ group.partner }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}

View file

@ -1,6 +1,4 @@
import json
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import Any
from django.test import TestCase from django.test import TestCase
from django.urls import reverse from django.urls import reverse
@ -12,91 +10,13 @@ if TYPE_CHECKING:
class YouTubeIndexViewTest(TestCase): class YouTubeIndexViewTest(TestCase):
"""Tests for the YouTube drops channels index page.""" """Tests for the YouTube drops channels index page."""
def test_index_includes_page_specific_seo_metadata(self) -> None:
"""The YouTube page should render dedicated title and description metadata."""
response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index"))
content: str = response.content.decode()
assert response.context is not None
assert response.context["page_title"] == "YouTube channels with rewards"
assert (
response.context["page_description"]
== "Browse YouTube channels listed as reward-enabled, including Call of Duty, Blizzard, "
"Fortnite, Riot Games, and more."
)
assert (
'<meta property="og:title" content="YouTube channels with rewards" />'
in content
)
assert (
'<meta property="og:description"\n'
' content="Browse YouTube channels listed as reward-enabled, including Call of Duty, '
'Blizzard, Fortnite, Riot Games, and more." />'
) in content
assert (
'<meta name="twitter:title" content="YouTube channels with rewards" />'
in content
)
assert (
'<meta name="description"\n'
' content="Browse YouTube channels listed as reward-enabled, including Call of Duty, '
'Blizzard, Fortnite, Riot Games, and more." />'
) in content
def test_index_schema_data_is_valid_itemlist(self) -> None:
"""The page should include a valid Schema.org ItemList in the JSON-LD context."""
response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index"))
assert response.context is not None
assert "schema_data" in response.context
schema: dict[str, Any] = json.loads(response.context["schema_data"])
assert schema["@context"] == "https://schema.org"
assert schema["@type"] == "ItemList"
assert schema["name"] == "YouTube channels with rewards"
assert "itemListElement" in schema
items: list[dict[str, Any]] = schema["itemListElement"]
assert len(items) > 0
# Every entry must be a ListItem wrapping an Organization
for item in items:
assert item["@type"] == "ListItem"
assert "position" in item
org: dict[str, Any] = item["item"]
assert org["@type"] == "Organization"
assert "name" in org
assert isinstance(org["sameAs"], list)
assert len(org["sameAs"]) > 0
def test_index_schema_data_includes_known_orgs(self) -> None:
"""The Schema.org ItemList should contain entries for known organizations."""
response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index"))
schema: dict[str, Any] = json.loads(response.context["schema_data"]) # type: ignore[index]
org_names: list[str] = [
item["item"]["name"] for item in schema["itemListElement"]
]
assert "Activision (Call of Duty)" in org_names
assert "Battle.net / Blizzard" in org_names
assert "Riot Games" in org_names
assert "Epic Games" in org_names
def test_index_schema_data_org_same_as_are_youtube_urls(self) -> None:
"""Each Organization's sameAs values should be YouTube URLs."""
response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index"))
schema: dict[str, Any] = json.loads(response.context["schema_data"]) # type: ignore[index]
for list_item in schema["itemListElement"]:
for url in list_item["item"]["sameAs"]:
assert url.startswith("https://www.youtube.com/")
def test_index_returns_200(self) -> None: def test_index_returns_200(self) -> None:
"""The YouTube index page should return HTTP 200.""" """The YouTube index page should return HTTP 200."""
response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index")) response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index"))
assert response.status_code == 200 assert response.status_code == 200
def test_index_displays_known_channels(self) -> None: def test_index_displays_known_channels(self) -> None:
"""The page should include key known channels from the organization list.""" """The page should include key known channels from the partner list."""
response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index")) response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index"))
content: str = response.content.decode() content: str = response.content.decode()
@ -108,8 +28,8 @@ class YouTubeIndexViewTest(TestCase):
assert "Riot Games" in content assert "Riot Games" in content
assert "Ubisoft" in content assert "Ubisoft" in content
def test_index_includes_organization_urls(self) -> None: def test_index_includes_partner_urls(self) -> None:
"""The page should render organization channel links from the source list.""" """The page should render partner channel links from the source list."""
response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index")) response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index"))
content: str = response.content.decode() content: str = response.content.decode()
@ -117,8 +37,8 @@ class YouTubeIndexViewTest(TestCase):
assert "https://www.youtube.com/user/epicfortnite" in content assert "https://www.youtube.com/user/epicfortnite" in content
assert "https://www.youtube.com/lolesports" in content assert "https://www.youtube.com/lolesports" in content
def test_index_groups_organizations_alphabetically(self) -> None: def test_index_groups_partners_alphabetically(self) -> None:
"""Organization sections should render grouped and in alphabetical order.""" """Partner sections should render grouped and in alphabetical order."""
response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index")) response: _MonkeyPatchedWSGIResponse = self.client.get(reverse("youtube:index"))
content: str = response.content.decode() content: str = response.content.decode()

View file

@ -1,7 +1,5 @@
import json
from collections import defaultdict from collections import defaultdict
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import Any
from django.shortcuts import render from django.shortcuts import render
@ -10,94 +8,90 @@ if TYPE_CHECKING:
from django.http import HttpResponse from django.http import HttpResponse
PAGE_TITLE = "YouTube channels with rewards"
PAGE_DESCRIPTION = "Browse YouTube channels listed as reward-enabled, including Call of Duty, Blizzard, Fortnite, Riot Games, and more."
def index(request: HttpRequest) -> HttpResponse: def index(request: HttpRequest) -> HttpResponse:
"""Render a minimal list of YouTube channels with known drops-enabled organizations. """Render a minimal list of YouTube channels with known drops-enabled partners.
Returns: Returns:
HttpResponse: Rendered index page for YouTube drops channels. HttpResponse: Rendered index page for YouTube drops channels.
""" """
channels: list[dict[str, str]] = [ channels: list[dict[str, str]] = [
{ {
"organization": "Activision (Call of Duty)", "partner": "Activision (Call of Duty)",
"channel": "Call of Duty", "channel": "Call of Duty",
"url": "https://www.youtube.com/channel/UCbLIqv9Puhyp9_ZjVtfOy7w", "url": "https://www.youtube.com/channel/UCbLIqv9Puhyp9_ZjVtfOy7w",
}, },
{ {
"organization": "Battle.net / Blizzard", "partner": "Battle.net / Blizzard",
"channel": "PlayOverwatch", "channel": "PlayOverwatch",
"url": "https://www.youtube.com/c/playoverwatch/featured", "url": "https://www.youtube.com/c/playoverwatch/featured",
}, },
{ {
"organization": "Battle.net / Blizzard", "partner": "Battle.net / Blizzard",
"channel": "Hearthstone", "channel": "Hearthstone",
"url": "https://www.youtube.com/c/Hearthstone/featured", "url": "https://www.youtube.com/c/Hearthstone/featured",
}, },
{ {
"organization": "Electronic Arts", "partner": "Electronic Arts",
"channel": "FIFA", "channel": "FIFA",
"url": "https://www.youtube.com/channel/UCFA6YGp5lvgayO20lk7_Ung", "url": "https://www.youtube.com/channel/UCFA6YGp5lvgayO20lk7_Ung",
}, },
{ {
"organization": "Electronic Arts", "partner": "Electronic Arts",
"channel": "EA Madden NFL", "channel": "EA Madden NFL",
"url": "https://www.youtube.com/@EAMaddenNFL", "url": "https://www.youtube.com/@EAMaddenNFL",
}, },
{ {
"organization": "Epic Games", "partner": "Epic Games",
"channel": "Fortnite", "channel": "Fortnite",
"url": "https://www.youtube.com/user/epicfortnite", "url": "https://www.youtube.com/user/epicfortnite",
}, },
{ {
"organization": "Garena", "partner": "Garena",
"channel": "Free Fire", "channel": "Free Fire",
"url": "https://www.youtube.com/channel/UC_vVy4OI86F0amXqFN_zTMg", "url": "https://www.youtube.com/channel/UC_vVy4OI86F0amXqFN_zTMg",
}, },
{ {
"organization": "Krafton (PUBG)", "partner": "Krafton (PUBG)",
"channel": "PUBG: BATTLEGROUNDS", "channel": "PUBG: BATTLEGROUNDS",
"url": "https://www.youtube.com/channel/UCTDO0RgowRyaAEUrPnBAg4g", "url": "https://www.youtube.com/channel/UCTDO0RgowRyaAEUrPnBAg4g",
}, },
{ {
"organization": "MLBB", "partner": "MLBB",
"channel": "Mobile Legends: Bang Bang", "channel": "Mobile Legends: Bang Bang",
"url": "https://www.youtube.com/channel/UCqmld-BIYME2i_ooRTo1EOg", "url": "https://www.youtube.com/channel/UCqmld-BIYME2i_ooRTo1EOg",
}, },
{ {
"organization": "NBA", "partner": "NBA",
"channel": "NBA", "channel": "NBA",
"url": "https://www.youtube.com/user/NBA", "url": "https://www.youtube.com/user/NBA",
}, },
{ {
"organization": "NFL", "partner": "NFL",
"channel": "NFL", "channel": "NFL",
"url": "https://www.youtube.com/@NFL", "url": "https://www.youtube.com/@NFL",
}, },
{ {
"organization": "PUBG Mobile", "partner": "PUBG Mobile",
"channel": "PUBG MOBILE", "channel": "PUBG MOBILE",
"url": "https://www.youtube.com/channel/UCTDO0RgowRyaAEUrPnBAg4g", "url": "https://www.youtube.com/channel/UCTDO0RgowRyaAEUrPnBAg4g",
}, },
{ {
"organization": "Riot Games", "partner": "Riot Games",
"channel": "Riot Games", "channel": "Riot Games",
"url": "https://www.youtube.com/user/RiotGamesInc", "url": "https://www.youtube.com/user/RiotGamesInc",
}, },
{ {
"organization": "Riot Games", "partner": "Riot Games",
"channel": "LoL Esports", "channel": "LoL Esports",
"url": "https://www.youtube.com/lolesports", "url": "https://www.youtube.com/lolesports",
}, },
{ {
"organization": "Supercell", "partner": "Supercell",
"channel": "Clash Royale", "channel": "Clash Royale",
"url": "https://www.youtube.com/channel/UC_F8DoJf9MZogEOU51TpTbQ", "url": "https://www.youtube.com/channel/UC_F8DoJf9MZogEOU51TpTbQ",
}, },
{ {
"organization": "Ubisoft", "partner": "Ubisoft",
"channel": "Ubisoft", "channel": "Ubisoft",
"url": "https://www.youtube.com/user/ubisoft", "url": "https://www.youtube.com/user/ubisoft",
}, },
@ -105,45 +99,17 @@ def index(request: HttpRequest) -> HttpResponse:
grouped_channels: dict[str, list[dict[str, str]]] = defaultdict(list) grouped_channels: dict[str, list[dict[str, str]]] = defaultdict(list)
for channel in channels: for channel in channels:
grouped_channels[channel["organization"]].append(channel) grouped_channels[channel["partner"]].append(channel)
organization_groups: list[dict[str, str | list[dict[str, str]]]] = [] partner_groups: list[dict[str, str | list[dict[str, str]]]] = []
for organization in sorted(grouped_channels.keys(), key=str.lower): for partner in sorted(grouped_channels.keys(), key=str.lower):
sorted_items: list[dict[str, str]] = sorted( sorted_items: list[dict[str, str]] = sorted(
grouped_channels[organization], grouped_channels[partner],
key=lambda item: item["channel"].lower(), key=lambda item: item["channel"].lower(),
) )
organization_groups.append({ partner_groups.append({"partner": partner, "channels": sorted_items})
"organization": organization,
"channels": sorted_items,
})
list_items: list[dict[str, Any]] = [ context: dict[str, list[dict[str, str | list[dict[str, str]]]]] = {
{ "partner_groups": partner_groups,
"@type": "ListItem",
"position": position,
"item": {
"@type": "Organization",
"name": group["organization"],
"sameAs": [ch["url"] for ch in group["channels"]], # type: ignore[index]
},
}
for position, group in enumerate(organization_groups, start=1)
]
schema: dict[str, Any] = {
"@context": "https://schema.org",
"@type": "ItemList",
"name": PAGE_TITLE,
"description": PAGE_DESCRIPTION,
"url": request.build_absolute_uri(),
"itemListElement": list_items,
}
context: dict[str, Any] = {
"page_title": PAGE_TITLE,
"page_description": PAGE_DESCRIPTION,
"organization_groups": organization_groups,
"schema_data": json.dumps(schema),
} }
return render(request=request, template_name="youtube/index.html", context=context) return render(request=request, template_name="youtube/index.html", context=context)