commit | author | age
|
728235
|
1 |
import os |
CM |
2 |
import unittest |
|
3 |
|
dd3cc8
|
4 |
from . import dummyfactory |
728235
|
5 |
|
CM |
6 |
here = os.path.dirname(__file__) |
|
7 |
locale = os.path.abspath( |
24b1c8
|
8 |
os.path.join(here, '..', 'pkgs', 'localeapp', 'locale')) |
728235
|
9 |
locale2 = os.path.abspath( |
24b1c8
|
10 |
os.path.join(here, '..', 'pkgs', 'localeapp', 'locale2')) |
728235
|
11 |
locale3 = os.path.abspath( |
24b1c8
|
12 |
os.path.join(here, '..', 'pkgs', 'localeapp', 'locale3')) |
728235
|
13 |
|
CM |
14 |
class TestI18NConfiguratorMixin(unittest.TestCase): |
|
15 |
def _makeOne(self, *arg, **kw): |
|
16 |
from pyramid.config import Configurator |
|
17 |
config = Configurator(*arg, **kw) |
|
18 |
return config |
|
19 |
|
|
20 |
def test_set_locale_negotiator(self): |
|
21 |
from pyramid.interfaces import ILocaleNegotiator |
|
22 |
config = self._makeOne(autocommit=True) |
|
23 |
def negotiator(request): pass |
|
24 |
config.set_locale_negotiator(negotiator) |
|
25 |
self.assertEqual(config.registry.getUtility(ILocaleNegotiator), |
|
26 |
negotiator) |
|
27 |
|
|
28 |
def test_set_locale_negotiator_dottedname(self): |
|
29 |
from pyramid.interfaces import ILocaleNegotiator |
|
30 |
config = self._makeOne(autocommit=True) |
|
31 |
config.set_locale_negotiator( |
dd3cc8
|
32 |
'tests.test_config.dummyfactory') |
728235
|
33 |
self.assertEqual(config.registry.getUtility(ILocaleNegotiator), |
CM |
34 |
dummyfactory) |
|
35 |
|
|
36 |
def test_add_translation_dirs_missing_dir(self): |
|
37 |
from pyramid.exceptions import ConfigurationError |
|
38 |
config = self._makeOne() |
0c1c58
|
39 |
config.add_translation_dirs('/wont/exist/on/my/system') |
MM |
40 |
self.assertRaises(ConfigurationError, config.commit) |
728235
|
41 |
|
CM |
42 |
def test_add_translation_dirs_no_specs(self): |
|
43 |
from pyramid.interfaces import ITranslationDirectories |
|
44 |
config = self._makeOne() |
|
45 |
config.add_translation_dirs() |
|
46 |
self.assertEqual(config.registry.queryUtility(ITranslationDirectories), |
|
47 |
None) |
|
48 |
|
|
49 |
def test_add_translation_dirs_asset_spec(self): |
|
50 |
from pyramid.interfaces import ITranslationDirectories |
|
51 |
config = self._makeOne(autocommit=True) |
dd3cc8
|
52 |
config.add_translation_dirs('tests.pkgs.localeapp:locale') |
728235
|
53 |
self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
CM |
54 |
[locale]) |
|
55 |
|
|
56 |
def test_add_translation_dirs_asset_spec_existing_translation_dirs(self): |
|
57 |
from pyramid.interfaces import ITranslationDirectories |
|
58 |
config = self._makeOne(autocommit=True) |
|
59 |
directories = ['abc'] |
|
60 |
config.registry.registerUtility(directories, ITranslationDirectories) |
dd3cc8
|
61 |
config.add_translation_dirs('tests.pkgs.localeapp:locale') |
728235
|
62 |
result = config.registry.getUtility(ITranslationDirectories) |
CM |
63 |
self.assertEqual(result, [locale, 'abc']) |
|
64 |
|
|
65 |
def test_add_translation_dirs_multiple_specs(self): |
|
66 |
from pyramid.interfaces import ITranslationDirectories |
|
67 |
config = self._makeOne(autocommit=True) |
dd3cc8
|
68 |
config.add_translation_dirs('tests.pkgs.localeapp:locale', |
MM |
69 |
'tests.pkgs.localeapp:locale2') |
728235
|
70 |
self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
CM |
71 |
[locale, locale2]) |
|
72 |
|
|
73 |
def test_add_translation_dirs_multiple_specs_multiple_calls(self): |
|
74 |
from pyramid.interfaces import ITranslationDirectories |
|
75 |
config = self._makeOne(autocommit=True) |
dd3cc8
|
76 |
config.add_translation_dirs('tests.pkgs.localeapp:locale', |
MM |
77 |
'tests.pkgs.localeapp:locale2') |
|
78 |
config.add_translation_dirs('tests.pkgs.localeapp:locale3') |
728235
|
79 |
self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
CM |
80 |
[locale3, locale, locale2]) |
|
81 |
|
d009c0
|
82 |
def test_add_translation_dirs_override_multiple_specs_multiple_calls(self): |
MM |
83 |
from pyramid.interfaces import ITranslationDirectories |
|
84 |
config = self._makeOne(autocommit=True) |
dd3cc8
|
85 |
config.add_translation_dirs('tests.pkgs.localeapp:locale', |
MM |
86 |
'tests.pkgs.localeapp:locale2') |
|
87 |
config.add_translation_dirs('tests.pkgs.localeapp:locale3', |
d009c0
|
88 |
override=True) |
MM |
89 |
self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
|
90 |
[locale, locale2, locale3]) |
|
91 |
|
|
92 |
def test_add_translation_dirs_invalid_kwargs(self): |
|
93 |
from pyramid.interfaces import ITranslationDirectories |
|
94 |
config = self._makeOne(autocommit=True) |
|
95 |
with self.assertRaises(TypeError): |
dd3cc8
|
96 |
config.add_translation_dirs('tests.pkgs.localeapp:locale', |
d009c0
|
97 |
foo=1) |
MM |
98 |
|
728235
|
99 |
def test_add_translation_dirs_abspath(self): |
CM |
100 |
from pyramid.interfaces import ITranslationDirectories |
|
101 |
config = self._makeOne(autocommit=True) |
|
102 |
config.add_translation_dirs(locale) |
|
103 |
self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
|
104 |
[locale]) |
|
105 |
|
804eb0
|
106 |
def test_add_translation_dirs_uses_override_out_of_order(self): |
0c1c58
|
107 |
from pyramid.interfaces import ITranslationDirectories |
MM |
108 |
config = self._makeOne() |
dd3cc8
|
109 |
config.add_translation_dirs('tests.pkgs.localeapp:locale') |
MM |
110 |
config.override_asset('tests.pkgs.localeapp:locale/', |
|
111 |
'tests.pkgs.localeapp:locale2/') |
0c1c58
|
112 |
config.commit() |
MM |
113 |
self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
804eb0
|
114 |
[locale2]) |
MM |
115 |
|
|
116 |
def test_add_translation_dirs_doesnt_use_override_w_autocommit(self): |
|
117 |
from pyramid.interfaces import ITranslationDirectories |
|
118 |
config = self._makeOne(autocommit=True) |
dd3cc8
|
119 |
config.add_translation_dirs('tests.pkgs.localeapp:locale') |
MM |
120 |
config.override_asset('tests.pkgs.localeapp:locale/', |
|
121 |
'tests.pkgs.localeapp:locale2/') |
804eb0
|
122 |
self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
MM |
123 |
[locale]) |
|
124 |
|
|
125 |
def test_add_translation_dirs_uses_override_w_autocommit(self): |
|
126 |
from pyramid.interfaces import ITranslationDirectories |
|
127 |
config = self._makeOne(autocommit=True) |
dd3cc8
|
128 |
config.override_asset('tests.pkgs.localeapp:locale/', |
MM |
129 |
'tests.pkgs.localeapp:locale2/') |
|
130 |
config.add_translation_dirs('tests.pkgs.localeapp:locale') |
804eb0
|
131 |
self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
MM |
132 |
[locale2]) |