class TestSubmitSnippetTranslationView(WagtailTestUtils, TestCase): def setUp(self): self.en_locale = Locale.objects.first() self.fr_locale = Locale.objects.create(language_code="fr") self.en_snippet = TranslatableSnippet(text="Hello world", locale=self.en_locale) self.en_snippet.save() def test_get_title(self): view = SubmitSnippetTranslationView() view.object = self.en_snippet self.assertEqual(view.get_title(), "Translate translatable snippet") def test_get_object(self): view = SubmitSnippetTranslationView() view.object = self.en_snippet view.kwargs = { "app_label": "some_app", "model_name": "some_model", "pk": 1, } with self.assertRaises(Http404): view.get_object() content_type = ContentType.objects.get_for_model(self.en_snippet) view.kwargs = { "app_label": content_type.app_label, "model_name": content_type.model, "pk": str(self.en_snippet.pk), } self.assertEqual(view.get_object(), self.en_snippet) def test_get_success_url(self): view = SubmitSnippetTranslationView() view.object = self.en_snippet view.kwargs = { "app_label": "some_app", "model_name": "some_model", "pk": 99, } self.assertEqual(view.get_success_url(), "/admin/snippets/some_app/some_model/edit/99/") def test_get_success_message(self): view = SubmitSnippetTranslationView() view.object = self.en_snippet self.assertEqual( view.get_success_message(self.fr_locale), f"Successfully created French for translatable snippet 'TranslatableSnippet object ({self.en_snippet.id})'", )
def setUp(self): self.en_locale = Locale.objects.first() self.fr_locale = Locale.objects.create(language_code="fr") self.en_snippet = TranslatableSnippet(text="Hello world", locale=self.en_locale) self.en_snippet.save()