Skip to content
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
Empty file.
21 changes: 21 additions & 0 deletions src/api/endpoints/check/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from fastapi import APIRouter, Depends

Check warning on line 1 in src/api/endpoints/check/routes.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/check/routes.py#L1 <100>

Missing docstring in public module
Raw output
./src/api/endpoints/check/routes.py:1:1: D100 Missing docstring in public module

from src.api.dependencies import get_async_core
from src.api.endpoints.check.unique_url.response import CheckUniqueURLResponse
from src.api.endpoints.check.unique_url.wrapper import check_unique_url_wrapper
from src.core.core import AsyncCore

check_router = APIRouter(
prefix="/check",
tags=["check"]
)

@check_router.get("/unique-url")
async def check_unique_url(

Check warning on line 14 in src/api/endpoints/check/routes.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/check/routes.py#L14 <103>

Missing docstring in public function
Raw output
./src/api/endpoints/check/routes.py:14:1: D103 Missing docstring in public function
url: str,
async_core: AsyncCore = Depends(get_async_core),
) -> CheckUniqueURLResponse:
return await check_unique_url_wrapper(
adb_client=async_core.adb_client,
url=url
)
Empty file.
6 changes: 6 additions & 0 deletions src/api/endpoints/check/unique_url/response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pydantic import BaseModel

Check warning on line 1 in src/api/endpoints/check/unique_url/response.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/check/unique_url/response.py#L1 <100>

Missing docstring in public module
Raw output
./src/api/endpoints/check/unique_url/response.py:1:1: D100 Missing docstring in public module


class CheckUniqueURLResponse(BaseModel):

Check warning on line 4 in src/api/endpoints/check/unique_url/response.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/check/unique_url/response.py#L4 <101>

Missing docstring in public class
Raw output
./src/api/endpoints/check/unique_url/response.py:4:1: D101 Missing docstring in public class
unique_url: bool
url_id: int | None

Check warning on line 6 in src/api/endpoints/check/unique_url/response.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/check/unique_url/response.py#L6 <292>

no newline at end of file
Raw output
./src/api/endpoints/check/unique_url/response.py:6:23: W292 no newline at end of file
23 changes: 23 additions & 0 deletions src/api/endpoints/check/unique_url/wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from src.api.endpoints.check.unique_url.response import CheckUniqueURLResponse

Check warning on line 1 in src/api/endpoints/check/unique_url/wrapper.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/check/unique_url/wrapper.py#L1 <100>

Missing docstring in public module
Raw output
./src/api/endpoints/check/unique_url/wrapper.py:1:1: D100 Missing docstring in public module
from src.db.client.async_ import AsyncDatabaseClient
from src.db.queries.urls_exist.model import URLExistsResult
from src.db.queries.urls_exist.query import URLsExistInDBQueryBuilder
from src.util.models.full_url import FullURL


async def check_unique_url_wrapper(

Check warning on line 8 in src/api/endpoints/check/unique_url/wrapper.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/check/unique_url/wrapper.py#L8 <103>

Missing docstring in public function
Raw output
./src/api/endpoints/check/unique_url/wrapper.py:8:1: D103 Missing docstring in public function
adb_client: AsyncDatabaseClient,
url: str
) -> CheckUniqueURLResponse:
result: URLExistsResult = (await adb_client.run_query_builder(
URLsExistInDBQueryBuilder(full_urls=[FullURL(url)])
))[0]
if result.exists:
return CheckUniqueURLResponse(
unique_url=False,
url_id=result.url_id
)
return CheckUniqueURLResponse(
unique_url=True,
url_id=None
)
Empty file.
Empty file.
46 changes: 46 additions & 0 deletions src/api/endpoints/locations/post/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from typing import Any

Check warning on line 1 in src/api/endpoints/locations/post/query.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/post/query.py#L1 <100>

Missing docstring in public module
Raw output
./src/api/endpoints/locations/post/query.py:1:1: D100 Missing docstring in public module

Check warning on line 1 in src/api/endpoints/locations/post/query.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/post/query.py#L1 <401>

'typing.Any' imported but unused
Raw output
./src/api/endpoints/locations/post/query.py:1:1: F401 'typing.Any' imported but unused

from sqlalchemy import select, RowMapping
from sqlalchemy.ext.asyncio import AsyncSession

from src.api.endpoints.locations.post.request import AddLocationRequestModel
from src.api.endpoints.locations.post.response import AddLocationResponseModel
from src.db import Locality, Location
from src.db.queries.base.builder import QueryBuilderBase


class AddLocationQueryBuilder(QueryBuilderBase):

Check warning on line 12 in src/api/endpoints/locations/post/query.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/post/query.py#L12 <101>

