pyramid-localize 0.1.0__py3.4.egg

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. EGG-INFO/PKG-INFO +139 -0
  2. EGG-INFO/SOURCES.txt +50 -0
  3. EGG-INFO/dependency_links.txt +1 -0
  4. EGG-INFO/not-zip-safe +1 -0
  5. EGG-INFO/requires.txt +15 -0
  6. EGG-INFO/top_level.txt +2 -0
  7. pyramid_localize/__init__.py +62 -0
  8. pyramid_localize/__pycache__/__init__.cpython-34.pyc +0 -0
  9. pyramid_localize/__pycache__/models.cpython-34.pyc +0 -0
  10. pyramid_localize/__pycache__/negotiator.cpython-34.pyc +0 -0
  11. pyramid_localize/__pycache__/request.cpython-34.pyc +0 -0
  12. pyramid_localize/__pycache__/tools.cpython-34.pyc +0 -0
  13. pyramid_localize/config/config.yml +13 -0
  14. pyramid_localize/models.py +37 -0
  15. pyramid_localize/negotiator.py +41 -0
  16. pyramid_localize/request.py +124 -0
  17. pyramid_localize/resources/locale/pyramid_localize.pot +58 -0
  18. pyramid_localize/resources/templates/_list.mako +33 -0
  19. pyramid_localize/resources/templates/index.mako +19 -0
  20. pyramid_localize/resources/templates/layout.mako +12 -0
  21. pyramid_localize/routing/__init__.py +5 -0
  22. pyramid_localize/routing/__pycache__/__init__.cpython-34.pyc +0 -0
  23. pyramid_localize/routing/__pycache__/predicates.cpython-34.pyc +0 -0
  24. pyramid_localize/routing/predicates.py +18 -0
  25. pyramid_localize/subscribers/__init__.py +5 -0
  26. pyramid_localize/subscribers/__pycache__/__init__.cpython-34.pyc +0 -0
  27. pyramid_localize/subscribers/__pycache__/fake.cpython-34.pyc +0 -0
  28. pyramid_localize/subscribers/__pycache__/i18n.cpython-34.pyc +0 -0
  29. pyramid_localize/subscribers/fake.py +27 -0
  30. pyramid_localize/subscribers/i18n.py +27 -0
  31. pyramid_localize/tools.py +100 -0
  32. pyramid_localize/views/__init__.py +5 -0
  33. pyramid_localize/views/__pycache__/__init__.cpython-34.pyc +0 -0
  34. pyramid_localize/views/__pycache__/catalogue.cpython-34.pyc +0 -0
  35. pyramid_localize/views/catalogue.py +225 -0
  36. tests/__init__.py +1 -0
  37. tests/__pycache__/__init__.cpython-34.pyc +0 -0
  38. tests/__pycache__/conftest.cpython-34.pyc +0 -0
  39. tests/__pycache__/test_negotiator.cpython-34.pyc +0 -0
  40. tests/__pycache__/test_predicates.cpython-34.pyc +0 -0
  41. tests/__pycache__/test_request.cpython-34.pyc +0 -0
  42. tests/__pycache__/test_subscribers.cpython-34.pyc +0 -0
  43. tests/__pycache__/test_tools.cpython-34.pyc +0 -0
  44. tests/conftest.py +58 -0
  45. tests/test_negotiator.py +55 -0
  46. tests/test_predicates.py +23 -0
  47. tests/test_request.py +89 -0
  48. tests/test_subscribers.py +80 -0
  49. tests/test_tools.py +105 -0
