add some tests to prove that OpenAPI JSON compilation works

This commit is contained in:
Ryan Petrello 2018-02-02 15:36:08 -05:00
parent 10974159b5
commit 07dfab648c
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777

View File

@ -76,7 +76,7 @@ class TestSwaggerGeneration():
revised_paths = {}
deprecated_paths = JSON.pop('deprecated_paths', [])
for path, node in self.__class__.JSON['paths'].items():
for path, node in JSON['paths'].items():
# change {version} in paths to the actual default API version (e.g., v2)
revised_paths[path.replace(
'{version}',
@ -90,7 +90,34 @@ class TestSwaggerGeneration():
lines = node[method]['description'].splitlines()
node[method]['summary'] = lines.pop(0).strip('#:')
node[method]['description'] = '\n'.join(lines)
self.__class__.JSON['paths'] = revised_paths
JSON['paths'] = revised_paths
# Make some basic assertions about the rendered JSON so we can
# be sure it doesn't break across DRF upgrades and view/serializer
# changes.
assert len(JSON['tags'])
assert JSON['info']['version'] == release
assert len(JSON['paths'])
# The number of API endpoints changes over time, but let's just check
# for a reasonable number here; if this test starts failing, raise/lower the bounds
paths = JSON['paths']
assert 250 < len(paths) < 300
assert paths['/api/'].keys() == ['get']
assert paths['/api/v2/'].keys() == ['get']
assert sorted(
paths['/api/v2/credentials/'].keys()
) == ['get', 'post']
assert sorted(
paths['/api/v2/credentials/{id}/'].keys()
) == ['delete', 'get', 'patch', 'put']
assert paths['/api/v2/settings/'].keys() == ['get']
assert paths['/api/v2/settings/{category_slug}/'].keys() == [
'get', 'put', 'patch', 'delete'
]
# Test deprecated paths
assert paths['/api/v2/jobs/{id}/extra_credentials/']['get']['deprecated'] is True
@classmethod
def teardown_class(cls):