Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update requirements and deprecated code #122

Merged
merged 5 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,21 @@ class ResponseType(StrEnum):
...,
title="BGS LOCA ID",
description="BGS LOCA ID",
example="20190430093402523419",
examples=["20190430093402523419"],
)

ags_export_query = Query(
...,
title="BGS LOCA ID",
description="A single ID or multiple IDs separated by semicolons",
example="20190430093402523419",
examples=["20190430093402523419"],
)

polygon_query = Query(
...,
title="POLYGON",
description="A polygon expressed in Well Known Text",
example="POLYGON((-4.5 56,-4 56,-4 55.5,-4.5 55.5,-4.5 56))",
examples=["POLYGON((-4.5 56,-4 56,-4 55.5,-4.5 55.5,-4.5 56))"],
)

count_only_query = Query(
Expand Down
42 changes: 21 additions & 21 deletions app/schemas.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from typing import Dict, List, Union

from pydantic import BaseModel, Field, validator
from pydantic import BaseModel, Field, field_validator

from app.bgs_rules import BGS_RULES

Expand All @@ -25,45 +25,45 @@


class LineError(BaseModel):
line: Union[int, str] = Field(..., example="5")
group: str = Field(..., example="TRAN")
desc: str = Field(..., example="Blah blah")
line: Union[int, str] = Field(..., examples=["5"])
group: str = Field(..., examples=["TRAN"])
desc: str = Field(..., examples=["Blah blah"])

@validator('line')
@field_validator('line')
def line_if_string_must_be_hyphen(cls, line):
if type(line) is str:
assert line in ['-', ''], f"Unknown non-integer line number: '{line}'"
return line


class Validation(BaseModel):
filename: str = Field(..., example="example.ags")
filesize: int = Field(None, example="1024")
checkers: List[str] = Field(None, example=["python_ags4 v0.4.1"])
dictionary: str = Field(None, example="Standard_dictionary_v4_1_1.ags")
time: datetime = Field(None, example="2021-08-18 09:23:29")
message: str = Field(None, example="7 error(s) found in file!")
errors: Dict[str, List[LineError]] = Field(..., example="Rule 1a")
valid: bool = Field(..., example='false')
filename: str = Field(..., examples=["example.ags"])
filesize: int = Field(None, examples=["1024"])
checkers: List[str] = Field(None, examples=["python_ags4 v0.4.1"])
dictionary: str = Field(None, examples=["Standard_dictionary_v4_1_1.ags"])
time: datetime = Field(None, examples=["2021-08-18 09:23:29"])
message: str = Field(None, examples=["7 error(s) found in file!"])
errors: Dict[str, List[LineError]] = Field(..., examples=["Rule 1a"])
valid: bool = Field(..., examples=['false'])
additional_metadata: dict = Field(...)

@validator('errors')
@field_validator('errors')
def errors_keys_must_be_known_rules(cls, errors):
for key in errors.keys():
assert key in VALID_KEYS, f"Unknown rule: '{key}'"
return errors


class Error(BaseModel):
error: str = Field(..., example="error")
propName: str = Field(None, example="error")
desc: str = Field(..., example="Error message")
error: str = Field(..., examples=["error"])
propName: str = Field(None, examples=["error"])
desc: str = Field(..., examples=["Error message"])


class MinimalResponse(BaseModel):
msg: str = Field(..., example="Example response")
type: str = Field(..., example="success")
self: str = Field(..., example="http://example.com/apis/query")
msg: str = Field(..., examples=["Example response"])
type: str = Field(..., examples=["success"])
self: str = Field(..., examples=["http://example.com/apis/query"])


class ErrorResponse(MinimalResponse):
Expand All @@ -75,4 +75,4 @@ class ValidationResponse(MinimalResponse):


class BoreholeCountResponse(MinimalResponse):
count: int = Field(..., example=4)
count: int = Field(..., examples=[4])
30 changes: 15 additions & 15 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
aiofiles==23.1.0
numpy==1.24.2
python-ags4==0.4.1
python-multipart==0.0.5
colorlog==6.7.0
shortuuid==1.0.11
Jinja2==3.1.2
Fiona==1.9.1
Shapely==2.0.1
pyproj==3.4.1
geopandas==0.12.2
requests==2.28.2
aiofiles<24
numpy<2
python-ags4<1
python-multipart<1
colorlog<7
shortuuid<2
Jinja2<4
Fiona<2
Shapely<3
pyproj<4
geopandas<1
requests<3
# These libraries are already in FastAPI container but need updated
fastapi==0.92.0
uvicorn==0.20.0
h11==0.14.0
fastapi<1
uvicorn<1
h11<1
17 changes: 8 additions & 9 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
ipython==8.10.0
ipdb==0.13.11
pytest==7.2.1
flake8==6.0.0
requests==2.28.2
httpx==0.23.3
pytest-asyncio==0.20.3
requests-toolbelt==0.10.1
freezegun==1.2.2
ipython
ipdb
pytest
flake8
httpx
pytest-asyncio
requests-toolbelt
freezegun
24 changes: 12 additions & 12 deletions test/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def test_validate_json(async_client, filename, expected):
response = await ac.post(
'/validate/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand Down Expand Up @@ -89,7 +89,7 @@ async def test_validate_many_json(async_client):
response = await ac.post(
'/validate/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand Down Expand Up @@ -120,7 +120,7 @@ async def test_validate_custom_dictionary(async_client, dictionary, expected):
response = await ac.post(
'/validate/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand Down Expand Up @@ -152,7 +152,7 @@ async def test_validate_text(async_client, filename, expected):
response = await ac.post(
'/validate/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand All @@ -179,7 +179,7 @@ async def test_validate_many_text(async_client):
response = await ac.post(
'/validate/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
# Just check that API responds and contains each file name
Expand All @@ -204,7 +204,7 @@ async def test_convert_good_files(async_client, tmp_path):
response = await ac.post(
'/convert/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand Down Expand Up @@ -244,7 +244,7 @@ async def test_convert_sort_tables(async_client, tmp_path, sort_tables):
response = await ac.post(
'/convert/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand Down Expand Up @@ -278,7 +278,7 @@ async def test_convert_bad_files(async_client, tmp_path):
response = await ac.post(
'/convert/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand Down Expand Up @@ -312,7 +312,7 @@ async def test_validate_bgs_json(async_client):
response = await ac.post(
'/validate/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand Down Expand Up @@ -342,7 +342,7 @@ async def test_validate_ags_bgs_json(async_client):
response = await ac.post(
'/validate/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand Down Expand Up @@ -371,7 +371,7 @@ async def test_validate_bgs_text(async_client):
response = await ac.post(
'/validate/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand Down Expand Up @@ -407,7 +407,7 @@ async def test_validate_dictionary_choice(async_client, dictionary, filename, ex
response = await ac.post(
'/validate/',
headers={'Content-Type': mp_encoder.content_type},
data=mp_encoder.to_string())
content=mp_encoder.to_string())

# Assert
assert response.status_code == 200
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests for schemas."""
import pytest
from pydantic.error_wrappers import ValidationError
from pydantic import ValidationError

from app.schemas import Validation
from test.fixtures_json import JSON_RESPONSES, BROKEN_JSON_RESPONSES
Expand Down