From e8c8b06ff588fecee56bcb350a8cc54098b0924a Mon Sep 17 00:00:00 2001 From: KoalaGeo Date: Wed, 30 Aug 2023 13:53:12 +0100 Subject: [PATCH] Revert "Update requirements and deprecated code" --- app/routes.py | 6 +++--- app/schemas.py | 42 ++++++++++++++++++------------------ requirements.txt | 30 +++++++++++++------------- requirements_dev.txt | 17 ++++++++------- test/integration/test_api.py | 24 ++++++++++----------- test/unit/test_schemas.py | 2 +- 6 files changed, 61 insertions(+), 60 deletions(-) diff --git a/app/routes.py b/app/routes.py index 19aac868..354170a4 100644 --- a/app/routes.py +++ b/app/routes.py @@ -121,21 +121,21 @@ class ResponseType(StrEnum): ..., title="BGS LOCA ID", description="BGS LOCA ID", - examples=["20190430093402523419"], + example="20190430093402523419", ) ags_export_query = Query( ..., title="BGS LOCA ID", description="A single ID or multiple IDs separated by semicolons", - examples=["20190430093402523419"], + example="20190430093402523419", ) polygon_query = Query( ..., title="POLYGON", description="A polygon expressed in Well Known Text", - examples=["POLYGON((-4.5 56,-4 56,-4 55.5,-4.5 55.5,-4.5 56))"], + example="POLYGON((-4.5 56,-4 56,-4 55.5,-4.5 55.5,-4.5 56))", ) count_only_query = Query( diff --git a/app/schemas.py b/app/schemas.py index 475b4eba..0f8c3efa 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -1,7 +1,7 @@ from datetime import datetime from typing import Dict, List, Union -from pydantic import BaseModel, Field, field_validator +from pydantic import BaseModel, Field, validator from app.bgs_rules import BGS_RULES @@ -25,11 +25,11 @@ class LineError(BaseModel): - line: Union[int, str] = Field(..., examples=["5"]) - group: str = Field(..., examples=["TRAN"]) - desc: str = Field(..., examples=["Blah blah"]) + line: Union[int, str] = Field(..., example="5") + group: str = Field(..., example="TRAN") + desc: str = Field(..., example="Blah blah") - @field_validator('line') + @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}'" @@ -37,17 +37,17 @@ def line_if_string_must_be_hyphen(cls, line): class Validation(BaseModel): - 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']) + 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') additional_metadata: dict = Field(...) - @field_validator('errors') + @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}'" @@ -55,15 +55,15 @@ def errors_keys_must_be_known_rules(cls, errors): class Error(BaseModel): - error: str = Field(..., examples=["error"]) - propName: str = Field(None, examples=["error"]) - desc: str = Field(..., examples=["Error message"]) + error: str = Field(..., example="error") + propName: str = Field(None, example="error") + desc: str = Field(..., example="Error message") class MinimalResponse(BaseModel): - msg: str = Field(..., examples=["Example response"]) - type: str = Field(..., examples=["success"]) - self: str = Field(..., examples=["http://example.com/apis/query"]) + msg: str = Field(..., example="Example response") + type: str = Field(..., example="success") + self: str = Field(..., example="http://example.com/apis/query") class ErrorResponse(MinimalResponse): @@ -75,4 +75,4 @@ class ValidationResponse(MinimalResponse): class BoreholeCountResponse(MinimalResponse): - count: int = Field(..., examples=[4]) + count: int = Field(..., example=4) diff --git a/requirements.txt b/requirements.txt index 83ea8cfd..6b00ee99 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,16 +1,16 @@ -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 +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 # These libraries are already in FastAPI container but need updated -fastapi<1 -uvicorn<1 -h11<1 +fastapi==0.92.0 +uvicorn==0.20.0 +h11==0.14.0 diff --git a/requirements_dev.txt b/requirements_dev.txt index 0778509b..d27f7670 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,8 +1,9 @@ -ipython -ipdb -pytest -flake8 -httpx -pytest-asyncio -requests-toolbelt -freezegun +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 diff --git a/test/integration/test_api.py b/test/integration/test_api.py index 2192eaa4..589e0d01 100644 --- a/test/integration/test_api.py +++ b/test/integration/test_api.py @@ -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}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 @@ -89,7 +89,7 @@ async def test_validate_many_json(async_client): response = await ac.post( '/validate/', headers={'Content-Type': mp_encoder.content_type}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 @@ -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}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 @@ -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}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 @@ -179,7 +179,7 @@ async def test_validate_many_text(async_client): response = await ac.post( '/validate/', headers={'Content-Type': mp_encoder.content_type}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert # Just check that API responds and contains each file name @@ -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}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 @@ -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}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 @@ -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}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 @@ -312,7 +312,7 @@ async def test_validate_bgs_json(async_client): response = await ac.post( '/validate/', headers={'Content-Type': mp_encoder.content_type}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 @@ -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}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 @@ -371,7 +371,7 @@ async def test_validate_bgs_text(async_client): response = await ac.post( '/validate/', headers={'Content-Type': mp_encoder.content_type}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 @@ -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}, - content=mp_encoder.to_string()) + data=mp_encoder.to_string()) # Assert assert response.status_code == 200 diff --git a/test/unit/test_schemas.py b/test/unit/test_schemas.py index 835d188d..acee36b5 100644 --- a/test/unit/test_schemas.py +++ b/test/unit/test_schemas.py @@ -1,6 +1,6 @@ """Tests for schemas.""" import pytest -from pydantic import ValidationError +from pydantic.error_wrappers import ValidationError from app.schemas import Validation from test.fixtures_json import JSON_RESPONSES, BROKEN_JSON_RESPONSES