diff --git a/requirements.txt b/requirements.txt index 1ac5fd2b..3b8f6b5c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,11 @@ -fastapi>=0.66 -aiofiles -uvicorn -numpy -python-ags4 -python-multipart -colorlog -shortuuid -jinja2 +aiofiles==0.7.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 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..e7ebaa02 --- /dev/null +++ b/test/integration/test_api.py @@ -0,0 +1,45 @@ +"""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.""" + response = client.get('/openapi.json') + assert response.status_code == 200 + 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)