def apimas_context(urlconf_module, spec):
"""
This function (decorator) is used to customize `TestCase` classes based
on the `APIMAS` spec of an application.
More specifically, the given spec is used in order `Django` urls to be
created and then test functions (triggering test case scenarios for
every collection and action) are created and bound to the provided
`TestCase` class.
:param urlconf_module: Path to the module where generated django urls
will be added.
:param spec: `APIMAS` specification.
"""
def wrapper(cls):
setattr(cls, 'spec', spec)
adapter = DjangoRestAdapter()
adapter.construct(spec)
setattr(cls, 'adapter', adapter)
urls = adapter.urls.values()
_add_urlpatterns(urlconf_module, urls)
_add_test_functions(cls, adapter, spec)
return override_settings(ROOT_URLCONF=urlconf_module)(cls)
return wrapper
评论列表
文章目录