Skip to content

Commit

Permalink
Découpe mieux les tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philippemilink committed Jun 23, 2024
1 parent 57af9c6 commit e44c558
Showing 1 changed file with 104 additions and 99 deletions.
203 changes: 104 additions & 99 deletions zds/tutorialv2/tests/tests_views/tests_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,131 +24,136 @@
@override_settings(ZDS_APP=overridden_zds_app)
@override_settings(ES_ENABLED=False)
class DisplayConfigTests(TutorialTestMixin, TestCase):
TEXT_FIRST_MODIFICATION = "Modified introduction"
TEXT_SECOND_MODIFICATION = "Modified Introduction"

def setUp(self):
self.overridden_zds_app = overridden_zds_app
overridden_zds_app["content"]["default_licence_pk"] = LicenceFactory().pk

self.user_author = ProfileFactory().user

def test_sidebar_items(self):
self.client.force_login(self.user_author)

# Publish an article:
article = PublishedContentFactory(author_list=[self.user_author], type="ARTICLE")
# Public page:
public_page = self.client.get(article.get_absolute_url_online())
self.assertContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertContains(public_page, PublicActionsState.messages["export_content"])
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])
# Draft page:
draft_page = self.client.get(reverse("content:view", args=[article.pk, article.slug]), follow=False)
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])
self.article = PublishedContentFactory(author_list=[self.user_author], type="ARTICLE")

def _new_draft_version(self, text):
# Create a new draft version:
versioned = article.load_version()
versioned = self.article.load_version()
result = self.client.post(
reverse("content:edit", args=[article.pk, article.slug]),
reverse("content:edit", args=[self.article.pk, self.article.slug]),
{
"title": article.title,
"description": article.description,
"introduction": "Modified introduction",
"title": self.article.title,
"description": self.article.description,
"introduction": text,
"conclusion": "Modified conclusion",
"type": article.type,
"subcategory": article.subcategory.first().pk,
"type": self.article.type,
"subcategory": self.article.subcategory.first().pk,
"last_hash": versioned.compute_hash(),
},
follow=False,
)
self.assertEqual(result.status_code, 302)
article.refresh_from_db() # the previous request changes sha_draft
# Public page:
public_page = self.client.get(article.get_absolute_url_online())
self.assertNotContains(public_page, "Modified introduction")
self.article.refresh_from_db() # the previous request changes sha_draft

def test_sidebar_items_on_public_page(self):
def common_tests():
public_page = self.client.get(self.article.get_absolute_url_online())

self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
self.assertContains(public_page, PublicActionsState.messages["export_content"])
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])

return public_page

public_page = common_tests()
self.assertContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_more_recent"])

self._new_draft_version(self.TEXT_FIRST_MODIFICATION)

public_page = common_tests()
self.assertNotContains(public_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertContains(public_page, PublicActionsState.messages["export_content"])
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])
# Draft page:
draft_page = self.client.get(reverse("content:view", args=[article.pk, article.slug]), follow=False)
self.assertContains(draft_page, "Modified introduction")
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])

# Ask validation:
request_validation(article)
# Public page:
public_page = self.client.get(article.get_absolute_url_online())
request_validation(self.article)

public_page = common_tests()
self.assertNotContains(public_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertContains(public_page, PublicActionsState.messages["export_content"])
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])
# Draft page:
draft_page = self.client.get(reverse("content:view", args=[article.pk, article.slug]), follow=False)
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])
self.assertContains(draft_page, ValidationActions.messages["validation_is_same"])
# Validation page:
validation_page = self.client.get(
reverse("content:validation-view", args=[article.pk, article.slug]), follow=False
)
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(validation_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(validation_page, PublicActionsState.messages["export_content"])
self.assertNotContains(validation_page, ValidationActions.messages["validation_is_same"])

# Now a new draft version, to have different version from validation:
versioned = article.load_version()
result = self.client.post(
reverse("content:edit", args=[article.pk, article.slug]),
{
"title": article.title,
"description": article.description,
"introduction": "Modified introduction again",
"conclusion": "Modified conclusion",
"type": article.type,
"subcategory": article.subcategory.first().pk,
"last_hash": versioned.compute_hash(),
},
follow=False,
)
self.assertEqual(result.status_code, 302)
article.refresh_from_db() # the previous request changes sha_draft
# Public page:
public_page = self.client.get(article.get_absolute_url_online())
self.assertNotContains(public_page, "Modified introduction")
self._new_draft_version(self.TEXT_SECOND_MODIFICATION)

public_page = common_tests()
self.assertNotContains(public_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(public_page, self.TEXT_SECOND_MODIFICATION)
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertContains(public_page, PublicActionsState.messages["export_content"])
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])
# Draft page:
draft_page = self.client.get(reverse("content:view", args=[article.pk, article.slug]), follow=False)
self.assertContains(draft_page, "Modified introduction")
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])

def test_sidebar_items_on_draft_page(self):
def common_tests():
draft_page = self.client.get(
reverse("content:view", args=[self.article.pk, self.article.slug]), follow=False
)

self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])

return draft_page

draft_page = common_tests()
self.assertContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])

self._new_draft_version(self.TEXT_FIRST_MODIFICATION)

draft_page = common_tests()
self.assertContains(draft_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])
# Validation page:
validation_page = self.client.get(
reverse("content:validation-view", args=[article.pk, article.slug]), follow=False
)
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(validation_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(validation_page, PublicActionsState.messages["export_content"])
self.assertNotContains(validation_page, ValidationActions.messages["validation_is_same"])

request_validation(self.article)

draft_page = common_tests()
self.assertContains(draft_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertContains(draft_page, ValidationActions.messages["validation_is_same"])

# Now a new draft version, to have different version from validation:
self._new_draft_version(self.TEXT_SECOND_MODIFICATION)

draft_page = common_tests()
self.assertContains(draft_page, self.TEXT_SECOND_MODIFICATION)
self.assertNotContains(draft_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])

def test_sidebar_items_on_validation_page(self):
def common_tests():
validation_page = self.client.get(
reverse("content:validation-view", args=[self.article.pk, self.article.slug]), follow=False
)

self.assertContains(validation_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(validation_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(validation_page, PublicActionsState.messages["export_content"])
self.assertNotContains(validation_page, ValidationActions.messages["validation_is_same"])

return validation_page

self._new_draft_version(self.TEXT_FIRST_MODIFICATION)
request_validation(self.article)

validation_page = common_tests()

# Now a new draft version, to have different version from validation:
self._new_draft_version(self.TEXT_SECOND_MODIFICATION)

validation_page = common_tests()
self.assertNotContains(validation_page, self.TEXT_SECOND_MODIFICATION)

0 comments on commit e44c558

Please sign in to comment.