From f26b1ead56f6fbbfc9112838a475f7eb2710854a Mon Sep 17 00:00:00 2001 From: Max Chis Date: Mon, 29 Dec 2025 14:07:10 -0500 Subject: [PATCH] Clean up and refactor --- .../pdap/_templates/request_builder.py | 21 +++++++++++++++-- src/external/pdap/client.py | 23 ------------------- src/external/pdap/impl/sync/follows/core.py | 2 +- .../api/proposals/test_agencies.py | 1 + .../external/pdap/test_check_for_duplicate.py | 9 -------- 5 files changed, 21 insertions(+), 35 deletions(-) delete mode 100644 tests/manual/external/pdap/test_check_for_duplicate.py diff --git a/src/external/pdap/_templates/request_builder.py b/src/external/pdap/_templates/request_builder.py index 887e2cfd..d944efdf 100644 --- a/src/external/pdap/_templates/request_builder.py +++ b/src/external/pdap/_templates/request_builder.py @@ -38,10 +38,27 @@ async def post( raise Exception(f"Failed to make request to PDAP: {response_info.data}") return response_info.data + async def post_v2( + self, + url: str, + request_model: BaseModel, + return_model_type: type[T] + ) -> T: + request_info = RequestInfo( + type_=RequestType.POST, + url=url, + json_=request_model.model_dump(mode='json'), + headers=await self.access_manager.jwt_header() + ) + response_info: ResponseInfo = await self.access_manager.make_request(request_info) + if response_info.status_code != HTTPStatus.OK: + raise Exception(f"Failed to make request to PDAP: {response_info.data}") + return return_model_type(**response_info.data) + async def get( self, url: str, - model: type[T] + return_model_type: type[T] ) -> T: request_info = RequestInfo( type_=RequestType.GET, @@ -51,7 +68,7 @@ async def get( response_info: ResponseInfo = await self.access_manager.make_request(request_info) if response_info.status_code != HTTPStatus.OK: raise Exception(f"Failed to make request to PDAP: {response_info.data}") - return model(**response_info.data) + return return_model_type(**response_info.data) @abstractmethod async def inner_logic(self) -> Any: diff --git a/src/external/pdap/client.py b/src/external/pdap/client.py index 38c67e08..d3cb1209 100644 --- a/src/external/pdap/client.py +++ b/src/external/pdap/client.py @@ -22,26 +22,3 @@ async def run_request_builder( request_builder: PDAPRequestBuilderBase ) -> Any: return await request_builder.run(self.access_manager) - - async def is_url_duplicate( - self, - url_to_check: str - ) -> bool: - """ - Check if a URL is unique. Returns duplicate info otherwise - """ - url: str = f"{self.access_manager.data_sources_url}/v2/check/unique-url" - - request_info = RequestInfo( - type_=RequestType.GET, - url=url, - params={ - "url": url_to_check - } - ) - response_info: ResponseInfo = await self.access_manager.make_request(request_info) - duplicates: list[UniqueURLDuplicateInfo] = [ - UniqueURLDuplicateInfo(**entry) for entry in response_info.data["duplicates"] - ] - is_duplicate: bool = (len(duplicates) != 0) - return is_duplicate diff --git a/src/external/pdap/impl/sync/follows/core.py b/src/external/pdap/impl/sync/follows/core.py index 707ac8c9..8b442e56 100644 --- a/src/external/pdap/impl/sync/follows/core.py +++ b/src/external/pdap/impl/sync/follows/core.py @@ -8,6 +8,6 @@ async def inner_logic(self) -> list[SyncFollowGetInnerResponse]: url: str = self.build_url("v3/sync/follows") response: SyncFollowGetOuterResponse = await self.get( url=url, - model=SyncFollowGetOuterResponse + return_model_type=SyncFollowGetOuterResponse ) return response.follows diff --git a/tests/automated/integration/api/proposals/test_agencies.py b/tests/automated/integration/api/proposals/test_agencies.py index 70a97118..31037f12 100644 --- a/tests/automated/integration/api/proposals/test_agencies.py +++ b/tests/automated/integration/api/proposals/test_agencies.py @@ -85,6 +85,7 @@ async def test_agencies( agencies: list[Agency] = await adb_client.get_all(Agency) assert len(agencies) == 1 agency = agencies[0] + assert agency.id == agency_id assert agency.name == request.name assert agency.agency_type == request.agency_type assert agency.jurisdiction_type == request.jurisdiction_type diff --git a/tests/manual/external/pdap/test_check_for_duplicate.py b/tests/manual/external/pdap/test_check_for_duplicate.py deleted file mode 100644 index 25a8bc52..00000000 --- a/tests/manual/external/pdap/test_check_for_duplicate.py +++ /dev/null @@ -1,9 +0,0 @@ -import pytest - - -@pytest.mark.asyncio -async def test_check_for_duplicate(pdap_client): - - response = await pdap_client.is_url_duplicate(url_to_check="example.com") - - print(response)