-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from BritishGeologicalSurvey/docker-problems2
Docker problems2 - fixes issues running in docker
- Loading branch information
Showing
3 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ ipython | |
ipdb | ||
pytest | ||
flake8 | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |