Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_services(self):
self.assertEqual([], get_services())
foobar = Service("Foobar", "/foobar")
self.assertIn(foobar, get_services())
barbaz = Service("Barbaz", "/barbaz")
self.assertIn(barbaz, get_services())
self.assertEqual([barbaz, ], get_services(exclude=['Foobar', ]))
self.assertEqual([foobar, ], get_services(names=['Foobar', ]))
self.assertEqual([foobar, barbaz],
get_services(names=['Foobar', 'Barbaz']))
def setUp(self):
super(OpenAPITest, self).setUp()
self.request = mock.MagicMock()
self.request.registry.settings = self.get_app_settings()
self.generator = OpenAPI(get_services(), self.request)
self.api_doc = self.generator.generate()
def test_get_services(self):
self.assertEqual([], get_services())
foobar = Service("Foobar", "/foobar")
self.assertIn(foobar, get_services())
barbaz = Service("Barbaz", "/barbaz")
self.assertIn(barbaz, get_services())
self.assertEqual([barbaz, ], get_services(exclude=['Foobar', ]))
self.assertEqual([foobar, ], get_services(names=['Foobar', ]))
self.assertEqual([foobar, barbaz],
get_services(names=['Foobar', 'Barbaz']))
def setUp(self):
super(OpenAPITest, self).setUp()
self.request = mock.MagicMock()
self.request.registry.settings = self.get_app_settings()
self.generator = OpenAPI(get_services(), self.request)
self.api_doc = self.generator.generate()
def test_get_services(self):
self.assertEqual([], get_services())
foobar = Service("Foobar", "/foobar")
self.assertIn(foobar, get_services())
barbaz = Service("Barbaz", "/barbaz")
self.assertIn(barbaz, get_services())
self.assertEqual([barbaz, ], get_services(exclude=['Foobar', ]))
self.assertEqual([foobar, ], get_services(names=['Foobar', ]))
self.assertEqual([foobar, barbaz],
get_services(names=['Foobar', 'Barbaz']))
def test_get_services(self):
self.assertEqual([], get_services())
foobar = Service("Foobar", "/foobar")
self.assertIn(foobar, get_services())
barbaz = Service("Barbaz", "/barbaz")
self.assertIn(barbaz, get_services())
self.assertEqual([barbaz, ], get_services(exclude=['Foobar', ]))
self.assertEqual([foobar, ], get_services(names=['Foobar', ]))
self.assertEqual([foobar, barbaz],
get_services(names=['Foobar', 'Barbaz']))
class User(object):
def __init__(self, request, context=None):
self.request = request
self.context = context
def collection_get(self):
return {'users': [1, 2, 3]}
@view(
renderer='json',
content_type='application/json',
schema=RequestSchema())
def collection_post(self):
return {'test': 'yeah'}
services = get_services()
ret = _generate_swagger(services)
self.assertEqual(
sorted(ret["paths"].keys()), [
'/users',
'/users/{id}',
])
self.assertEqual(
sorted(ret["definitions"]['Body']["required"]), ['bar', 'foo'])
def open_api_json_view(request):
"""
:param request:
:return:
Generates JSON representation of Swagger spec
"""
doc = cornice_swagger.CorniceSwagger(
cornice.service.get_services(), pyramid_registry=request.registry)
kwargs = request.registry.settings['cornice_swagger.spec_kwargs']
my_spec = doc.generate(**kwargs)
return my_spec
# import the modules, which will populate the SERVICES variable.
for module in self.options.get('modules', []):
if module in MODULES:
reload(MODULES[module])
else:
MODULES[module] = import_module(module)
names = self.options.get('services', [])
service = self.options.get('service')
if service is not None:
names.append(service)
# filter the services according to the options we got
services = get_services(names=names or None,
exclude=self.options.get('exclude'))
return [self._render_service(s) for s in services]
def openapi_view(request):
# Only build json once
try:
return openapi_view.__json__
except AttributeError:
openapi_view.__json__ = OpenAPI(get_services(), request).generate()
return openapi_view.__json__