From 467f3e65e886108c52edb21e62eb534b1e85a1f4 Mon Sep 17 00:00:00 2001 From: Arnaud-D <35631001+Arnaud-D@users.noreply.github.com> Date: Sun, 28 Apr 2024 20:05:51 +0200 Subject: [PATCH] Ajoute les tests de route basiques pour les tutoriels --- zds/tutorialv2/tests/tests_routes.py | 83 +++++++++++----------------- 1 file changed, 33 insertions(+), 50 deletions(-) diff --git a/zds/tutorialv2/tests/tests_routes.py b/zds/tutorialv2/tests/tests_routes.py index 5a6bd914a0..1418a764ce 100644 --- a/zds/tutorialv2/tests/tests_routes.py +++ b/zds/tutorialv2/tests/tests_routes.py @@ -7,11 +7,17 @@ from zds.tutorialv2.tests.factories import PublishableContentFactory, ContainerFactory -@override_for_contents() -class BasicRouteTests(TestCase, TutorialTestMixin): +def mock_publication_process(content: PublishableContent): + published = publish_content(content, content.load_version()) + content.sha_public = content.sha_draft + content.public_version = published + content.save() + + +class BasicRouteTestsMixin(TutorialTestMixin): def setUp(self): self.build_content(self.content_type) - self.mock_publication_process(self.content) + mock_publication_process(self.content) def build_content(self, type): self.content = PublishableContentFactory() @@ -21,75 +27,52 @@ def build_content(self, type): self.container = ContainerFactory(parent=content_versioned, db_object=self.content) self.subcontainer = ContainerFactory(parent=self.container, db_object=self.content) - def assert_can_be_reached(self, route, route_args): - url = reverse(route, kwargs=route_args) - response = self.client.get(url) - self.assertEqual(response.status_code, 200) - - def mock_publication_process(self, content: PublishableContent): - published = publish_content(content, content.load_version()) - content.sha_public = content.sha_draft - content.public_version = published - content.save() - - -class OpinionDisplayRoutesTests(BasicRouteTests): - content_type = "OPINION" - def test_view(self): - route = "opinion:view" route_args = { "pk": self.content.pk, "slug": self.content.slug, } - self.assert_can_be_reached(route, route_args) + self.assert_can_be_reached(self.view_name, route_args) def test_view_container_one_level_deep(self): - route = "opinion:view-container" route_args = { "pk": self.content.pk, "slug": self.content.slug, "container_slug": self.container.slug, } - self.assert_can_be_reached(route, route_args) + self.assert_can_be_reached(self.container_view_name, route_args) def test_view_container_two_level_deep(self): - route = "opinion:view-container" route_args = { "pk": self.content.pk, "slug": self.content.slug, "parent_container_slug": self.container.slug, "container_slug": self.subcontainer.slug, } - self.assert_can_be_reached(route, route_args) + self.assert_can_be_reached(self.container_view_name, route_args) + def assert_can_be_reached(self, route, route_args): + url = reverse(route, kwargs=route_args) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) -class ArticlesDisplayRoutesTests(BasicRouteTests): - content_type = "ARTICLE" - def test_view(self): - route = "article:view" - route_args = { - "pk": self.content.pk, - "slug": self.content.slug, - } - self.assert_can_be_reached(route, route_args) +@override_for_contents() +class OpinionDisplayRoutesTests(BasicRouteTestsMixin, TestCase): + content_type = "OPINION" + view_name = "opinion:view" + container_view_name = "opinion:view-container" - def test_view_container_one_level_deep(self): - route = "article:view-container" - route_args = { - "pk": self.content.pk, - "slug": self.content.slug, - "container_slug": self.container.slug, - } - self.assert_can_be_reached(route, route_args) - def test_view_container_two_level_deep(self): - route = "article:view-container" - route_args = { - "pk": self.content.pk, - "slug": self.content.slug, - "parent_container_slug": self.container.slug, - "container_slug": self.subcontainer.slug, - } - self.assert_can_be_reached(route, route_args) +@override_for_contents() +class ArticlesDisplayRoutesTests(BasicRouteTestsMixin, TestCase): + content_type = "ARTICLE" + view_name = "article:view" + container_view_name = "article:view-container" + + +@override_for_contents() +class TutorialsDisplayRoutesTests(BasicRouteTestsMixin, TestCase): + content_type = "TUTORIAL" + view_name = "tutorial:view" + container_view_name = "tutorial:view-container"