Skip to content

Commit

Permalink
schemas: better serialization and error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Pamfilos Fokianos <[email protected]>
  • Loading branch information
pamfilos committed Mar 7, 2022
1 parent 3a0fb39 commit 8398a27
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cap/modules/schemas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def get_all_versions(cls, name):
.filter_by(name=name) \
.order_by(cls.major.desc(),
cls.minor.desc(),
cls.patch.desc())
cls.patch.desc()).all()
if schemas:
return schemas
else:
Expand Down
9 changes: 3 additions & 6 deletions cap/modules/schemas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@ def get_all_versions(name=None):
if name:
try:
schemas = Schema.get_all_versions(name)
latest = schemas.first()
except JSONSchemaNotFound:
latest = schemas[0]
except (JSONSchemaNotFound, IndexError):
abort(404)
serialized_versions = [
link_serializer.dump(schema).data
for schema in schemas]
response = {
'versions': serialized_versions,
'versions': link_serializer.dump(schemas, many=True).data,
'latest': link_serializer.dump(latest).data
}
return jsonify(response)
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/test_schemas_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ def test_get_all_version_of_schema(
]
}

resp = client.get(
'/jsonschemas/wrong_schema/versions/', headers=auth_headers_for_user(cms_user))

assert resp.status_code == 404


def test_get_only_latest_version_of_schemas(
client, db, users, auth_headers_for_user):
Expand Down

0 comments on commit 8398a27

Please sign in to comment.