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( |
0c29cf
|
8 |
os.path.join(here, '..', 'pkgs', 'localeapp', 'locale') |
MM |
9 |
) |
728235
|
10 |
locale2 = os.path.abspath( |
0c29cf
|
11 |
os.path.join(here, '..', 'pkgs', 'localeapp', 'locale2') |
MM |
12 |
) |
728235
|
13 |
locale3 = os.path.abspath( |
0c29cf
|
14 |
os.path.join(here, '..', 'pkgs', 'localeapp', 'locale3') |
MM |
15 |
) |
|
16 |
|
728235
|
17 |
|
CM |
18 |
class TestI18NConfiguratorMixin(unittest.TestCase): |
|
19 |
def _makeOne(self, *arg, **kw): |
|
20 |
from pyramid.config import Configurator |
0c29cf
|
21 |
|
728235
|
22 |
config = Configurator(*arg, **kw) |
CM |
23 |
return config |
|
24 |
|
|
25 |
def test_set_locale_negotiator(self): |
|
26 |
from pyramid.interfaces import ILocaleNegotiator |
0c29cf
|
27 |
|
728235
|
28 |
config = self._makeOne(autocommit=True) |
0c29cf
|
29 |
|
10ddb6
|
30 |
def negotiator(request): # pragma: no cover |
0c29cf
|
31 |
pass |
MM |
32 |
|
728235
|
33 |
config.set_locale_negotiator(negotiator) |
0c29cf
|
34 |
self.assertEqual( |
MM |
35 |
config.registry.getUtility(ILocaleNegotiator), negotiator |
|
36 |
) |
728235
|
37 |
|
CM |
38 |
def test_set_locale_negotiator_dottedname(self): |
|
39 |
from pyramid.interfaces import ILocaleNegotiator |
0c29cf
|
40 |
|
728235
|
41 |
config = self._makeOne(autocommit=True) |
0c29cf
|
42 |
config.set_locale_negotiator('tests.test_config.dummyfactory') |
MM |
43 |
self.assertEqual( |
|
44 |
config.registry.getUtility(ILocaleNegotiator), dummyfactory |
|
45 |
) |
728235
|
46 |
|
CM |
47 |
def test_add_translation_dirs_missing_dir(self): |
|
48 |
from pyramid.exceptions import ConfigurationError |
0c29cf
|
49 |
|
728235
|
50 |
config = self._makeOne() |
0c1c58
|
51 |
config.add_translation_dirs('/wont/exist/on/my/system') |
MM |
52 |
self.assertRaises(ConfigurationError, config.commit) |
728235
|
53 |
|
CM |
54 |
def test_add_translation_dirs_no_specs(self): |
|
55 |
from pyramid.interfaces import ITranslationDirectories |
0c29cf
|
56 |
|
728235
|
57 |
config = self._makeOne() |
CM |
58 |
config.add_translation_dirs() |
0c29cf
|
59 |
self.assertEqual( |
MM |
60 |
config.registry.queryUtility(ITranslationDirectories), None |
|
61 |
) |
728235
|
62 |
|
CM |
63 |
def test_add_translation_dirs_asset_spec(self): |
|
64 |
from pyramid.interfaces import ITranslationDirectories |
0c29cf
|
65 |
|
728235
|
66 |
config = self._makeOne(autocommit=True) |
dd3cc8
|
67 |
config.add_translation_dirs('tests.pkgs.localeapp:locale') |
0c29cf
|
68 |
self.assertEqual( |
MM |
69 |
config.registry.getUtility(ITranslationDirectories), [locale] |
|
70 |
) |
728235
|
71 |
|
CM |
72 |
def test_add_translation_dirs_asset_spec_existing_translation_dirs(self): |
|
73 |
from pyramid.interfaces import ITranslationDirectories |
0c29cf
|
74 |
|
728235
|
75 |
config = self._makeOne(autocommit=True) |
CM |
76 |
directories = ['abc'] |
|
77 |
config.registry.registerUtility(directories, ITranslationDirectories) |
dd3cc8
|
78 |
config.add_translation_dirs('tests.pkgs.localeapp:locale') |
728235
|
79 |
result = config.registry.getUtility(ITranslationDirectories) |
CM |
80 |
self.assertEqual(result, [locale, 'abc']) |
|
81 |
|
|
82 |
def test_add_translation_dirs_multiple_specs(self): |
|
83 |
from pyramid.interfaces import ITranslationDirectories |
0c29cf
|
84 |
|
728235
|
85 |
config = self._makeOne(autocommit=True) |
0c29cf
|
86 |
config.add_translation_dirs( |
MM |
87 |
'tests.pkgs.localeapp:locale', 'tests.pkgs.localeapp:locale2' |
|
88 |
) |
|
89 |
self.assertEqual( |
|
90 |
config.registry.getUtility(ITranslationDirectories), |
|
91 |
[locale, locale2], |
|
92 |
) |
728235
|
93 |
|
CM |
94 |
def test_add_translation_dirs_multiple_specs_multiple_calls(self): |
|
95 |
from pyramid.interfaces import ITranslationDirectories |
0c29cf
|
96 |
|
728235
|
97 |
config = self._makeOne(autocommit=True) |
0c29cf
|
98 |
config.add_translation_dirs( |
MM |
99 |
'tests.pkgs.localeapp:locale', 'tests.pkgs.localeapp:locale2' |
|
100 |
) |
dd3cc8
|
101 |
config.add_translation_dirs('tests.pkgs.localeapp:locale3') |
0c29cf
|
102 |
self.assertEqual( |
MM |
103 |
config.registry.getUtility(ITranslationDirectories), |
|
104 |
[locale3, locale, locale2], |
|
105 |
) |
728235
|
106 |
|
d009c0
|
107 |
def test_add_translation_dirs_override_multiple_specs_multiple_calls(self): |
MM |
108 |
from pyramid.interfaces import ITranslationDirectories |
0c29cf
|
109 |
|
d009c0
|
110 |
config = self._makeOne(autocommit=True) |
0c29cf
|
111 |
config.add_translation_dirs( |
MM |
112 |
'tests.pkgs.localeapp:locale', 'tests.pkgs.localeapp:locale2' |
|
113 |
) |
|
114 |
config.add_translation_dirs( |
|
115 |
'tests.pkgs.localeapp:locale3', override=True |
|
116 |
) |
|
117 |
self.assertEqual( |
|
118 |
config.registry.getUtility(ITranslationDirectories), |
|
119 |
[locale, locale2, locale3], |
|
120 |
) |
d009c0
|
121 |
|
MM |
122 |
def test_add_translation_dirs_invalid_kwargs(self): |
|
123 |
config = self._makeOne(autocommit=True) |
|
124 |
with self.assertRaises(TypeError): |
0c29cf
|
125 |
config.add_translation_dirs('tests.pkgs.localeapp:locale', foo=1) |
d009c0
|
126 |
|
728235
|
127 |
def test_add_translation_dirs_abspath(self): |
CM |
128 |
from pyramid.interfaces import ITranslationDirectories |
0c29cf
|
129 |
|
728235
|
130 |
config = self._makeOne(autocommit=True) |
CM |
131 |
config.add_translation_dirs(locale) |
0c29cf
|
132 |
self.assertEqual( |
MM |
133 |
config.registry.getUtility(ITranslationDirectories), [locale] |
|
134 |
) |
728235
|
135 |
|
804eb0
|
136 |
def test_add_translation_dirs_uses_override_out_of_order(self): |
0c1c58
|
137 |
from pyramid.interfaces import ITranslationDirectories |
0c29cf
|
138 |
|
0c1c58
|
139 |
config = self._makeOne() |
dd3cc8
|
140 |
config.add_translation_dirs('tests.pkgs.localeapp:locale') |
0c29cf
|
141 |
config.override_asset( |
MM |
142 |
'tests.pkgs.localeapp:locale/', 'tests.pkgs.localeapp:locale2/' |
|
143 |
) |
0c1c58
|
144 |
config.commit() |
0c29cf
|
145 |
self.assertEqual( |
MM |
146 |
config.registry.getUtility(ITranslationDirectories), [locale2] |
|
147 |
) |
804eb0
|
148 |
|
MM |
149 |
def test_add_translation_dirs_doesnt_use_override_w_autocommit(self): |
|
150 |
from pyramid.interfaces import ITranslationDirectories |
0c29cf
|
151 |
|
804eb0
|
152 |
config = self._makeOne(autocommit=True) |
dd3cc8
|
153 |
config.add_translation_dirs('tests.pkgs.localeapp:locale') |
0c29cf
|
154 |
config.override_asset( |
MM |
155 |
'tests.pkgs.localeapp:locale/', 'tests.pkgs.localeapp:locale2/' |
|
156 |
) |
|
157 |
self.assertEqual( |
|
158 |
config.registry.getUtility(ITranslationDirectories), [locale] |
|
159 |
) |
804eb0
|
160 |
|
MM |
161 |
def test_add_translation_dirs_uses_override_w_autocommit(self): |
|
162 |
from pyramid.interfaces import ITranslationDirectories |
0c29cf
|
163 |
|
804eb0
|
164 |
config = self._makeOne(autocommit=True) |
0c29cf
|
165 |
config.override_asset( |
MM |
166 |
'tests.pkgs.localeapp:locale/', 'tests.pkgs.localeapp:locale2/' |
|
167 |
) |
dd3cc8
|
168 |
config.add_translation_dirs('tests.pkgs.localeapp:locale') |
0c29cf
|
169 |
self.assertEqual( |
MM |
170 |
config.registry.getUtility(ITranslationDirectories), [locale2] |
|
171 |
) |