| | |
| | | |
| | | class TestTweens(unittest.TestCase): |
| | | def _makeOne(self): |
| | | from pyramid.config import Tweens |
| | | from pyramid.tweens import Tweens |
| | | return Tweens() |
| | | |
| | | def test_add_explicit(self): |
| | |
| | | self.assertEqual(tweens(None, None), '123') |
| | | |
| | | def test___call___implicit(self): |
| | | from pyramid.tweens import INGRESS |
| | | tweens = self._makeOne() |
| | | def factory1(handler, registry): |
| | | return handler |
| | |
| | | tweens.names = ['name', 'name2'] |
| | | tweens.alias_to_name = {'name':'name', 'name2':'name2'} |
| | | tweens.name_to_alias = {'name':'name', 'name2':'name2'} |
| | | tweens.req_under = set(['name', 'name2']) |
| | | tweens.order = [(INGRESS, 'name'), (INGRESS, 'name2')] |
| | | tweens.factories = {'name':factory1, 'name2':factory2} |
| | | self.assertEqual(tweens(None, None), '123') |
| | | |
| | | def test___call___implicit_with_aliasnames_different_than_names(self): |
| | | from pyramid.tweens import INGRESS |
| | | tweens = self._makeOne() |
| | | def factory1(handler, registry): |
| | | return handler |
| | |
| | | tweens.names = ['name', 'name2'] |
| | | tweens.alias_to_name = {'foo1':'name', 'foo2':'name2'} |
| | | tweens.name_to_alias = {'name':'foo1', 'name2':'foo2'} |
| | | tweens.req_under = set(['foo1', 'foo2']) |
| | | tweens.order = [(INGRESS, 'name'), (INGRESS, 'name2')] |
| | | tweens.factories = {'name':factory1, 'name2':factory2} |
| | | self.assertEqual(tweens(None, None), '123') |
| | | |
| | |
| | | ('txnmgr', 'txnmgr_factory'), |
| | | ]) |
| | | |
| | | def test_implicit_ordering_missing_partial(self): |
| | | def test_implicit_ordering_missing_over_partial(self): |
| | | from pyramid.exceptions import ConfigurationError |
| | | tweens = self._makeOne() |
| | | add = tweens.add_implicit |
| | | add('dbt', 'dbt_factory') |
| | | add('auth', 'auth_factory', under='browserid') |
| | | add('retry', 'retry_factory', over='txnmgr', under='exceptionview') |
| | | add('browserid', 'browserid_factory') |
| | | self.assertRaises(ConfigurationError, tweens.implicit) |
| | | |
| | | def test_implicit_ordering_missing_under_partial(self): |
| | | from pyramid.exceptions import ConfigurationError |
| | | tweens = self._makeOne() |
| | | add = tweens.add_implicit |
| | | add('dbt', 'dbt_factory') |
| | | add('auth', 'auth_factory', under='txnmgr') |
| | | add('retry', 'retry_factory', over='dbt', under='exceptionview') |
| | | add('browserid', 'browserid_factory') |
| | | self.assertRaises(ConfigurationError, tweens.implicit) |
| | | |
| | | def test_implicit_ordering_missing_over_and_under_partials(self): |
| | | from pyramid.exceptions import ConfigurationError |
| | | tweens = self._makeOne() |
| | | add = tweens.add_implicit |
| | | add('dbt', 'dbt_factory') |
| | | add('auth', 'auth_factory', under='browserid') |
| | | add('retry', 'retry_factory', over='foo', under='txnmgr') |
| | | add('browserid', 'browserid_factory') |
| | | self.assertRaises(ConfigurationError, tweens.implicit) |
| | | |
| | | def test_implicit_ordering_missing_over_partial_with_fallback(self): |
| | | from pyramid.tweens import MAIN |
| | | tweens = self._makeOne() |
| | | add = tweens.add_implicit |
| | | add('exceptionview', 'excview_factory', over=MAIN) |
| | | add('auth', 'auth_factory', under='browserid') |
| | | add('retry', 'retry_factory', over='txnmgr', under='exceptionview') |
| | | add('retry', 'retry_factory', over=('txnmgr',MAIN), |
| | | under='exceptionview') |
| | | add('browserid', 'browserid_factory') |
| | | add('dbt', 'dbt_factory') |
| | | self.assertEqual(tweens.implicit(), |
| | |
| | | ('retry', 'retry_factory'), |
| | | ]) |
| | | |
| | | def test_implicit_ordering_missing_partial2(self): |
| | | tweens = self._makeOne() |
| | | add = tweens.add_implicit |
| | | add('dbt', 'dbt_factory') |
| | | add('auth', 'auth_factory', under='browserid') |
| | | add('retry', 'retry_factory', over='txnmgr', under='exceptionview') |
| | | add('browserid', 'browserid_factory') |
| | | self.assertEqual(tweens.implicit(), |
| | | [ |
| | | ('retry', 'retry_factory'), |
| | | ('browserid', 'browserid_factory'), |
| | | ('auth', 'auth_factory'), |
| | | ('dbt', 'dbt_factory'), |
| | | ]) |
| | | |
| | | def test_implicit_ordering_missing_partial3(self): |
| | | def test_implicit_ordering_missing_under_partial_with_fallback(self): |
| | | from pyramid.tweens import MAIN |
| | | tweens = self._makeOne() |
| | | add = tweens.add_implicit |
| | | add('exceptionview', 'excview_factory', over=MAIN) |
| | | add('retry', 'retry_factory', over='txnmgr', under='exceptionview') |
| | | add('auth', 'auth_factory', under=('txnmgr','browserid')) |
| | | add('retry', 'retry_factory', under='exceptionview') |
| | | add('browserid', 'browserid_factory') |
| | | add('dbt', 'dbt_factory') |
| | | self.assertEqual(tweens.implicit(), |
| | | [ |
| | | ('dbt', 'dbt_factory'), |
| | | ('browserid', 'browserid_factory'), |
| | | ('auth', 'auth_factory'), |
| | | ('exceptionview', 'excview_factory'), |
| | | ('retry', 'retry_factory'), |
| | | ]) |
| | |
| | | tweens = self._makeOne() |
| | | add = tweens.add_implicit |
| | | add('exceptionview', 'excview_factory', alias='e', over=MAIN) |
| | | add('retry', 'retry_factory', over='txnmgr', under='e') |
| | | add('retry', 'retry_factory', over=('txnmgr',MAIN), under='e') |
| | | add('browserid', 'browserid_factory') |
| | | self.assertEqual(tweens.implicit(), |
| | | [ |
| | |
| | | ('retry', 'retry_factory'), |
| | | ]) |
| | | |
| | | def test_implicit_ordering_with_partial_fallbacks(self): |
| | | from pyramid.tweens import MAIN |
| | | tweens = self._makeOne() |
| | | add = tweens.add_implicit |
| | | add('exceptionview', 'excview_factory', alias='e', over=('b', MAIN)) |
| | | add('retry', 'retry_factory', under='e') |
| | | add('browserid', 'browserid_factory', over=('txnmgr', 'e')) |
| | | self.assertEqual(tweens.implicit(), |
| | | [ |
| | | ('browserid', 'browserid_factory'), |
| | | ('exceptionview', 'excview_factory'), |
| | | ('retry', 'retry_factory'), |
| | | ]) |
| | | |
| | | def test_implicit_ordering_with_multiple_matching_fallbacks(self): |
| | | from pyramid.tweens import MAIN |
| | | tweens = self._makeOne() |
| | | add = tweens.add_implicit |
| | | add('exceptionview', 'excview_factory', alias='e', over=MAIN) |
| | | add('retry', 'retry_factory', under='e') |
| | | add('browserid', 'browserid_factory', over=('retry', 'e')) |
| | | self.assertEqual(tweens.implicit(), |
| | | [ |
| | | ('browserid', 'browserid_factory'), |
| | | ('exceptionview', 'excview_factory'), |
| | | ('retry', 'retry_factory'), |
| | | ]) |
| | | |
| | | def test_implicit_ordering_with_missing_fallbacks(self): |
| | | from pyramid.exceptions import ConfigurationError |
| | | from pyramid.tweens import MAIN |
| | | tweens = self._makeOne() |
| | | add = tweens.add_implicit |
| | | add('exceptionview', 'excview_factory', alias='e', over=MAIN) |
| | | add('retry', 'retry_factory', under='e') |
| | | add('browserid', 'browserid_factory', over=('txnmgr', 'auth')) |
| | | self.assertRaises(ConfigurationError, tweens.implicit) |
| | | |
| | | def test_implicit_ordering_conflict_direct(self): |
| | | from pyramid.tweens import CyclicDependencyError |
| | | tweens = self._makeOne() |