Missing docstring in public class
Raw output
./src/api/endpoints/locations/post/query.py:12:1: D101 Missing docstring in public class

def __init__(

Check warning on line 14 in src/api/endpoints/locations/post/query.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/post/query.py#L14 <107>

Missing docstring in __init__
Raw output
./src/api/endpoints/locations/post/query.py:14:1: D107 Missing docstring in __init__
self,
request: AddLocationRequestModel
):
super().__init__()
self.request = request

async def run(self, session: AsyncSession) -> AddLocationResponseModel:

Check warning on line 21 in src/api/endpoints/locations/post/query.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/post/query.py#L21 <102>

Missing docstring in public method
Raw output
./src/api/endpoints/locations/post/query.py:21:1: D102 Missing docstring in public method
locality = Locality(
name=self.request.locality_name,
county_id=self.request.county_id
)
session.add(locality)
await session.flush()
locality_id: int = locality.id

query = (
select(
Location.id
)
.where(
Location.locality_id == locality_id
)
)

mapping: RowMapping = await self.sh.mapping(
session=session,
query=query
)

return AddLocationResponseModel(
location_id=mapping[Location.id]
)
6 changes: 6 additions & 0 deletions src/api/endpoints/locations/post/request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pydantic import BaseModel

Check warning on line 1 in src/api/endpoints/locations/post/request.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/post/request.py#L1 <100>

Missing docstring in public module
Raw output
./src/api/endpoints/locations/post/request.py:1:1: D100 Missing docstring in public module


class AddLocationRequestModel(BaseModel):

Check warning on line 4 in src/api/endpoints/locations/post/request.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/post/request.py#L4 <101>

Missing docstring in public class
Raw output
./src/api/endpoints/locations/post/request.py:4:1: D101 Missing docstring in public class
locality_name: str
county_id: int
5 changes: 5 additions & 0 deletions src/api/endpoints/locations/post/response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pydantic import BaseModel

Check warning on line 1 in src/api/endpoints/locations/post/response.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/post/response.py#L1 <100>

Missing docstring in public module
Raw output
./src/api/endpoints/locations/post/response.py:1:1: D100 Missing docstring in public module


class AddLocationResponseModel(BaseModel):

Check warning on line 4 in src/api/endpoints/locations/post/response.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/post/response.py#L4 <101>

Missing docstring in public class
Raw output
./src/api/endpoints/locations/post/response.py:4:1: D101 Missing docstring in public class
location_id: int

Check warning on line 5 in src/api/endpoints/locations/post/response.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/post/response.py#L5 <292>

no newline at end of file
Raw output
./src/api/endpoints/locations/post/response.py:5:21: W292 no newline at end of file
22 changes: 22 additions & 0 deletions src/api/endpoints/locations/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from fastapi import APIRouter, Depends

Check warning on line 1 in src/api/endpoints/locations/routes.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/routes.py#L1 <100>

Missing docstring in public module
Raw output
./src/api/endpoints/locations/routes.py:1:1: D100 Missing docstring in public module

from src.api.dependencies import get_async_core
from src.api.endpoints.locations.post.query import AddLocationQueryBuilder
from src.api.endpoints.locations.post.request import AddLocationRequestModel
from src.api.endpoints.locations.post.response import AddLocationResponseModel
from src.core.core import AsyncCore

location_url_router = APIRouter(
prefix="/locations",
tags=["Locations"],
responses={404: {"description": "Not found"}}
)

@location_url_router.post("")
async def create_location(

Check warning on line 16 in src/api/endpoints/locations/routes.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/locations/routes.py#L16 <103>

Missing docstring in public function
Raw output
./src/api/endpoints/locations/routes.py:16:1: D103 Missing docstring in public function
request: AddLocationRequestModel,
async_core: AsyncCore = Depends(get_async_core),
) -> AddLocationResponseModel:
return await async_core.adb_client.run_query_builder(
AddLocationQueryBuilder(request)
)
6 changes: 5 additions & 1 deletion src/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
from src.api.endpoints.agencies.routes import agencies_router
from src.api.endpoints.annotate.routes import annotate_router
from src.api.endpoints.batch.routes import batch_router
from src.api.endpoints.check.routes import check_router
from src.api.endpoints.collector.routes import collector_router
from src.api.endpoints.contributions.routes import contributions_router
from src.api.endpoints.data_source.routes import data_sources_router
from src.api.endpoints.locations.routes import location_url_router
from src.api.endpoints.meta_url.routes import meta_urls_router
from src.api.endpoints.metrics.routes import metrics_router
from src.api.endpoints.root import root_router
Expand Down Expand Up @@ -183,7 +185,9 @@ async def redirect_docs():
contributions_router,
agencies_router,
data_sources_router,
meta_urls_router
meta_urls_router,
check_router,
location_url_router
]

