aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-11-16 18:52:18 +0100
committerWojtek Kosior <koszko@koszko.org>2021-11-16 18:57:15 +0100
commit30d5ada11fc5ffaa0b19f8730631f4d001696d61 (patch)
treebdbb1c8404300ead3ae1ab4a10df8ac06f847f44 /src
parent9bbc08a2c156be4e5c960e470a85b3d98570d94b (diff)
downloadhaketilo-hydrilla-30d5ada11fc5ffaa0b19f8730631f4d001696d61.tar.gz
haketilo-hydrilla-30d5ada11fc5ffaa0b19f8730631f4d001696d61.zip
add license fetching
Diffstat (limited to 'src')
-rw-r--r--src/pydrilla/pydrilla.py29
-rw-r--r--src/test/test_pydrilla.py13
2 files changed, 31 insertions, 11 deletions
diff --git a/src/pydrilla/pydrilla.py b/src/pydrilla/pydrilla.py
index 2e91b89..3e5edc8 100644
--- a/src/pydrilla/pydrilla.py
+++ b/src/pydrilla/pydrilla.py
@@ -661,18 +661,19 @@ def index():
def get_item(identifier, item_type):
ver = request.args.get('ver')
+
if ver == 'all':
- definitions = content().get_item_all_versions(item_type, identifier)
- return json.dumps(definitions)
- if ver is not None:
- try:
- ver = normalize_version(parse_version(ver))
- except:
- abort(400)
+ definition = content().get_item_all_versions(item_type, identifier)
+ else:
+ if ver is not None:
+ try:
+ ver = normalize_version(parse_version(ver))
+ except:
+ abort(400)
- definition = content().find_item(item_type, identifier, ver)
- if definition is None:
- abort(404)
+ definition = content().find_item(item_type, identifier, ver)
+ if definition is None:
+ abort(404)
return json.dumps(definition)
@@ -681,3 +682,11 @@ for item_type in ['mapping', 'resource']:
return get_item(identifier, item_type)
bp.add_url_rule(f'/{item_type}s/<string:identifier>', item_type, _get_item)
+
+@bp.route('/licenses/<string:identifier>')
+def get_license(identifier):
+ definition = content().licenses.get(identifier)
+ if definition is None:
+ abort(404)
+
+ return json.dumps(definition)
diff --git a/src/test/test_pydrilla.py b/src/test/test_pydrilla.py
index 9e87704..89b499f 100644
--- a/src/test/test_pydrilla.py
+++ b/src/test/test_pydrilla.py
@@ -61,15 +61,26 @@ def test_api_basic(client):
response = client.get(f'/{item_type}s/helloapple?ver=2021.11.10.999')
assert response.status_code == 404
- response = client.get(f'/{item_type}s/helloapple?ver=random_input')
+ response = client.get(f'/{item_type}s/helloapple?ver=random_bad_input')
assert response.status_code == 400
+ response = client.get(f'/{item_type}s/random-bad-identifier')
+ assert response.status_code == 404
+
response = client.get(f'/{item_type}s/helloapple?ver=all')
definitions = json.loads(response.data.decode())
assert type(definitions) is list
assert all([d['type'] == item_type for d in definitions])
assert any([d['version'] == [2021, 11, 10] for d in definitions])
+ response = client.get('/licenses/CC0-1.0')
+ definition = json.loads(response.data.decode())
+ assert definition['long_name'] == 'Creative Commons Zero v1.0 Universal'
+ assert definition['source_name'] == 'hello'
+
+ response = client.get('/licenses/random-bad-identifier')
+ assert response.status_code == 404
+
def test_normalize_version():
assert pydrilla.normalize_version([4, 5, 3, 0, 0]) == [4, 5, 3]
assert pydrilla.normalize_version([1, 0, 5, 0]) == [1, 0, 5]