From 53b1519f752409eafef0c1a27409f60a84c74ef8 Mon Sep 17 00:00:00 2001 From: John A Stevenson Date: Fri, 20 Aug 2021 16:47:37 +0100 Subject: [PATCH 1/4] Fix versions of all dependencies --- requirements.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1ac5fd2b..eb761579 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,9 @@ -fastapi>=0.66 -aiofiles -uvicorn -numpy -python-ags4 -python-multipart -colorlog -shortuuid -jinja2 +fastapi==0.68.0 +aiofiles==0.7.0 +uvicorn==0.15.0 +numpy==1.21.2 +python-ags4==0.3.6 +python-multipart==0.0.5 +colorlog==5.0.1 +shortuuid==1.0.1 +Jinja2==3.0.1 From 200b7c8ea44527fa6e6d82581eb618ceced9d78d Mon Sep 17 00:00:00 2001 From: John A Stevenson Date: Fri, 20 Aug 2021 16:58:29 +0100 Subject: [PATCH 2/4] Configure integration tests --- requirements_dev.txt | 1 + test/integration/test_api.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/integration/test_api.py diff --git a/requirements_dev.txt b/requirements_dev.txt index 046019cc..54837b1e 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -2,3 +2,4 @@ ipython ipdb pytest flake8 +requests diff --git a/test/integration/test_api.py b/test/integration/test_api.py new file mode 100644 index 00000000..910f6ca7 --- /dev/null +++ b/test/integration/test_api.py @@ -0,0 +1,17 @@ +"""Tests for API responses.""" +from fastapi.testclient import TestClient +import pytest + +from app.main import app + + +def test_openapi_json(client): + """A hello-world type test to confirm testing framework works.""" + response = client.get('/openapi.json') + assert response.status_code == 200 + assert '/validate' in response.text + + +@pytest.fixture(scope="function") +def client(): + return TestClient(app) From a0473b63997ab8a70a1c49ba78e5fc57bef5389f Mon Sep 17 00:00:00 2001 From: John A Stevenson Date: Fri, 20 Aug 2021 17:28:52 +0100 Subject: [PATCH 3/4] Attempt testing validate endpoint (not working) --- test/integration/test_api.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/integration/test_api.py b/test/integration/test_api.py index 910f6ca7..e7ebaa02 100644 --- a/test/integration/test_api.py +++ b/test/integration/test_api.py @@ -1,9 +1,14 @@ """Tests for API responses.""" +from pathlib import Path +import re + from fastapi.testclient import TestClient import pytest from app.main import app +TEST_FILE_DIR = Path(__file__).parent.parent / 'files' + def test_openapi_json(client): """A hello-world type test to confirm testing framework works.""" @@ -12,6 +17,29 @@ def test_openapi_json(client): assert '/validate' in response.text +@pytest.mark.parametrize('filename, expected', [ + ('example1.ags', 'All checks passed!'), + ('nonsense.ags', r'7 error\(s\) found in file!'), + ('empty.ags', r'4 error\(s\) found in file!'), + ('real/A3040_03.ags', r'5733 error\(s\) found in file!'), + ('example1.xlsx', 'ERROR: Only .ags files are accepted as input.'), + ('random_binary.ags', 'ERROR: Unreadable character "á" at position 1 on line: 1\nStarting:'), + ('real/CG014058_F.ags', r'ERROR: Unreadable character "æ" at position 80 on line: 263'), + ('real/Blackburn Southern Bypass.ags', r'93 error\(s\) found in file!'), # this file contains BOM character +]) +def test_validate(client, filename, expected): + # Arrange + filename = TEST_FILE_DIR / filename + + # Act + response = client.post('/validate/?fmt=text', + files={'file': (filename.name, str(filename))}) + + # Assert + assert response.status_code == 200 + assert re.search(expected, response.text) + + @pytest.fixture(scope="function") def client(): return TestClient(app) From 12f231f6c00eb5c15ef67bedaaca3b36b6a7e521 Mon Sep 17 00:00:00 2001 From: John A Stevenson Date: Mon, 23 Aug 2021 10:40:57 +0100 Subject: [PATCH 4/4] Pin H11 library version 0.12.0 (FastAPI dependency) H11 is an HTTP library and FastAPI dependency. An older version is present in the FastAPI Docker container. It contains a bug. This commit ensures that the Docker builds have a working version. --- requirements.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index eb761579..3b8f6b5c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,11 @@ -fastapi==0.68.0 aiofiles==0.7.0 -uvicorn==0.15.0 numpy==1.21.2 python-ags4==0.3.6 python-multipart==0.0.5 colorlog==5.0.1 shortuuid==1.0.1 Jinja2==3.0.1 +# These libraries are already in FastAPI container but need updated +fastapi==0.68.0 +uvicorn==0.15.0 +h11==0.12.0