From 93d729db40907aa0a9156f79946089de623b7fd5 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 28 Oct 2024 15:34:41 -0700 Subject: [PATCH] ran linter on all python files --- backend/api/config.py | 7 +++-- backend/api/main.py | 6 ++-- backend/api/models/comined_risk.py | 7 +++-- backend/api/models/landslide_zones.py | 16 +++++++---- backend/api/models/liquefaction_zones.py | 12 +++++--- backend/api/models/neighborhoods.py | 10 +++++-- backend/api/models/seismic_hazard_zones.py | 12 +++++--- backend/api/models/soft_story_properties.py | 20 +++++++++---- backend/api/models/tsunami.py | 10 +++++-- backend/api/routers/combined_risk.py | 3 +- backend/api/routers/polygons.py | 9 +++--- backend/api/routers/reinforced_soft_story.py | 30 ++++++++++---------- backend/api/routers/seismic.py | 3 +- backend/api/routers/soft_story.py | 14 ++++----- backend/api/routers/tsunami.py | 3 +- backend/api/schemas.py | 1 + backend/api/tags.py | 1 + backend/api/tests/test_combined_risks.py | 18 +++++++----- backend/api/tests/test_polygons.py | 29 +++++++++++-------- backend/api/tests/test_seismic.py | 13 +++++---- backend/api/tests/test_soft_story.py | 4 ++- backend/api/tests/test_tsunami.py | 15 ++++++---- backend/database/tests/test_database.py | 22 ++++++++------ 23 files changed, 162 insertions(+), 103 deletions(-) diff --git a/backend/api/config.py b/backend/api/config.py index 14a031e6..b1af9eb6 100644 --- a/backend/api/config.py +++ b/backend/api/config.py @@ -5,7 +5,9 @@ """ Provides the environment variables that are read by the application. """ -class Settings(BaseSettings): + + +class Settings(BaseSettings): postgres_user: str postgres_password: str postgres_db: str @@ -17,7 +19,6 @@ class Settings(BaseSettings): next_public_api_url: str node_env: str - class Config: env_file = ".env.local" env_file_encoding = "utf-8" @@ -29,4 +30,4 @@ def get_settings() -> Settings: return Settings() -settings = get_settings() \ No newline at end of file +settings = get_settings() diff --git a/backend/api/main.py b/backend/api/main.py index f4c8fe0d..29a1c9bf 100644 --- a/backend/api/main.py +++ b/backend/api/main.py @@ -9,16 +9,16 @@ combined risk records. """ # TODO: -# Decide: +# Decide: # - whether old polygons should be kept #53 # - whether old soft story records should be kept #53 # - whether old combined risk records should be kept #53 # - where current and old polygons, soft story records, and # combined risk records should be kept #53 -# Create: +# Create: # - a database to back the exposed arguments #54 # - a new API key for OpenGate -# - fuzzy logic to match addresses +# - fuzzy logic to match addresses # Make: each get method return that of their pydantic annotations from .routers import combined_risk, polygons, soft_story, seismic, tsunami from fastapi import FastAPI diff --git a/backend/api/models/comined_risk.py b/backend/api/models/comined_risk.py index e437d173..19aadac7 100644 --- a/backend/api/models/comined_risk.py +++ b/backend/api/models/comined_risk.py @@ -3,9 +3,10 @@ Base = declarative_base() + class CombinedRisk(Base): - __tablename__ = 'combined_risk' - + __tablename__ = "combined_risk" + id = Column(Integer, primary_key=True, autoincrement=True) address = Column(String(50), nullable=False, unique=True) soft_story_risk = Column(Boolean, nullable=False, default=False) @@ -20,4 +21,4 @@ def __repr__(self): f"seismic_hazard_risk={self.seismic_hazard_risk}, " f"landslide_risk={self.landslide_risk}, " f"liquefaction_risk={self.liquefaction_risk})>" - ) \ No newline at end of file + ) diff --git a/backend/api/models/landslide_zones.py b/backend/api/models/landslide_zones.py index 4b2c35e2..e35d9d4d 100644 --- a/backend/api/models/landslide_zones.py +++ b/backend/api/models/landslide_zones.py @@ -1,4 +1,5 @@ """All data of the Landslide Zones table from SFData.""" + from sqlalchemy import String, Integer from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import Mapped @@ -16,18 +17,23 @@ class LandslideZones(DeclarativeBase): __tablename__ = "landslide_zones" identifier: Mapped[int] = mapped_column(Integerprimary_key=True) - geometry: Mapped[Geometry] = mapped_column(Geometry('MULTIPOLYGON', srid=4326)) + geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326)) gridcode: Mapped[int] = mapped_column(Integer) sum_shape: Mapped[float] = mapped_column(Float) shape_length: Mapped[float] = mapped_column(Float) created_us: Mapped[str] = mapped_column(String) - created_da: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow) + created_da: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=datetime.utcnow + ) last_edited: Mapped[str] = mapped_column(String) - last_edi_1: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow) + last_edi_1: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=datetime.utcnow + ) shape_Le_1: Mapped[float] = mapped_column(Float) shape_area: Mapped[float] = mapped_column(Float) - update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow) + update_timestamp: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=datetime.utcnow + ) def __repr__(self) -> str: return f"" - diff --git a/backend/api/models/liquefaction_zones.py b/backend/api/models/liquefaction_zones.py index 0ca154f0..bf58dc0f 100644 --- a/backend/api/models/liquefaction_zones.py +++ b/backend/api/models/liquefaction_zones.py @@ -1,4 +1,5 @@ """All data of the Liquefaction Zones table from SFData.""" + from sqlalchemy import String from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import Mapped @@ -10,17 +11,20 @@ class LiquefactionZones(DeclarativeBase): """ All data of the Liquefaction Zones table from SFData. - Contains multipolygon geometries defining soil liquefaction zones as High (H) or + Contains multipolygon geometries defining soil liquefaction zones as High (H) or Very High (VH) susceptibility. """ + __tablename__ = "liquefaction_zones" identifier: Mapped[int] = mapped_column(primary_key=True) - geometry: Mapped[Geometry] = mapped_column(Geometry('MULTIPOLYGON', srid=4326)) + geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326)) susceptibility: Mapped[str] = mapped_column(String) shape_length: Mapped[float] = mapped_column(Float) shape_area: Mapped[float] = mapped_column(Float) - update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow) + update_timestamp: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=datetime.utcnow + ) def __repr__(self) -> str: - return f"" \ No newline at end of file + return f"" diff --git a/backend/api/models/neighborhoods.py b/backend/api/models/neighborhoods.py index 851b5f26..f1106c38 100644 --- a/backend/api/models/neighborhoods.py +++ b/backend/api/models/neighborhoods.py @@ -1,4 +1,5 @@ """Neighborhood boundaries in San Francisco""" + from sqlalchemy import String, Integer from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import Mapped @@ -14,12 +15,15 @@ class Neighborhoods(DeclarativeBase): """ Stores neighborhood boundaries as multipolygon geometries. """ + __tablename__ = "neighborhoods" identifier: Mapped[int] = mapped_column(Integer, primary_key=True) neighborhood: Mapped[str] = mapped_column(String(MAPPED_COLUMN_STRING_LENGTH)) - geometry: Mapped[Geometry] = mapped_column(Geometry('MULTIPOLYGON', srid=4326)) - update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utc_now) - + geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326)) + update_timestamp: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=datetime.utc_now + ) + def __repr__(self) -> str: return f"" diff --git a/backend/api/models/seismic_hazard_zones.py b/backend/api/models/seismic_hazard_zones.py index d5fa61d0..0e9b4362 100644 --- a/backend/api/models/seismic_hazard_zones.py +++ b/backend/api/models/seismic_hazard_zones.py @@ -1,4 +1,5 @@ """All data of the Seismic Hazard table from SFData.""" + from sqlalchemy import Integer from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import Mapped @@ -12,11 +13,14 @@ class SeismicHazardZones(DeclarativeBase): All data of the Seismic Hazard table from SFData. Contains multipolygon geometries defining seismic hazard areas. """ + __tablename__ = "seismic_hazard_zones" identifier: Mapped[int] = mapped_column(Integer, primary_key=True) - geometry: Mapped[Geometry] = mapped_column(Geometry('MULTIPOLYGON', srid=4326)) - update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow) - + geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326)) + update_timestamp: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=datetime.utcnow + ) + def __repr__(self) -> str: - return f"" \ No newline at end of file + return f"" diff --git a/backend/api/models/soft_story_properties.py b/backend/api/models/soft_story_properties.py index 173df4fb..17a8f3ca 100644 --- a/backend/api/models/soft_story_properties.py +++ b/backend/api/models/soft_story_properties.py @@ -1,4 +1,5 @@ """All data of the Soft Story table from SFData.""" + from sqlalchemy import String, Integer from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import Mapped @@ -14,9 +15,10 @@ class SoftStoryProperties(DeclarativeBase): """ All data of the Soft Story table from SFData. - Contains point geometries for properties. + Contains point geometries for properties. Used for spatial comparison to determine hazard zone overlaps. """ + __tablename__ = "soft_story_properties" identifier: Mapped[int] = mapped_column(Integer, primary_key=True) @@ -28,10 +30,16 @@ class SoftStoryProperties(DeclarativeBase): tier: Mapped[int] = mapped_column(Integer) status: Mapped[str] = mapped_column(String(MAPPED_COLUMN_STRING_LENGTH)) bos_district: Mapped[int] = mapped_column(Integer) - point: Mapped[Geometry] = mapped_column(Geometry('POINT', srid=4326)) - sfdata_as_of: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow) - sfdata_loaded_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow) - update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow) + point: Mapped[Geometry] = mapped_column(Geometry("POINT", srid=4326)) + sfdata_as_of: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=datetime.utcnow + ) + sfdata_loaded_at: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=datetime.utcnow + ) + update_timestamp: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=datetime.utcnow + ) def __repr__(self) -> str: - return f"" \ No newline at end of file + return f"" diff --git a/backend/api/models/tsunami.py b/backend/api/models/tsunami.py index 40c2278e..a6b21b50 100644 --- a/backend/api/models/tsunami.py +++ b/backend/api/models/tsunami.py @@ -1,4 +1,5 @@ """Tsunami Risk Zone data""" + from sqlalchemy import String, Integer from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import Mapped @@ -14,8 +15,9 @@ class TsunamiZones(DeclarativeBase): """ All data of the Tsunami Hazard table from conservation.ca.gov. """ + __tablename__ = "tsunami_zones" - + identifier: Mapped[int] = mapped_column(Integer, primary_key=True) evacuate: Mapped[str] = mapped_column(String(MAPPED_COLUMN_STRING_LENGTH)) county: Mapped[str] = mapped_column(String(MAPPED_COLUMN_STRING_LENGTH)) @@ -26,8 +28,10 @@ class TsunamiZones(DeclarativeBase): shape_length: Mapped[float] = mapped_column(Float) shape_area: Mapped[float] = mapped_column(Float) # This data is ingested as PolygonZ but should be stored as MultiPolygon - geometry: Mapped[Geometry] = mapped_column(Geometry('MULTIPOLYGON', srid=4326)) - update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow) + geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326)) + update_timestamp: Mapped[datetime] = mapped_column( + DateTime(timezone=True), server_default=datetime.utcnow + ) def __repr__(self) -> str: return f"" diff --git a/backend/api/routers/combined_risk.py b/backend/api/routers/combined_risk.py index e43c6445..42a9fe91 100644 --- a/backend/api/routers/combined_risk.py +++ b/backend/api/routers/combined_risk.py @@ -1,4 +1,5 @@ """Router to CRUD combined risk.""" + from fastapi import APIRouter from ..tags import Tags @@ -41,4 +42,4 @@ async def get_combined_risks(address: str) -> dict: three booleans. """ # TODO: Return a dictionary to avoid validation error - pass \ No newline at end of file + pass diff --git a/backend/api/routers/polygons.py b/backend/api/routers/polygons.py index 40371d8e..932fa5d7 100644 --- a/backend/api/routers/polygons.py +++ b/backend/api/routers/polygons.py @@ -1,17 +1,16 @@ """Router to CRUD polygons.""" + from fastapi import APIRouter from pydantic import BaseModel from ..tags import Tags -router = APIRouter( - prefix="/api/polygons", - tags=[Tags.POLYGONS] -) +router = APIRouter(prefix="/api/polygons", tags=[Tags.POLYGONS]) class Polygon(BaseModel): """GIS data container of vertices defining a polygon.""" + pass @@ -44,4 +43,4 @@ async def get_polygon(id: int, table_name: str) -> Polygon: """ Get this polygon from that table. """ - pass \ No newline at end of file + pass diff --git a/backend/api/routers/reinforced_soft_story.py b/backend/api/routers/reinforced_soft_story.py index 2da12b9d..e33d9434 100644 --- a/backend/api/routers/reinforced_soft_story.py +++ b/backend/api/routers/reinforced_soft_story.py @@ -12,38 +12,38 @@ @router.delete("/{address}") async def delete_reinforced(address: str): """ - Delete the record that the building at an address, having a soft + Delete the record that the building at an address, having a soft story, has been reinforced. - Check a small group of reinforced soft stories and raise an + Check a small group of reinforced soft stories and raise an exception if the building lacks an original soft story. """ pass @router.put("/{address}") -async def put_reinforced(address: str, - soft_story: Annotated[ - bool, Query(alias="soft-story")]): +async def put_reinforced( + address: str, soft_story: Annotated[bool, Query(alias="soft-story")] +): """ - Update whether the building at an address, having a soft story, + Update whether the building at an address, having a soft story, has been reinforced. - Check a small group of reinforced soft stories and raise an + Check a small group of reinforced soft stories and raise an exception if the building lacks an original soft story. """ pass @router.post("/{address}") -async def post_reinforced(address: str, - soft_story: Annotated[ - bool, Query(alias="soft-story")]): +async def post_reinforced( + address: str, soft_story: Annotated[bool, Query(alias="soft-story")] +): """ - Add that the building at an address, having a soft story, has + Add that the building at an address, having a soft story, has been reinforced. - Check a small table of reinforced soft stories and raise an + Check a small table of reinforced soft stories and raise an exception if the building lacks an original soft story. """ pass @@ -52,11 +52,11 @@ async def post_reinforced(address: str, @router.get("/{address}") async def get_reinforced(address: str) -> bool: """ - Return whether the building at an address, having a soft story, + Return whether the building at an address, having a soft story, has been reinforced. - Check a small table of reinforced soft stories and raise an + Check a small table of reinforced soft stories and raise an exception if the building lacks an original soft story. """ # TODO: Change return type to boolean to avoid validation error - pass \ No newline at end of file + pass diff --git a/backend/api/routers/seismic.py b/backend/api/routers/seismic.py index 52bf709b..b38ec112 100644 --- a/backend/api/routers/seismic.py +++ b/backend/api/routers/seismic.py @@ -1,4 +1,5 @@ """Router to get seismic risk and CRUD seismic polygons.""" + from fastapi import APIRouter from ..tags import Tags @@ -16,4 +17,4 @@ async def get_seismic_risk(address: str) -> bool: polygon. """ # TODO: Change return type to boolean to avoid validation error - pass \ No newline at end of file + pass diff --git a/backend/api/routers/soft_story.py b/backend/api/routers/soft_story.py index cc299f63..bbfe070f 100644 --- a/backend/api/routers/soft_story.py +++ b/backend/api/routers/soft_story.py @@ -19,9 +19,9 @@ async def delete_soft_story(address: str): @router.put("/{address}") -async def put_soft_story(address: str, - soft_story: Annotated[ - bool, Query(alias="soft-story")]): +async def put_soft_story( + address: str, soft_story: Annotated[bool, Query(alias="soft-story")] +): """ Update whether the building at an address has a soft story to the database. @@ -30,9 +30,9 @@ async def put_soft_story(address: str, @router.post("/{address}") -async def post_soft_story(address: str, - soft_story: Annotated[ - bool, Query(alias="soft-story")]): +async def post_soft_story( + address: str, soft_story: Annotated[bool, Query(alias="soft-story")] +): """ Add that the building at an address has a soft story to the database. @@ -46,4 +46,4 @@ async def get_soft_story(address: str) -> bool: Return whether the building at an address has a soft story. """ # TODO: Change return type to boolean to avoid validation error - pass \ No newline at end of file + pass diff --git a/backend/api/routers/tsunami.py b/backend/api/routers/tsunami.py index 2dbf95df..0ce41e6c 100644 --- a/backend/api/routers/tsunami.py +++ b/backend/api/routers/tsunami.py @@ -1,4 +1,5 @@ """Router to get tsunami risk and CRUD tsunami polygons.""" + from fastapi import APIRouter from ..tags import Tags @@ -16,4 +17,4 @@ async def get_risk(address: str) -> bool: polygon. """ # TODO: Change return type to boolean to avoid validation error - pass \ No newline at end of file + pass diff --git a/backend/api/schemas.py b/backend/api/schemas.py index 557cfd67..58fb97e3 100644 --- a/backend/api/schemas.py +++ b/backend/api/schemas.py @@ -10,4 +10,5 @@ class Polygon(BaseModel): Complex pydantic object bounding which addresses are at risk of area-based perils and which ones are not. """ + pass diff --git a/backend/api/tags.py b/backend/api/tags.py index f5ea95dd..cbafd7e5 100644 --- a/backend/api/tags.py +++ b/backend/api/tags.py @@ -1,4 +1,5 @@ """Tags for the routers and API.""" + from enum import Enum diff --git a/backend/api/tests/test_combined_risks.py b/backend/api/tests/test_combined_risks.py index 7fa12660..b1a22ff3 100644 --- a/backend/api/tests/test_combined_risks.py +++ b/backend/api/tests/test_combined_risks.py @@ -1,8 +1,10 @@ """ Test the API of combined_risks.py. """ + import pytest from fastapi.testclient import TestClient + # Will the .. be stable? from ..main import app from ..schemas import Polygon @@ -21,18 +23,20 @@ def test_delete_combined_risks(client): def test_put_combined_risks(client): - response = client.put("/api/combined-risks/address", - json={"soft-story": True, "seismic": True, - "tsunami": True}) + response = client.put( + "/api/combined-risks/address", + json={"soft-story": True, "seismic": True, "tsunami": True}, + ) assert response.status_code == 200 # Temporary guaranteed failure until test is written assert False def test_post_combined_risks(client): - response = client.post("/api/combined-risks/address", - json={"soft-story": True, "seismic": True, - "tsunami": True}) + response = client.post( + "/api/combined-risks/address", + json={"soft-story": True, "seismic": True, "tsunami": True}, + ) assert response.status_code == 200 # Temporary guaranteed failure until test is written assert False @@ -42,4 +46,4 @@ def test_get_combined_risks(client): response = client.get("/api/combined-risks/address") assert response.status_code == 200 # Temporary guaranteed failure until test is written - assert False \ No newline at end of file + assert False diff --git a/backend/api/tests/test_polygons.py b/backend/api/tests/test_polygons.py index 50fa299a..a21df0ab 100644 --- a/backend/api/tests/test_polygons.py +++ b/backend/api/tests/test_polygons.py @@ -1,38 +1,43 @@ """ Test the API of polygons.py. """ + import pytest from fastapi.testclient import TestClient from ..schemas import Polygon from ..index import app + @pytest.fixture def client(): return TestClient(app) def test_post_polygon(client): - table_name='seismic' - response = client.put("/api/polygons/?table_name={table_name}", - json=Polygon().model_dump()) + table_name = "seismic" + response = client.put( + "/api/polygons/?table_name={table_name}", json=Polygon().model_dump() + ) assert response.status_code == 200 # Temporary guaranteed failure until test is written assert False def test_put_polygon(client): - polygon_id = 1 - table_name='seismic' - response = client.put("/api/polygons/{polygon_id}?table_name={table_name}", - json=Polygon().model_dump()) + polygon_id = 1 + table_name = "seismic" + response = client.put( + "/api/polygons/{polygon_id}?table_name={table_name}", + json=Polygon().model_dump(), + ) assert response.status_code == 200 # Temporary guaranteed failure until test is written assert False def test_get_polygon(client): - polygon_id = 1 - table_name='seismic' + polygon_id = 1 + table_name = "seismic" response = client.get("/api/polygons/{polygon_id}?table_name={table_name}") assert response.status_code == 200 # Temporary guaranteed failure until test is written @@ -40,9 +45,9 @@ def test_get_polygon(client): def test_delete_polygon(client): - polygon_id = 1 - table_name='seismic' + polygon_id = 1 + table_name = "seismic" response = client.delete("/api/polygons/{polygon_id}?table_name={table_name}") assert response.status_code == 200 # Temporary guaranteed failure until test is written - assert False \ No newline at end of file + assert False diff --git a/backend/api/tests/test_seismic.py b/backend/api/tests/test_seismic.py index 8c57bfe6..88ee2bf1 100644 --- a/backend/api/tests/test_seismic.py +++ b/backend/api/tests/test_seismic.py @@ -1,5 +1,6 @@ import pytest from fastapi.testclient import TestClient + # Will the .. be stable? from ..main import app from ..schemas import Polygon @@ -18,16 +19,18 @@ def test_delete_polygon(client): def test_put_polygon(client): - response = client.put("/api/polygons/1?table_name=seismic", - json=Polygon().model_dump()) + response = client.put( + "/api/polygons/1?table_name=seismic", json=Polygon().model_dump() + ) assert response.status_code == 200 # Temporary guaranteed failure until test is written assert False def test_post_polygon(client): - response = client.put("/api/polygons/1?table_name=seismic", - json=Polygon().model_dump()) + response = client.put( + "/api/polygons/1?table_name=seismic", json=Polygon().model_dump() + ) assert response.status_code == 200 # Temporary guaranteed failure until test is written assert False @@ -44,4 +47,4 @@ def test_get_seismic_risk(client): response = client.get("/api/seismic-risk/address") assert response.status_code == 200 # Temporary guaranteed failure until test is written - assert False \ No newline at end of file + assert False diff --git a/backend/api/tests/test_soft_story.py b/backend/api/tests/test_soft_story.py index 6e87f06e..083efcf8 100644 --- a/backend/api/tests/test_soft_story.py +++ b/backend/api/tests/test_soft_story.py @@ -1,8 +1,10 @@ """ Test the API of soft_story.py. """ + import pytest from fastapi.testclient import TestClient + # Will the .. be stable? from ..main import app from ..schemas import Polygon @@ -38,4 +40,4 @@ def test_get_soft_story(client): response = client.get("/api/soft-story/address") assert response.status_code == 200 # Temporary guaranteed failure until test is written - assert False \ No newline at end of file + assert False diff --git a/backend/api/tests/test_tsunami.py b/backend/api/tests/test_tsunami.py index 4ef89b6f..99ea3f33 100644 --- a/backend/api/tests/test_tsunami.py +++ b/backend/api/tests/test_tsunami.py @@ -1,8 +1,10 @@ """ Test the API of tsunami.py. """ + import pytest from fastapi.testclient import TestClient + # Will the .. be stable? from ..main import app from ..schemas import Polygon @@ -13,7 +15,6 @@ def client(): return TestClient(app) - def test_delete_tsunami_polygon(client): response = client.delete("/api/polygons/1?table_name=tsunami") assert response.status_code == 200 @@ -22,16 +23,18 @@ def test_delete_tsunami_polygon(client): def test_put_tsunami_polygon(client): - response = client.put("/api/polygons/1?table_name=tsunami", - json=Polygon().model_dump()) + response = client.put( + "/api/polygons/1?table_name=tsunami", json=Polygon().model_dump() + ) assert response.status_code == 200 # Temporary guaranteed failure until test is written assert False def test_post_tsunami_polygon(client): - response = client.put("/api/polygons/1?table_name=tsunami", - json=Polygon().model_dump()) + response = client.put( + "/api/polygons/1?table_name=tsunami", json=Polygon().model_dump() + ) assert response.status_code == 200 # Temporary guaranteed failure until test is written assert False @@ -48,4 +51,4 @@ def test_get_tsunami_risk(client): response = client.get("/api/tsunami-risk/addresss") assert response.status_code == 200 # Temporary guaranteed failure until test is written - assert False \ No newline at end of file + assert False diff --git a/backend/database/tests/test_database.py b/backend/database/tests/test_database.py index 7cef0e1c..c3356a1b 100644 --- a/backend/database/tests/test_database.py +++ b/backend/database/tests/test_database.py @@ -5,7 +5,7 @@ from ...api.config import settings -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def test_db(): # Create a session using the existing database engine = create_engine(settings.localhost_database_url) @@ -17,31 +17,35 @@ def test_db(): Session = scoped_session(sessionmaker(bind=connection)) session = Session() # Start a transaction - session.begin_nested() + session.begin_nested() yield session # This will be the session we use in tests - session.rollback() session.close() # Clean up after tests connection.close() + def test_insert_combined_risk(test_db): # Arrange new_risk = CombinedRisk( - address='124 Test St, San Francisco, CA', + address="124 Test St, San Francisco, CA", soft_story_risk=True, seismic_hazard_risk=False, landslide_risk=False, - liquefaction_risk=False + liquefaction_risk=False, ) - + # Act test_db.add(new_risk) test_db.commit() # Assert - result = test_db.query(CombinedRisk).filter_by(address='124 Test St, San Francisco, CA').first() + result = ( + test_db.query(CombinedRisk) + .filter_by(address="124 Test St, San Francisco, CA") + .first() + ) assert result is not None assert result.soft_story_risk is True assert result.seismic_hazard_risk is False @@ -53,4 +57,6 @@ def test_query_combined_risk(test_db): # Assert assert len(results) > 0 # Check if there are records - assert all(isinstance(r, CombinedRisk) for r in results) # Ensure all records are CombinedRisk instances + assert all( + isinstance(r, CombinedRisk) for r in results + ) # Ensure all records are CombinedRisk instances