'''
+def base_view(wrapped):
+ '''Decorator for any view which includes base.mk.
+ '''
+ def wrapper(request):
+ '''Add variables missing but needed by base.mk to the response.
+ '''
+ response = wrapped(request)
+ pgwui = response.get('pgwui', {})
+ pgwui.setdefault('url.css',
+ request.static_url('pgwui_common:static/pgwui.css'))
+ response['pgwui'] = pgwui
+ return response
+ return wrapper
+
+
+def auth_base_view(wrapped):
+ '''Decorator for any view which includes auth_base.mk.
+ '''
+ return base_view(wrapped)
+
+
def includeme(config):
'''Pyramid configuration for PGWUI_Common
'''
config.include('pyramid_mako')
config.include('pyramid_beaker')
config.add_static_view(
- 'static', 'pgwui_common:/static', cache_max_age=3600)
+ 'static',
+ 'pgwui_common:static/',
+ cache_max_age=3600)
# Karl O. Pinc <kop@meme.com>
+import pyramid.config
+import pyramid.testing
+import pyramid.threadlocal
+import pytest
import pgwui_common.__init__ as pgwui_common_init
-def test_configure_includecalled():
+# Fixtures
+@pytest.fixture
+def pyramid_config():
+ yield pyramid.testing.setUp()
+ pyramid.testing.tearDown()
+
+
+@pytest.fixture
+def pyramid_request_config():
+ request = pyramid.testing.DummyRequest()
+ yield pyramid.testing.setUp(request=request)
+ pyramid.testing.tearDown()
+
+
+# Unit tests
+
+# base_view()
+def test_base_view_add(pyramid_request_config):
+ '''The response adds all expected variables'''
+ def mock_view(request):
+ return {}
+
+ pgwui_common_init.includeme(pyramid_request_config)
+ wrapper = pgwui_common_init.base_view(mock_view)
+ response = wrapper(pyramid.threadlocal.get_current_request())
+ assert response['pgwui']['url.css'][0:4] == 'http'
+
+
+def test_base_view_default(pyramid_request_config):
+ '''The response retains the mock view's variables'''
+ css_url = 'foo://bar/'
+
+ def mock_view(request):
+ return {'pgwui': {'url.css': css_url}}
+
+ pgwui_common_init.includeme(pyramid_request_config)
+ wrapper = pgwui_common_init.base_view(mock_view)
+ response = wrapper(pyramid.threadlocal.get_current_request())
+ assert response['pgwui']['url.css'] == css_url
+
+
+# auth_base_view()
+
+def test_auth_base_view(monkeypatch):
+ '''base_view() is called'''
+ base_view_called = False
+
+ def mock_base_view(wrapped):
+ nonlocal base_view_called
+ base_view_called = True
+
+ monkeypatch.setattr(pgwui_common_init, 'base_view', mock_base_view)
+
+ pgwui_common_init.auth_base_view(None)
+ assert base_view_called is True
+
+
+# includeme()
+
+def test_includeme_configurecalled():
+ '''Pyramid Configure() methods are called'''
class MockConfig():
def __init__(self):
self.include_called = False
pgwui_common_init.includeme(config)
assert config.include_called
assert config.add_static_view_called
+
+
+# Integration tests
+
+def test_includeme():
+ config = pyramid.config.Configurator()
+ pgwui_common_init.includeme(config)