From 0a469cfdd112b0aaae9a7576c688dffd8976142e Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Thu, 7 Jan 2021 16:58:38 +0100 Subject: [PATCH] test case for localized index view --- src/documents/tests/test_views.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/documents/tests/test_views.py diff --git a/src/documents/tests/test_views.py b/src/documents/tests/test_views.py new file mode 100644 index 000000000..ccc41666a --- /dev/null +++ b/src/documents/tests/test_views.py @@ -0,0 +1,30 @@ +from django.conf import settings +from django.contrib.auth.models import User +from django.test import TestCase + + +class TestViews(TestCase): + + def setUp(self) -> None: + self.user = User.objects.create_user("testuser") + + def test_login_redirect(self): + response = self.client.get('/') + self.assertEqual(response.status_code, 302) + self.assertEqual(response.url, "/accounts/login/?next=/") + + def test_index(self): + self.client.force_login(self.user) + for (language_given, language_actual) in [("", "en-US"), ("en-US", "en-US"), ("de", "de"), ("en", "en-US"), ("en-us", "en-US"), ("fr", "fr"), ("jp", "en-US")]: + if language_given: + self.client.cookies.load({settings.LANGUAGE_COOKIE_NAME: language_given}) + elif settings.LANGUAGE_COOKIE_NAME in self.client.cookies.keys(): + self.client.cookies.pop(settings.LANGUAGE_COOKIE_NAME) + + response = self.client.get('/', ) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context_data['webmanifest'], f"frontend/{language_actual}/manifest.webmanifest") + self.assertEqual(response.context_data['styles_css'], f"frontend/{language_actual}/styles.css") + self.assertEqual(response.context_data['runtime_js'], f"frontend/{language_actual}/runtime.js") + self.assertEqual(response.context_data['polyfills_js'], f"frontend/{language_actual}/polyfills.js") + self.assertEqual(response.context_data['main_js'], f"frontend/{language_actual}/main.js")