@@ -0,0 +1,80 @@
1
+ """Subscribers related tests."""
2
+ import pytest
3
+
4
+
5
+ from pyramid import testing
6
+ from pyramid.request import Request
7
+ from pyramid.events import BeforeRender
8
+ from pyramid.events import NewRequest
9
+ from pyramid.i18n import Localizer
10
+
11
+ # for this tests, these will be imported internally by pyramid's config
12
+ # from pyramid_localize.subscribers.i18n import global_renderer
13
+ # from pyramid_localize.subscribers.i18n import add_localizer
14
+ # from pyramid_localize.subscribers.fake import global_renderer
15
+ # from pyramid_localize.subscribers.fake import add_localizer
16
+
17
+
18
+ @pytest.fixture
19
+ def request_i18n():
20
+ """New request with i18n subscribers on."""
21
+ config = testing.setUp()
22
+ config.scan('pyramid_localize.subscribers.i18n')
23
+ request = Request({})
24
+ request.registry = config.registry
25
+ return request
26
+
27
+
28
+ def test_i18n_new_request(request_i18n):
29
+ """Test if method are being added to request."""
30
+ request_i18n.registry.notify(NewRequest(request_i18n))
31
+ assert isinstance(request_i18n.localizer, Localizer)
32
+ assert hasattr(request_i18n, '_')
33
+
34
+
35
+ def test_i18n_before_render(request_i18n):
36
+ """Test if appropriate methods are being added to render context."""
37
+ before_render_event = BeforeRender({'request': request_i18n}, {})
38
+ request_i18n.registry.notify(before_render_event)
39
+ assert 'localizer' in before_render_event
40
+ assert '_' in before_render_event
41
+
42
+
43
+ def test_i18n_before_render_and_request(request_i18n):
44
+ """Test if appropriate methods are being added to both context and request."""
45
+ request_i18n.registry.notify(NewRequest(request_i18n))
46
+ before_render_event = BeforeRender({'request': request_i18n}, {})
47
+ request_i18n.registry.notify(before_render_event)
48
+ assert 'localizer' in before_render_event
49
+ assert '_' in before_render_event
50
+
51
+
52
+ @pytest.fixture
53
+ def request_fake():
54
+ """New request with fake i18n subscribers on."""
55
+ config = testing.setUp()
56
+ config.scan('pyramid_localize.subscribers.fake')
57
+ request = Request({})
58
+ request.registry = config.registry
59
+ return request
60
+
61
+
62
+ def test_fake_new_request(request_fake):
63
+ """Test if method are being added to request."""
64
+ request_fake.registry.notify(NewRequest(request_fake))
65
+ assert hasattr(request_fake, '_')
66
+
67
+
68
+ def test_fake_before_render(request_fake):
69
+ """Test if appropriate methods are being added to both context and request."""
70
+ request_fake.registry.notify(NewRequest(request_fake))
71
+ before_render_event = BeforeRender({'request': request_fake}, {})
72
+ request_fake.registry.notify(before_render_event)
73
+ assert '_' in before_render_event
74
+
75
+
76
+ def test_fake_before_render_norequest(request_fake):
77
+ """Test if appropriate methods are being added to render context."""
78
+ before_render_event = BeforeRender({'request': request_fake}, {})
79
+ request_fake.registry.notify(before_render_event)
80
+ assert '_' in before_render_event
tests/test_tools.py ADDED
@@ -0,0 +1,105 @@
1
+ """Tools related tests."""
2
+
3
+ import sys
4
+ import os
5
+
6
+ import pytest
7
+ from mock import Mock
8
+ from pyramid.path import package_path
9
+ from pyramid.i18n import Localizer
10
+ from pyramid.interfaces import ILocalizer
11
+
12
+ from pyramid_localize.tools import dummy_autotranslate
13
+ from pyramid_localize.tools import destination_path
14
+ from pyramid_localize.tools import set_localizer
15
+
16
+ from tests.conftest import web_request as web_request_func
17
+
18
+
19
+ def test_simple(web_request):
20
+ """Simple localizer setting test on a request."""
21
+ set_localizer(web_request)
22
+ assert isinstance(web_request.localizer, Localizer)
23
+ assert hasattr(web_request, '_')
24
+
25
+
26
+ def test_reset(web_request):
27
+ """
28
+ Test resetting localizer capabilites.
29
+
30
+ 1. localizer gets set on a request.
31
+ 2. Reset localizer call gets issued.
32
+ 3. New request have new localizer set.
33
+ """
34
+ # set (and create localizer)
35
+ set_localizer(web_request)
36
+ old_localizer = web_request.localizer
37
+
38
+ queried_localizer = web_request.registry.queryUtility(
39
+ ILocalizer, name=web_request.locale_name)
40
+ assert queried_localizer == web_request.localizer
41
+ # resetting localizer
42
+ set_localizer(web_request, reset=True)
43
+ # these are equal due to request.localizer
44
+ # being reify property since pyramid 1.5
45
+ assert old_localizer == web_request.localizer
46
+ queried_localizer_after_reset = web_request.registry.queryUtility(
47
+ ILocalizer, name=web_request.locale_name)
48
+
49
+ assert queried_localizer_after_reset is not queried_localizer
50
+ # let's create a new request, to check that
51
+ request = web_request_func()
52
+ set_localizer(web_request)
53
+ assert old_localizer is not request.localizer
54
+
55
+
56
+ def test_translate(web_request):
57
+ """Simple test for translating method call."""
58
+ msgid = 'Test message'
59
+ set_localizer(web_request)
60
+ assert msgid == web_request._(msgid)
61
+
62
+
63
+ def test_destination_filename():
64
+ """Testing translation fullpath resolve."""
65
+ request = Mock()
66
+ request.registry = {'config': Mock()}
67
+ path = '/some/path/to/translations'
68
+ mock_configuration = {
69
+ 'localize.translation.destination': path}
70
+ request.registry['config'].configure_mock(**mock_configuration)
71
+ result = destination_path(request)
72
+ assert result == path
73
+
74
+
75
+ def test_destination_package():
76
+ """Testing translation package:path resolve."""
77
+ request = Mock()
78
+ request.registry = {'config': Mock()}
79
+ mock_configuration = {'localize.translation.destination': 'tests:translations'}
80
+ request.registry['config'].configure_mock(**mock_configuration)
81
+ result = destination_path(request)
82
+ assert result == os.path.join(package_path(sys.modules['tests']), 'translations')
83
+
84
+
85
+ @pytest.mark.parametrize('kwargs, result', (
86
+ (
87
+ {'msgid': 'Simple fake text'},
88
+ 'Simple fake text'
89
+ ), (
90
+ {
91
+ 'msgid': 'test-msgid',
92
+ 'default': 'Simple fake text'
93
+ },
94
+ 'Simple fake text'
95
+ ), (
96
+ {
97
+ 'msgid': 'Simple ${what} text',
98
+ 'mapping': {'what': 'fake'}
99
+ },
100
+ 'Simple fake text'
101
+ ),
102
+ ))
103
+ def test_dummy_message(kwargs, result):
104
+ """Test dummy autotranslate method."""
105
+ assert dummy_autotranslate(**kwargs) == result