-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic redirect for legacy print URLs (refs #442)
- Loading branch information
Showing
3 changed files
with
79 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,62 @@ | ||
from unittest import TestCase | ||
|
||
from django.template import Context, Template | ||
from django.test import Client | ||
from django.test import Client, TestCase | ||
|
||
from ddcz.models import ApprovalChoices, CommonArticle, RangerSpell, Skill, Quest | ||
|
||
from ddcz.models import Quest | ||
|
||
class RedirectTestCase(TestCase): | ||
fixtures = ["pages"] | ||
|
||
class TestDobrodruztviRedirect(TestCase): | ||
def setUp(self): | ||
self.quest = Quest.objects.create( | ||
super().setUp() | ||
self.create_creation() | ||
self.client = Client() | ||
|
||
def assert_redirect(self, from_url, to_url_prefix): | ||
response = self.client.get(from_url) | ||
self.assertEquals(response.status_code, 301) | ||
self.assertEquals( | ||
response.url, | ||
f"{to_url_prefix}/{self.creation.id}-{self.creation.get_slug()}/", | ||
) | ||
|
||
|
||
class TestQuestRedirect(RedirectTestCase): | ||
def create_creation(self): | ||
self.creation = Quest.objects.create( | ||
id=21, | ||
name="Test quest", | ||
abstract="yolo", | ||
keywords="test, quest", | ||
) | ||
self.client = Client() | ||
|
||
def test_dobrodruzstvi_without_suffix(self): | ||
response = self.client.get(f"/dobrodruzstvi/{self.quest.id}/") | ||
self.assertEquals(response.status_code, 301) | ||
self.assertEquals( | ||
response.url, f"/dobrodruzstvi/{self.quest.id}-{self.quest.get_slug()}/" | ||
def test_redirect(self): | ||
self.assert_redirect(f"/dobrodruzstvi/{self.creation.id}/", "/dobrodruzstvi") | ||
|
||
|
||
class TestSkillPrintRedirect(RedirectTestCase): | ||
def create_creation(self): | ||
self.creation = Skill.objects.create( | ||
id=1, name="Test skill", description="yolo" | ||
) | ||
|
||
def test_redirect(self): | ||
self.assert_redirect( | ||
f"/code/dovednosti/dovednosti_tisk.php?id={self.creation.id}", | ||
"/rubriky/dovednosti", | ||
) | ||
|
||
|
||
class TestRangerSpellRedirect(RedirectTestCase): | ||
def create_creation(self): | ||
self.creation = RangerSpell.objects.create( | ||
name="Super Kouzlo", | ||
magenergy=1, | ||
is_published=ApprovalChoices.APPROVED.value, | ||
) | ||
|
||
def test_redirect(self): | ||
self.assert_redirect( | ||
f"/code/hranicarkouzla/hranicarkouzla_tisk.php?id={self.creation.id}", | ||
"/rubriky/hranicarkouzla", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters