tailbone/tests/test_subscribers.py

40 lines
1.4 KiB
Python
Raw Permalink Normal View History

2013-06-20 00:23:15 -05:00
from unittest import TestCase
2013-06-20 00:23:15 -05:00
from mock import Mock
from pyramid import testing
2013-06-20 00:23:15 -05:00
2013-09-01 09:27:47 -05:00
from tailbone import subscribers
2013-06-20 00:23:15 -05:00
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()