Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds failing test for cleared foreignkey behaviour #744

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions wagtail_localize/tests/test_update_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,46 @@ def test_post_update_page_translation_with_publish_translations_and_cleared_text
self.assertEqual(self.fr_blog_post.test_charfield, "")
self.assertEqual(self.fr_blog_post.test_richtextfield, "")

def test_post_update_page_translation_with_publish_translations_and_cleared_foreignkey(
self,
):
# Premable: First publish and translate with a test_snippet value
self.en_blog_post.test_snippet = self.en_snippet
self.en_blog_post.save_revision().publish()
response = self.client.post(
reverse(
"wagtail_localize:update_translations",
args=[self.page_source.id],
),
{"publish_translations": "on"},
)

# Sanity check: Both versions of page point to localise snippet instance
self.fr_blog_post.refresh_from_db()
self.assertEqual(self.en_blog_post.test_snippet, self.en_snippet)
self.assertEqual(self.fr_blog_post.test_snippet, self.fr_snippet)

# Now update page by clearing the test_snippet foreign key
self.en_blog_post.test_snippet = None
self.en_blog_post.save_revision().publish()

# ... and retranslate
response = self.client.post(
reverse(
"wagtail_localize:update_translations",
args=[self.page_source.id],
),
{"publish_translations": "on"},
)

self.assertRedirects(
response, reverse("wagtailadmin_explore", args=[self.en_blog_index.id])
)

# The FR version's test_snippet field should also be cleared
self.fr_blog_post.refresh_from_db()
self.assertEqual(self.fr_blog_post.test_snippet, None)

def test_post_update_snippet_translation(self):
self.en_snippet.field = "Edited snippet"
self.en_snippet.save()
Expand Down
Loading