Skip to content

Commit

Permalink
Ajoute les tests pour le signal tags_management
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed Oct 3, 2021
1 parent 3b721e5 commit 00c2416
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion zds/tutorialv2/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# For the signal below, the arguments "performer" and "content" shall be provided.
tags_management = Signal()

# Suggestion management
# Suggestions management
# For the signals below, the arguments "performer" and "content" shall be provided.
suggestions_management = Signal()

Expand Down
22 changes: 15 additions & 7 deletions zds/tutorialv2/tests/tests_views/tests_editcontenttags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import patch

from django.test import TestCase
from django.urls import reverse
from django.utils.html import escape
Expand Down Expand Up @@ -145,9 +147,10 @@ def test_form_function(self):
test_cases = self.get_test_cases()
for case_name, case in test_cases.items():
with self.subTest(msg=case_name):
self.enforce_preconditions(case["preconditions"])
self.post_form(case["inputs"])
self.check_effects(case["expected_outputs"])
with patch("zds.tutorialv2.signals.tags_management") as tags_management:
self.enforce_preconditions(case["preconditions"])
self.post_form(case["inputs"])
self.check_effects(case["expected_outputs"], tags_management)

def get_test_cases(self):
"""List test cases for the license editing form."""
Expand All @@ -156,17 +159,21 @@ def get_test_cases(self):
"nothing": {
"preconditions": {"all_tags": self.tags_name, "content_tags": []},
"inputs": {"tags": ""},
"expected_outputs": {"all_tags": self.tags_name, "content_tags": []},
"expected_outputs": {"all_tags": self.tags_name, "content_tags": [], "call_count": 1},
},
"existing_tag": {
"preconditions": {"all_tags": self.tags_name, "content_tags": []},
"inputs": {"tags": self.tag_1.title},
"expected_outputs": {"all_tags": self.tags_name, "content_tags": [self.tag_1.title]},
"expected_outputs": {"all_tags": self.tags_name, "content_tags": [self.tag_1.title], "call_count": 1},
},
"new_tag": {
"preconditions": {"all_tags": self.tags_name, "content_tags": []},
"inputs": {"tags": new_tag_name},
"expected_outputs": {"all_tags": self.tags_name + [new_tag_name], "content_tags": [new_tag_name]},
"expected_outputs": {
"all_tags": self.tags_name + [new_tag_name],
"content_tags": [new_tag_name],
"call_count": 1,
},
},
}

Expand All @@ -183,10 +190,11 @@ def post_form(self, inputs):
form_data = {"tags": inputs["tags"]}
self.client.post(self.form_url, form_data)

def check_effects(self, expected_outputs):
def check_effects(self, expected_outputs, tags_management):
"""Check the effects of having sent the form."""
updated_content = PublishableContent.objects.get(pk=self.content.pk)
content_tags_as_string = [tag.title for tag in updated_content.tags.all()]
all_tags_as_string = [tag.title for tag in Tag.objects.all()]
self.assertEqual(content_tags_as_string, expected_outputs["content_tags"])
self.assertEqual(all_tags_as_string, expected_outputs["all_tags"])
self.assertEqual(tags_management.send.call_count, expected_outputs["call_count"])

0 comments on commit 00c2416

Please sign in to comment.