_ROUTES_TESTED = {}
def tests_routes(*args):
"""
`@tests_routes` is a decorator
when writing/editing a test, declare what routes the test covers, like such:
@tests_routes(("foo", "bar"))
def test_foo_bar(self):
...
this will populate a global variable `_ROUTES_TESTED` with the name of the
tested routes.
invoking the Audit test:
python -m unittest tests.FunctionalTests_AuditRoutes
will ensure all routes in Pyramid have test coverage
"""
_routes = args[0]
if isinstance(_routes, (list, tuple)):
for _r in _routes:
_ROUTES_TESTED[_r] = True
else:
_ROUTES_TESTED[_routes] = True
def _decorator(_function):
def _wrapper(*args, **kwargs):
_function(*args, **kwargs)
return _wrapper
return _decorator
class FunctionalTests_AuditRoutes(AppTest):
"""
python -m unittest tests.FunctionalTests_AuditRoutes
"""
def test_audit(self):
pyramid_route_names = [i.name for i in self.testapp.app.routes_mapper.routelist]
names_missing = [r for r in pyramid_route_names if r not in _ROUTES_TESTED.keys()]
if names_missing:
raise ValueError("no coverage for %s routes: %s" % (len(names_missing), names_missing))