40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
|
|
from unittest import TestCase
|
|
|
|
from mock import Mock
|
|
from pyramid import testing
|
|
|
|
from tailbone import subscribers
|
|
|
|
|
|
class SubscribersTests(TestCase):
|
|
|
|
def test_before_render(self):
|
|
event = Mock()
|
|
event.__setitem__ = Mock()
|
|
subscribers.before_render(event)
|
|
|
|
|
|
class TestAddRattailConfigAttributeToRequest(TestCase):
|
|
|
|
def test_nothing_is_done_if_no_config_in_registry_settings(self):
|
|
request = testing.DummyRequest()
|
|
config = testing.setUp(request=request)
|
|
self.assertFalse('rattail_config' in request.registry.settings)
|
|
self.assertFalse(hasattr(request, 'rattail_config'))
|
|
event = Mock(request=request)
|
|
subscribers.add_rattail_config_attribute_to_request(event)
|
|
self.assertFalse(hasattr(request, 'rattail_config'))
|
|
testing.tearDown()
|
|
|
|
def test_attribute_added_if_config_present_in_registry_settings(self):
|
|
rattail_config = Mock()
|
|
request = testing.DummyRequest()
|
|
config = testing.setUp(request=request, settings={'rattail_config': rattail_config})
|
|
self.assertTrue('rattail_config' in request.registry.settings)
|
|
self.assertFalse(hasattr(request, 'rattail_config'))
|
|
event = Mock(request=request)
|
|
subscribers.add_rattail_config_attribute_to_request(event)
|
|
self.assertTrue(request.rattail_config is rattail_config)
|
|
testing.tearDown()
|