From 10ce5c83b94714b12061b5befe1157ce72ade3c1 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Mon, 15 Nov 2021 18:49:42 +0100 Subject: make test pass --- src/pydrilla/pydrilla.py | 17 ++++++++--------- src/pydrilla/templates/index.html | 2 -- src/test/test_pydrilla.py | 23 ++++++++++++++++++----- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/pydrilla/pydrilla.py b/src/pydrilla/pydrilla.py index 7300198..239267e 100644 --- a/src/pydrilla/pydrilla.py +++ b/src/pydrilla/pydrilla.py @@ -634,10 +634,10 @@ j2env = MyEnvironment(loader=PackageLoader(__package__), autoescape=False) indexpage = j2env.get_template('index.html') @bp.route('/') def index(): - return indexpage.render(content=current_app._pydrilla_resources_map) + return indexpage.render() -for item_type in ['resource', 'mapping']: - def item(identifier): +for item_type in ['mapping', 'resource']: + def item(identifier, item_type=item_type): ver = request.args.get('ver') if ver is not None: try: @@ -645,12 +645,11 @@ for item_type in ['resource', 'mapping']: except: abort(400) - item = current_app._pydrilla_content\ - .find_item(item_type, identifier, ver) - if item is None: + definition = current_app._pydrilla_content\ + .find_item(item_type, identifier, ver) + if definition is None: abort(404) - return json.dumps(item) + return json.dumps(definition) - item.__name__ = item_type + 's' - bp.route(f'/{item_type}s/')(item) + bp.add_url_rule(f'/{item_type}s/', item_type, item) diff --git a/src/pydrilla/templates/index.html b/src/pydrilla/templates/index.html index 71de8ba..5f5b319 100644 --- a/src/pydrilla/templates/index.html +++ b/src/pydrilla/templates/index.html @@ -27,6 +27,4 @@ in a proprietary program, I am not going to enforce this in court. {% block body %} {{ super() }}

{{ _('hydrilla_welcome') }}

-

content

- {{ content }} {% endblock %} diff --git a/src/test/test_pydrilla.py b/src/test/test_pydrilla.py index 5937db9..07c580a 100644 --- a/src/test/test_pydrilla.py +++ b/src/test/test_pydrilla.py @@ -31,23 +31,36 @@ from pathlib import Path from os import mkdir, unlink, environ import json -import pydrilla +from pydrilla import pydrilla, create_app test_dir = Path(__file__).resolve().parent -pydrilla_dir = Path(hydrilla.__file__).resolve().parent -test_config_path = test_dir / 'config.json' +pydrilla_dir = Path(pydrilla.__file__).resolve().parent +test_config_path = pydrilla_dir / 'development_config.json' @pytest.fixture def client(): - app = pydrilla.create_app(test_config_path, flask_config={'TESTING': True}) + app = create_app(test_config_path, flask_config={'TESTING': True}) with app.test_client() as client: yield client -def test_basic(client): +def test_api_basic(client): response = client.get('/') assert b'html' in response.data + for item_type in ['mapping', 'resource']: + response = client.get(f'/{item_type}s/helloapple') + definition = json.loads(response.data.decode()) + assert definition['type'] == item_type + assert definition['source_name'] == 'hello' + assert definition['version'] == [2021, 11, 10] + + response = client.get(f'/{item_type}s/helloapple?ver=2021.11.10.0') + assert definition == json.loads(response.data.decode()) + + response = client.get(f'/{item_type}s/helloapple?ver=2021.11.10.999') + 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] -- cgit v1.2.3 mmitter.scm.in?id=0836af9a3b33813e69ece7075fbc222fdb85bfb3'>etc/committer: Do not recompute changes when there are no definitions....Ricardo Wurmus 2022-05-31etc/committer: Teach it how to commit package removal....Maxim Cournoyer 2022-05-31etc/committer: Prefix (sxml xpath) symbols to avoid name conflict....Maxim Cournoyer 2022-01-23etc: committer: Support plain input lists....Ricardo Wurmus 2021-09-21etc: committer: Amend previous commit if a copyright line was added....Xinglu Chen 2021-08-10etc/committer: Pass command-line arguments to main....Sarah Morgensen 2021-08-10etc/committer: Support custom commit messages....Sarah Morgensen 2021-08-07etc: committer: Support reading G-expressions....Maxime Devos 2021-05-04etc: Break long lines in commit messages....Ricardo Wurmus 2021-04-12etc/committer: Add missing newline....Morgan Smith 2021-04-12etc/committer: Use git plumbing instead of porcelain....Morgan Smith 2021-04-08etc/committer: Disable diff colors....Ricardo Wurmus 2021-04-08etc/committer: Recompute hunks before processing changes....Ricardo Wurmus 2021-04-08etc/committer: Record minimal context for hunks to avoid problems....Ricardo Wurmus 2021-04-08etc/committer: Define delay duration as a variable....Ricardo Wurmus 2021-04-08etc/committer: Handle package additions....Ricardo Wurmus 2020-10-06etc: committer: Use EQUAL? instead of EQ? for differences....Ricardo Wurmus 2020-06-16etc: Add committer script....Ricardo Wurmus