Skip to content

Commit f26b1ea

Browse files
committed
Clean up and refactor
1 parent c118df2 commit f26b1ea

File tree

5 files changed

+21
-35
lines changed

5 files changed

+21
-35
lines changed

src/external/pdap/_templates/request_builder.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,27 @@ async def post(
3838
raise Exception(f"Failed to make request to PDAP: {response_info.data}")
3939
return response_info.data
4040

41+
async def post_v2(
42+
self,
43+
url: str,
44+
request_model: BaseModel,
45+
return_model_type: type[T]
46+
) -> T:
47+
request_info = RequestInfo(
48+
type_=RequestType.POST,
49+
url=url,
50+
json_=request_model.model_dump(mode='json'),
51+
headers=await self.access_manager.jwt_header()
52+
)
53+
response_info: ResponseInfo = await self.access_manager.make_request(request_info)
54+
if response_info.status_code != HTTPStatus.OK:
55+
raise Exception(f"Failed to make request to PDAP: {response_info.data}")
56+
return return_model_type(**response_info.data)
57+
4158
async def get(
4259
self,
4360
url: str,
44-
model: type[T]
61+
return_model_type: type[T]
4562
) -> T:
4663
request_info = RequestInfo(
4764
type_=RequestType.GET,
@@ -51,7 +68,7 @@ async def get(
5168
response_info: ResponseInfo = await self.access_manager.make_request(request_info)
5269
if response_info.status_code != HTTPStatus.OK:
5370
raise Exception(f"Failed to make request to PDAP: {response_info.data}")
54-
return model(**response_info.data)
71+
return return_model_type(**response_info.data)
5572

5673
@abstractmethod
5774
async def inner_logic(self) -> Any:

src/external/pdap/client.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,3 @@ async def run_request_builder(
2222
request_builder: PDAPRequestBuilderBase
2323
) -> Any:
2424
return await request_builder.run(self.access_manager)
25-
26-
async def is_url_duplicate(
27-
self,
28-
url_to_check: str
29-
) -> bool:
30-
"""
31-
Check if a URL is unique. Returns duplicate info otherwise
32-
"""
33-
url: str = f"{self.access_manager.data_sources_url}/v2/check/unique-url"
34-
35-
request_info = RequestInfo(
36-
type_=RequestType.GET,
37-
url=url,
38-
params={
39-
"url": url_to_check
40-
}
41-
)
42-
response_info: ResponseInfo = await self.access_manager.make_request(request_info)
43-
duplicates: list[UniqueURLDuplicateInfo] = [
44-
UniqueURLDuplicateInfo(**entry) for entry in response_info.data["duplicates"]
45-
]
46-
is_duplicate: bool = (len(duplicates) != 0)
47-
return is_duplicate

src/external/pdap/impl/sync/follows/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ async def inner_logic(self) -> list[SyncFollowGetInnerResponse]:
88
url: str = self.build_url("v3/sync/follows")
99
response: SyncFollowGetOuterResponse = await self.get(
1010
url=url,
11-
model=SyncFollowGetOuterResponse
11+
return_model_type=SyncFollowGetOuterResponse
1212
)
1313
return response.follows

tests/automated/integration/api/proposals/test_agencies.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ async def test_agencies(
8585
agencies: list[Agency] = await adb_client.get_all(Agency)
8686
assert len(agencies) == 1
8787
agency = agencies[0]
88+
assert agency.id == agency_id
8889
assert agency.name == request.name
8990
assert agency.agency_type == request.agency_type
9091
assert agency.jurisdiction_type == request.jurisdiction_type

tests/manual/external/pdap/test_check_for_duplicate.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)