Skip to content

Commit

Permalink
Merge branch 'dev' into django_loginview
Browse files Browse the repository at this point in the history
  • Loading branch information
philippemilink authored Jul 19, 2022
2 parents 5117df9 + d585f02 commit 4f2a440
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
23 changes: 23 additions & 0 deletions zds/tutorialv2/tests/tests_views/tests_redirect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.test import TestCase
from django.urls import reverse

from zds.member.tests.factories import ProfileFactory


class RedirectOldContentOfAuthorTest(TestCase):
def test_redirect(self):
user = ProfileFactory().user

response = self.client.get(reverse("content:legacy-find-tutorial", args=[user.pk]))
self.assertRedirects(response, reverse("tutorial:find-tutorial", args=[user]), status_code=301)

response = self.client.get(reverse("content:legacy-find-article", args=[user.pk]))
self.assertRedirects(response, reverse("article:find-article", args=[user]), status_code=301)

response = self.client.get(reverse("content:legacy-find-opinion", args=[user.pk]))
self.assertRedirects(response, reverse("opinion:find-opinion", args=[user]), status_code=301)

# The user with pk=3954 doesn't exist (the view in the redirection
# triggers the 404, so we need to follow the response):
response = self.client.get(reverse("content:legacy-find-tutorial", args=[3954]), follow=True)
self.assertEqual(response.status_code, 404)
6 changes: 3 additions & 3 deletions zds/tutorialv2/urls/urls_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
name="find-contribution-all",
),
path("commentaires/<int:pk>/", ListContentReactions.as_view(), name="list-content-reactions"),
path("tutoriels/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="TUTORIAL")),
path("articles/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="ARTICLE")),
path("tribunes/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="OPINION")),
path("tutoriels/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="TUTORIAL"), name="legacy-find-tutorial"),
path("articles/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="ARTICLE"), name="legacy-find-article"),
path("tribunes/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="OPINION"), name="legacy-find-opinion"),
path("aides/", ContentsWithHelps.as_view(), name="helps"),
path("aides/<int:pk>/change/", ChangeHelp.as_view(), name="helps-change"),
path(
Expand Down
3 changes: 3 additions & 0 deletions zds/tutorialv2/views/redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def get_redirect_url(self, **kwargs):
user = User.objects.filter(pk=int(kwargs["pk"])).first()
route = None

if not user:
raise Http404("Cet utilisateur est inconnu dans le système")

if self.type == "TUTORIAL":
route = "tutorial:find-tutorial"
elif self.type == "ARTICLE":
Expand Down

0 comments on commit 4f2a440

Please sign in to comment.