summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/__init__.py0
-rw-r--r--test/test_l10n.py44
2 files changed, 44 insertions, 0 deletions
diff --git a/test/__init__.py b/test/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/__init__.py
diff --git a/test/test_l10n.py b/test/test_l10n.py
new file mode 100644
index 00000000..1a1ef3e6
--- /dev/null
+++ b/test/test_l10n.py
@@ -0,0 +1,44 @@
+""" Test our l10n module. """
+from aurweb import l10n
+
+
+class FakeRequest:
+ """ A fake Request doppleganger; use this to change request.cookies
+ easily and with no side-effects. """
+
+ def __init__(self, *args, **kwargs):
+ self.cookies = kwargs.pop("cookies", dict())
+
+
+def test_translator():
+ """ Test creating l10n translation tools. """
+ de_home = l10n.translator.translate("Home", "de")
+ assert de_home == "Startseite"
+
+
+def test_get_request_language():
+ """ First, tests default_lang, then tests a modified AURLANG cookie. """
+ request = FakeRequest()
+ assert l10n.get_request_language(request) == "en"
+
+ request.cookies["AURLANG"] = "de"
+ assert l10n.get_request_language(request) == "de"
+
+
+def test_get_raw_translator_for_request():
+ """ Make sure that get_raw_translator_for_request is giving us
+ the translator we expect. """
+ request = FakeRequest(cookies={"AURLANG": "de"})
+
+ translator = l10n.get_raw_translator_for_request(request)
+ assert translator.gettext("Home") == \
+ l10n.translator.translate("Home", "de")
+
+
+def test_get_translator_for_request():
+ """ Make sure that get_translator_for_request is giving us back
+ our expected translation function. """
+ request = FakeRequest(cookies={"AURLANG": "de"})
+
+ translate = l10n.get_translator_for_request(request)
+ assert translate("Home") == "Startseite"