From 0b5fda7fa2ee1c854cc9c8efb0bec122e623111d Mon Sep 17 00:00:00 2001 From: Arnaud-D <35631001+Arnaud-D@users.noreply.github.com> Date: Tue, 17 Sep 2024 08:33:35 +0200 Subject: [PATCH] Corrige 'test_basic_tutorial_workflow()' --- .../tests/tests_views/tests_content.py | 84 ++++--------------- 1 file changed, 16 insertions(+), 68 deletions(-) diff --git a/zds/tutorialv2/tests/tests_views/tests_content.py b/zds/tutorialv2/tests/tests_views/tests_content.py index 6dbdea6192..0f623f93ec 100644 --- a/zds/tutorialv2/tests/tests_views/tests_content.py +++ b/zds/tutorialv2/tests/tests_views/tests_content.py @@ -230,89 +230,37 @@ def test_ensure_access(self): ) self.assertEqual(result.status_code, 200) - def test_basic_tutorial_workflow(self): - """General test on the basic workflow of a tutorial: creation, edition, deletion for the author""" - self.client.force_login(self.user_author) - - # create tutorial - intro = "une intro" - conclusion = "une conclusion" - description = "une description" + def test_create_tutorial(self): + """Test the creation of a new content.""" title = "un titre" - random = "un truc à la rien à voir" - random_with_md = "un text contenant du **markdown** ." - - response = self.client.post( - reverse("content:create-content", kwargs={"created_content_type": "TUTORIAL"}), - { - "text": random_with_md, - "preview": "", - }, - HTTP_X_REQUESTED_WITH="XMLHttpRequest", - ) - - self.assertEqual(200, response.status_code) - - result_string = "".join(str(a, "utf-8") for a in response.streaming_content) - self.assertIn("markdown", result_string, "We need the text to be properly formatted") - result = self.client.post( reverse("content:create-content", kwargs={"created_content_type": "TUTORIAL"}), - { - "title": title, - "introduction": intro, - "conclusion": conclusion, - "type": "TUTORIAL", - "licence": self.licence.pk, - }, + {"title": title}, follow=False, ) self.assertEqual(result.status_code, 302) self.assertEqual(PublishableContent.objects.all().count(), 2) tuto = PublishableContent.objects.last() - pk = tuto.pk - slug = tuto.slug - versioned = tuto.load_version() self.assertEqual(Gallery.objects.filter(pk=tuto.gallery.pk).count(), 1) self.assertEqual(UserGallery.objects.filter(gallery__pk=tuto.gallery.pk).count(), tuto.authors.count()) - # access to tutorial - result = self.client.get(reverse("content:edit", args=[pk, slug]), follow=False) - self.assertEqual(result.status_code, 200) - - # preview tutorial - result = self.client.post( - reverse("content:edit", args=[pk, slug]), - {"text": random_with_md, "last_hash": versioned.compute_hash(), "preview": ""}, - HTTP_X_REQUESTED_WITH="XMLHttpRequest", - ) - - self.assertEqual(result.status_code, 200) - - result_string = "".join(a.decode() for a in result.streaming_content) - self.assertIn("markdown", result_string, "We need the text to be properly formatted") + def test_basic_tutorial_workflow(self): + """General test on the basic workflow of a tutorial: edition, deletion for the author""" + self.client.force_login(self.user_author) - result = self.client.post( - reverse("content:edit", args=[pk, slug]), - { - "introduction": random, - "conclusion": random, - "type": "TUTORIAL", - "subcategory": self.subcategory.pk, - "last_hash": versioned.compute_hash(), - }, - follow=False, - ) - self.assertEqual(result.status_code, 302) + # create tutorial + intro = "une intro" + conclusion = "une conclusion" + description = "une description" + title = "un titre" + random = "un truc à la rien à voir" + random_with_md = "un text contenant du **markdown** ." - tuto = PublishableContent.objects.get(pk=pk) - self.assertEqual(tuto.licence, None) - versioned = tuto.load_version() - self.assertEqual(versioned.get_introduction(), random) - self.assertEqual(versioned.get_conclusion(), random) - self.assertEqual(versioned.licence, None) + tuto = PublishableContent.objects.last() + pk = tuto.pk + slug = tuto.slug # preview container result = self.client.post(