for router in routers:
Expand Down
Empty file.
Empty file.
38 changes: 38 additions & 0 deletions tests/automated/integration/api/locations/post/test_locality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest

Check warning on line 1 in tests/automated/integration/api/locations/post/test_locality.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/locations/post/test_locality.py#L1 <100>

Missing docstring in public module
Raw output
./tests/automated/integration/api/locations/post/test_locality.py:1:1: D100 Missing docstring in public module

from src.api.endpoints.locations.post.request import AddLocationRequestModel
from src.api.endpoints.locations.post.response import AddLocationResponseModel
from src.db import Locality, Location
from src.db.client.async_ import AsyncDatabaseClient
from tests.helpers.api_test_helper import APITestHelper
from tests.helpers.data_creator.models.creation_info.county import CountyCreationInfo


@pytest.mark.asyncio
async def test_add_locality(

Check warning on line 12 in tests/automated/integration/api/locations/post/test_locality.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/locations/post/test_locality.py#L12 <103>

Missing docstring in public function
Raw output
./tests/automated/integration/api/locations/post/test_locality.py:12:1: D103 Missing docstring in public function
allegheny_county: CountyCreationInfo,
adb_client_test: AsyncDatabaseClient,
api_test_helper: APITestHelper
):
# Add Locality
locality_response: dict = api_test_helper.request_validator.post_v3(
"/locations",
json=AddLocationRequestModel(
locality_name="Test Locality",
county_id=allegheny_county.county_id
).model_dump(mode='json')
)
response_model = AddLocationResponseModel(
**locality_response
)

# Confirm exists in database
localities: list[Locality] = await adb_client_test.get_all(Locality)
assert len(localities) == 1
assert localities[0].name == "Test Locality"
assert localities[0].county_id == allegheny_county.county_id

locations: list[Location] = await adb_client_test.get_all(Location)
assert len(locations) == 3
location_ids = {location.id for location in locations}
assert response_model.location_id in location_ids
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

Check warning on line 1 in tests/automated/integration/readonly/api/check/test_unique_url.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/readonly/api/check/test_unique_url.py#L1 <100>

Missing docstring in public module
Raw output
./tests/automated/integration/readonly/api/check/test_unique_url.py:1:1: D100 Missing docstring in public module

from src.api.endpoints.check.unique_url.response import CheckUniqueURLResponse
from tests.automated.integration.readonly.helper import ReadOnlyTestHelper
from tests.helpers.api_test_helper import APITestHelper


@pytest.mark.asyncio
async def test_check_unique_url(

Check warning on line 9 in tests/automated/integration/readonly/api/check/test_unique_url.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/readonly/api/check/test_unique_url.py#L9 <103>

Missing docstring in public function
Raw output
./tests/automated/integration/readonly/api/check/test_unique_url.py:9:1: D103 Missing docstring in public function
readonly_helper: ReadOnlyTestHelper
):

ath: APITestHelper = readonly_helper.api_test_helper
response_not_unique_url = ath.request_validator.get_v3(
url="/check/unique-url",
params={
"url": "https://read-only-ds.com"
}
)
model_not_unique_url = CheckUniqueURLResponse(**response_not_unique_url)
assert not model_not_unique_url.unique_url
assert model_not_unique_url.url_id == readonly_helper.maximal_data_source_url_id


response_unique_url = ath.request_validator.get_v3(

Check failure on line 25 in tests/automated/integration/readonly/api/check/test_unique_url.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/readonly/api/check/test_unique_url.py#L25 <303>

too many blank lines (2)
Raw output
./tests/automated/integration/readonly/api/check/test_unique_url.py:25:5: E303 too many blank lines (2)
url="/check/unique-url",
params={
"url": "https://nonexistent-url.com"
}
)
model_unique_url = CheckUniqueURLResponse(**response_unique_url)
assert model_unique_url.unique_url
assert model_unique_url.url_id is None

Check warning on line 33 in tests/automated/integration/readonly/api/check/test_unique_url.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/readonly/api/check/test_unique_url.py#L33 <292>

no newline at end of file
Raw output
./tests/automated/integration/readonly/api/check/test_unique_url.py:33:43: W292 no newline at end of file
3 changes: 0 additions & 3 deletions tests/automated/integration/readonly/setup/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ async def setup_readonly_data(
adb_client=adb_client
)




# Add Data Source With Linked Agency
maximal_data_source: int = await add_maximal_data_source(
agency_1_id=agency_1_id,
Expand Down