/usr/lib/python2.7/dist-packages/pyramid/tests/test_config/test_tweens.py is in python-pyramid 1.4.5+dfsg-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | import unittest
from pyramid.tests.test_config import dummy_tween_factory
from pyramid.tests.test_config import dummy_tween_factory2
from pyramid.exceptions import ConfigurationConflictError
class TestTweensConfiguratorMixin(unittest.TestCase):
def _makeOne(self, *arg, **kw):
from pyramid.config import Configurator
config = Configurator(*arg, **kw)
return config
def test_add_tweens_names_distinct(self):
from pyramid.interfaces import ITweens
from pyramid.tweens import excview_tween_factory
def factory1(handler, registry): return handler
def factory2(handler, registry): return handler
config = self._makeOne()
config.add_tween(
'pyramid.tests.test_config.dummy_tween_factory')
config.add_tween(
'pyramid.tests.test_config.dummy_tween_factory2')
config.commit()
tweens = config.registry.queryUtility(ITweens)
implicit = tweens.implicit()
self.assertEqual(
implicit,
[
('pyramid.tests.test_config.dummy_tween_factory2',
dummy_tween_factory2),
('pyramid.tests.test_config.dummy_tween_factory',
dummy_tween_factory),
('pyramid.tweens.excview_tween_factory',
excview_tween_factory),
]
)
def test_add_tweens_names_with_underover(self):
from pyramid.interfaces import ITweens
from pyramid.tweens import excview_tween_factory
from pyramid.tweens import MAIN
config = self._makeOne()
config.add_tween(
'pyramid.tests.test_config.dummy_tween_factory',
over=MAIN)
config.add_tween(
'pyramid.tests.test_config.dummy_tween_factory2',
over=MAIN,
under='pyramid.tests.test_config.dummy_tween_factory')
config.commit()
tweens = config.registry.queryUtility(ITweens)
implicit = tweens.implicit()
self.assertEqual(
implicit,
[
('pyramid.tweens.excview_tween_factory', excview_tween_factory),
('pyramid.tests.test_config.dummy_tween_factory',
dummy_tween_factory),
('pyramid.tests.test_config.dummy_tween_factory2',
dummy_tween_factory2),
])
def test_add_tweens_names_with_under_nonstringoriter(self):
from pyramid.exceptions import ConfigurationError
config = self._makeOne()
self.assertRaises(
ConfigurationError, config.add_tween,
'pyramid.tests.test_config.dummy_tween_factory',
under=False)
def test_add_tweens_names_with_over_nonstringoriter(self):
from pyramid.exceptions import ConfigurationError
config = self._makeOne()
self.assertRaises(
ConfigurationError, config.add_tween,
'pyramid.tests.test_config.dummy_tween_factory',
over=False)
def test_add_tween_dottedname(self):
from pyramid.interfaces import ITweens
from pyramid.tweens import excview_tween_factory
config = self._makeOne()
config.add_tween('pyramid.tests.test_config.dummy_tween_factory')
config.commit()
tweens = config.registry.queryUtility(ITweens)
self.assertEqual(
tweens.implicit(),
[
('pyramid.tests.test_config.dummy_tween_factory',
dummy_tween_factory),
('pyramid.tweens.excview_tween_factory',
excview_tween_factory),
])
def test_add_tween_instance(self):
from pyramid.exceptions import ConfigurationError
class ATween(object): pass
atween = ATween()
config = self._makeOne()
self.assertRaises(ConfigurationError, config.add_tween, atween)
def test_add_tween_unsuitable(self):
from pyramid.exceptions import ConfigurationError
import pyramid.tests.test_config
config = self._makeOne()
self.assertRaises(ConfigurationError, config.add_tween,
pyramid.tests.test_config)
def test_add_tween_name_ingress(self):
from pyramid.exceptions import ConfigurationError
from pyramid.tweens import INGRESS
config = self._makeOne()
self.assertRaises(ConfigurationError, config.add_tween, INGRESS)
def test_add_tween_name_main(self):
from pyramid.exceptions import ConfigurationError
from pyramid.tweens import MAIN
config = self._makeOne()
self.assertRaises(ConfigurationError, config.add_tween, MAIN)
def test_add_tweens_conflict(self):
config = self._makeOne()
config.add_tween('pyramid.tests.test_config.dummy_tween_factory')
config.add_tween('pyramid.tests.test_config.dummy_tween_factory')
self.assertRaises(ConfigurationConflictError, config.commit)
def test_add_tween_over_ingress(self):
from pyramid.exceptions import ConfigurationError
from pyramid.tweens import INGRESS
config = self._makeOne()
self.assertRaises(
ConfigurationError,
config.add_tween,
'pyramid.tests.test_config.dummy_tween_factory',
over=INGRESS)
def test_add_tween_over_ingress_iterable(self):
from pyramid.exceptions import ConfigurationError
from pyramid.tweens import INGRESS
config = self._makeOne()
self.assertRaises(
ConfigurationError,
config.add_tween,
'pyramid.tests.test_config.dummy_tween_factory',
over=('a', INGRESS))
def test_add_tween_under_main(self):
from pyramid.exceptions import ConfigurationError
from pyramid.tweens import MAIN
config = self._makeOne()
self.assertRaises(
ConfigurationError,
config.add_tween,
'pyramid.tests.test_config.dummy_tween_factory',
under=MAIN)
def test_add_tween_under_main_iterable(self):
from pyramid.exceptions import ConfigurationError
from pyramid.tweens import MAIN
config = self._makeOne()
self.assertRaises(
ConfigurationError,
config.add_tween,
'pyramid.tests.test_config.dummy_tween_factory',
under=('a', MAIN))
class TestTweens(unittest.TestCase):
def _makeOne(self):
from pyramid.config.tweens import Tweens
return Tweens()
def test_add_explicit(self):
tweens = self._makeOne()
tweens.add_explicit('name', 'factory')
self.assertEqual(tweens.explicit, [('name', 'factory')])
tweens.add_explicit('name2', 'factory2')
self.assertEqual(tweens.explicit, [('name', 'factory'),
('name2', 'factory2')])
def test_add_implicit(self):
tweens = self._makeOne()
tweens.add_implicit('name', 'factory')
tweens.add_implicit('name2', 'factory2')
self.assertEqual(tweens.sorter.sorted(),
[('name2', 'factory2'),
('name', 'factory')])
def test___call___explicit(self):
tweens = self._makeOne()
def factory1(handler, registry):
return handler
def factory2(handler, registry):
return '123'
tweens.explicit = [('name', factory1), ('name', factory2)]
self.assertEqual(tweens(None, None), '123')
def test___call___implicit(self):
tweens = self._makeOne()
def factory1(handler, registry):
return handler
def factory2(handler, registry):
return '123'
tweens.add_implicit('name2', factory2)
tweens.add_implicit('name1', factory1)
self.assertEqual(tweens(None, None), '123')
def test_implicit_ordering_1(self):
tweens = self._makeOne()
tweens.add_implicit('name1', 'factory1')
tweens.add_implicit('name2', 'factory2')
self.assertEqual(tweens.implicit(),
[
('name2', 'factory2'),
('name1', 'factory1'),
])
def test_implicit_ordering_2(self):
from pyramid.tweens import MAIN
tweens = self._makeOne()
tweens.add_implicit('name1', 'factory1')
tweens.add_implicit('name2', 'factory2', over=MAIN)
self.assertEqual(tweens.implicit(),
[
('name1', 'factory1'),
('name2', 'factory2'),
])
def test_implicit_ordering_3(self):
from pyramid.tweens import MAIN
tweens = self._makeOne()
add = tweens.add_implicit
add('auth', 'auth_factory', under='browserid')
add('dbt', 'dbt_factory')
add('retry', 'retry_factory', over='txnmgr', under='exceptionview')
add('browserid', 'browserid_factory')
add('txnmgr', 'txnmgr_factory', under='exceptionview')
add('exceptionview', 'excview_factory', over=MAIN)
self.assertEqual(tweens.implicit(),
[
('browserid', 'browserid_factory'),
('auth', 'auth_factory'),
('dbt', 'dbt_factory'),
('exceptionview', 'excview_factory'),
('retry', 'retry_factory'),
('txnmgr', 'txnmgr_factory'),
])
def test_implicit_ordering_4(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('browserid', 'browserid_factory')
add('txnmgr', 'txnmgr_factory', under='exceptionview')
add('dbt', 'dbt_factory')
self.assertEqual(tweens.implicit(),
[
('dbt', 'dbt_factory'),
('browserid', 'browserid_factory'),
('auth', 'auth_factory'),
('exceptionview', 'excview_factory'),
('retry', 'retry_factory'),
('txnmgr', 'txnmgr_factory'),
])
def test_implicit_ordering_5(self):
from pyramid.tweens import MAIN, INGRESS
tweens = self._makeOne()
add = tweens.add_implicit
add('exceptionview', 'excview_factory', over=MAIN)
add('auth', 'auth_factory', under=INGRESS)
add('retry', 'retry_factory', over='txnmgr', under='exceptionview')
add('browserid', 'browserid_factory', under=INGRESS)
add('txnmgr', 'txnmgr_factory', under='exceptionview', over=MAIN)
add('dbt', 'dbt_factory')
self.assertEqual(tweens.implicit(),
[
('dbt', 'dbt_factory'),
('browserid', 'browserid_factory'),
('auth', 'auth_factory'),
('exceptionview', 'excview_factory'),
('retry', 'retry_factory'),
('txnmgr', 'txnmgr_factory'),
])
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',MAIN),
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'),
])
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('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'),
])
def test_implicit_ordering_with_partial_fallbacks(self):
from pyramid.tweens import MAIN
tweens = self._makeOne()
add = tweens.add_implicit
add('exceptionview', 'excview_factory', over=('wontbethere', MAIN))
add('retry', 'retry_factory', under='exceptionview')
add('browserid', 'browserid_factory', over=('wont2', 'exceptionview'))
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', over=MAIN)
add('retry', 'retry_factory', under='exceptionview')
add('browserid', 'browserid_factory', over=('retry', 'exceptionview'))
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', over=MAIN)
add('retry', 'retry_factory', under='exceptionview')
add('browserid', 'browserid_factory', over=('txnmgr', 'auth'))
self.assertRaises(ConfigurationError, tweens.implicit)
def test_implicit_ordering_conflict_direct(self):
from pyramid.exceptions import CyclicDependencyError
tweens = self._makeOne()
add = tweens.add_implicit
add('browserid', 'browserid_factory')
add('auth', 'auth_factory', over='browserid', under='browserid')
self.assertRaises(CyclicDependencyError, tweens.implicit)
def test_implicit_ordering_conflict_indirect(self):
from pyramid.exceptions import CyclicDependencyError
tweens = self._makeOne()
add = tweens.add_implicit
add('browserid', 'browserid_factory')
add('auth', 'auth_factory', over='browserid')
add('dbt', 'dbt_factory', under='browserid', over='auth')
self.assertRaises(CyclicDependencyError, tweens.implicit)
|