Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/units/client/routes.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/client/routes.py')
-rwxr-xr-xtests/units/client/routes.py92
1 files changed, 91 insertions, 1 deletions
diff --git a/tests/units/client/routes.py b/tests/units/client/routes.py
index 7514c96..6b0d6e5 100755
--- a/tests/units/client/routes.py
+++ b/tests/units/client/routes.py
@@ -10,7 +10,7 @@ from os.path import exists
from __init__ import tests
-from sugar_network import db, client, model
+from sugar_network import db, client, model, toolkit
from sugar_network.client import journal, IPCConnection, cache_limit, cache_lifetime
from sugar_network.client.routes import ClientRoutes, CachedClientRoutes
from sugar_network.model.user import User
@@ -396,6 +396,96 @@ class RoutesTest(tests.Test):
assert home_volume['implementation'].exists(guid)
assert exists('client/implementation/%s/%s' % (guid[:2], guid))
+ def test_LanguagesFallbackInRequests(self):
+ self.start_online_client()
+ ipc = IPCConnection()
+
+ guid1 = self.node_volume['context'].create({
+ 'type': 'activity',
+ 'title': {'en': '1', 'ru': '2', 'es': '3'},
+ 'summary': '',
+ 'description': '',
+ })
+ guid2 = self.node_volume['context'].create({
+ 'type': 'activity',
+ 'title': {'en': '1', 'ru': '2'},
+ 'summary': '',
+ 'description': '',
+ })
+ guid3 = self.node_volume['context'].create({
+ 'type': 'activity',
+ 'title': {'en': '1'},
+ 'summary': '',
+ 'description': '',
+ })
+
+ client.accept_language.value = ['es', 'ru', 'en']
+ self.assertEqual('3', ipc.get(['context', guid1, 'title']))
+ self.assertEqual('2', ipc.get(['context', guid2, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid3, 'title']))
+
+ client.accept_language.value = ['ru', 'en']
+ self.assertEqual('2', ipc.get(['context', guid1, 'title']))
+ self.assertEqual('2', ipc.get(['context', guid2, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid3, 'title']))
+
+ client.accept_language.value = ['en']
+ self.assertEqual('1', ipc.get(['context', guid1, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid2, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid3, 'title']))
+
+ client.accept_language.value = ['foo']
+ self.assertEqual('1', ipc.get(['context', guid1, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid2, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid3, 'title']))
+
+ def test_DefaultLanguagesFallbackInRequests(self):
+ self.start_online_client()
+ ipc = IPCConnection()
+
+ guid1 = self.node_volume['context'].create({
+ 'type': 'activity',
+ 'title': {'en': '1', 'ru': '2', 'es': '3'},
+ 'summary': '',
+ 'description': '',
+ })
+ guid2 = self.node_volume['context'].create({
+ 'type': 'activity',
+ 'title': {'en': '1', 'ru': '2'},
+ 'summary': '',
+ 'description': '',
+ })
+ guid3 = self.node_volume['context'].create({
+ 'type': 'activity',
+ 'title': {'en': '1'},
+ 'summary': '',
+ 'description': '',
+ })
+
+ toolkit._default_langs = None
+ os.environ['LANGUAGE'] = 'es:ru:en'
+ self.assertEqual('3', ipc.get(['context', guid1, 'title']))
+ self.assertEqual('2', ipc.get(['context', guid2, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid3, 'title']))
+
+ toolkit._default_langs = None
+ os.environ['LANGUAGE'] = 'ru:en'
+ self.assertEqual('2', ipc.get(['context', guid1, 'title']))
+ self.assertEqual('2', ipc.get(['context', guid2, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid3, 'title']))
+
+ toolkit._default_langs = None
+ os.environ['LANGUAGE'] = 'en'
+ self.assertEqual('1', ipc.get(['context', guid1, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid2, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid3, 'title']))
+
+ toolkit._default_langs = None
+ os.environ['LANGUAGE'] = 'foo'
+ self.assertEqual('1', ipc.get(['context', guid1, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid2, 'title']))
+ self.assertEqual('1', ipc.get(['context', guid3, 'title']))
+
def call(routes, request):
router = Router(routes)