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
16 changes: 16 additions & 0 deletions collector_db/AsyncDatabaseClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from collector_db.DTOs.URLMapping import URLMapping
from collector_db.DTOs.URLWithHTML import URLWithHTML
from collector_db.StatementComposer import StatementComposer
from collector_db.constants import PLACEHOLDER_AGENCY_NAME
from collector_db.enums import URLMetadataAttributeType, TaskType
from collector_db.helper_functions import get_postgres_connection_string
from collector_db.models import URL, URLErrorInfo, URLHTMLContent, Base, \
Expand Down Expand Up @@ -1184,6 +1185,21 @@
# Add any new agency ids that are not in the existing agency ids
for new_agency_id in new_agency_ids:
if new_agency_id not in existing_agency_ids:
# Check if the new agency exists in the database
query = (
select(Agency)
.where(Agency.agency_id == new_agency_id)
)
existing_agency = await session.execute(query)
existing_agency = existing_agency.scalars().first()
if existing_agency is None:
# If not, create it

Check failure on line 1196 in collector_db/AsyncDatabaseClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/AsyncDatabaseClient.py#L1196 <115>

expected an indented block (comment)
Raw output
./collector_db/AsyncDatabaseClient.py:1196:17: E115 expected an indented block (comment)
agency = Agency(
agency_id=new_agency_id,
name=PLACEHOLDER_AGENCY_NAME,
)
session.add(agency)

# If the new agency id is not in the existing agency ids, add it
confirmed_url_agency = ConfirmedURLAgency(
url_id=approval_info.url_id,
Expand Down
3 changes: 3 additions & 0 deletions collector_db/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Check warning on line 1 in collector_db/constants.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/constants.py#L1 <100>

Missing docstring in public module
Raw output
./collector_db/constants.py:1:1: D100 Missing docstring in public module

PLACEHOLDER_AGENCY_NAME = "PLACEHOLDER_AGENCY_NAME"

Check warning on line 3 in collector_db/constants.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/constants.py#L3 <292>

no newline at end of file
Raw output
./collector_db/constants.py:3:52: W292 no newline at end of file
19 changes: 15 additions & 4 deletions tests/test_automated/integration/api/test_review.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from collector_db.models import URL, URLOptionalDataSourceMetadata, ConfirmedURLAgency
from collector_db.constants import PLACEHOLDER_AGENCY_NAME
from collector_db.models import URL, URLOptionalDataSourceMetadata, ConfirmedURLAgency, Agency
from collector_manager.enums import URLStatus
from core.DTOs.FinalReviewApprovalInfo import FinalReviewApprovalInfo
from core.DTOs.GetNextURLForFinalReviewResponse import GetNextURLForFinalReviewOuterResponse
Expand Down Expand Up @@ -89,7 +90,11 @@ async def test_approve_and_get_next_source_for_review(api_test_helper):
# Add confirmed agency
confirmed_agency = await db_data_creator.confirmed_suggestions([url_mapping.url_id])

# Additionally, include an agency not yet included in the database
additional_agency = 999999

agency_ids = [await db_data_creator.agency() for _ in range(3)]
agency_ids.append(additional_agency)

result: GetNextURLForFinalReviewOuterResponse = await ath.request_validator.approve_and_get_next_source_for_review(
approval_info=FinalReviewApprovalInfo(
Expand Down Expand Up @@ -126,9 +131,15 @@ async def test_approve_and_get_next_source_for_review(api_test_helper):
assert optional_metadata[0].record_formats == ["New Test Record Format", "New Test Record Format 2"]

# Get agencies
agencies = await adb_client.get_all(ConfirmedURLAgency)
assert len(agencies) == 3
for agency in agencies:
confirmed_agencies = await adb_client.get_all(ConfirmedURLAgency)
assert len(confirmed_agencies) == 4
for agency in confirmed_agencies:
assert agency.agency_id in agency_ids

# Check that created agency has placeholder
agencies = await adb_client.get_all(Agency)
for agency in agencies:
if agency.agency_id == additional_agency:
assert agency.name == PLACEHOLDER_AGENCY_NAME