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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def _update_locations_expanded_view():
WHEN locations.type = 'Locality'::location_type THEN localities.name
WHEN locations.type = 'County'::location_type THEN counties.name::character varying
WHEN locations.type = 'State'::location_type THEN us_states.state_name::character varying
WHEN locations.type = 'National'::location_type THEN 'United States'
ELSE NULL::character varying
END AS display_name,
CASE
Expand Down
18 changes: 18 additions & 0 deletions src/api/endpoints/annotate/all/post/models/agency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pydantic import BaseModel

Check warning on line 1 in src/api/endpoints/annotate/all/post/models/agency.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/post/models/agency.py#L1 <100>

Missing docstring in public module
Raw output
./src/api/endpoints/annotate/all/post/models/agency.py:1:1: D100 Missing docstring in public module

from src.db.models.impl.agency.enums import JurisdictionType, AgencyType


class AnnotationNewAgencySuggestionInfo(BaseModel):

Check warning on line 6 in src/api/endpoints/annotate/all/post/models/agency.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/post/models/agency.py#L6 <101>

Missing docstring in public class
Raw output
./src/api/endpoints/annotate/all/post/models/agency.py:6:1: D101 Missing docstring in public class
name: str
location_id: int
jurisdiction_type: JurisdictionType | None
agency_type: AgencyType | None

class AnnotationPostAgencyInfo(BaseModel):

Check warning on line 12 in src/api/endpoints/annotate/all/post/models/agency.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/post/models/agency.py#L12 <101>

Missing docstring in public class
Raw output
./src/api/endpoints/annotate/all/post/models/agency.py:12:1: D101 Missing docstring in public class
new_agency_suggestion: AnnotationNewAgencySuggestionInfo | None = None
agency_ids: list[int] = []

@property
def empty(self) -> bool:

Check warning on line 17 in src/api/endpoints/annotate/all/post/models/agency.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/post/models/agency.py#L17 <102>

Missing docstring in public method
Raw output
./src/api/endpoints/annotate/all/post/models/agency.py:17:1: D102 Missing docstring in public method
return self.new_agency_suggestion is None and len(self.agency_ids) == 0
11 changes: 7 additions & 4 deletions src/api/endpoints/annotate/all/post/models/request.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from pydantic import BaseModel, model_validator
from pydantic import BaseModel, model_validator, ConfigDict

Check warning on line 1 in src/api/endpoints/annotate/all/post/models/request.py

View workflow job for this annotation

GitHub Actions / flake8

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

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

from src.api.endpoints.annotate.all.post.models.agency import AnnotationPostAgencyInfo
from src.api.endpoints.annotate.all.post.models.name import AnnotationPostNameInfo
from src.core.enums import RecordType
from src.core.exceptions import FailedValidationException
from src.db.models.impl.flag.url_validated.enums import URLType


class AllAnnotationPostInfo(BaseModel):
model_config = ConfigDict(extra='forbid')

suggested_status: URLType
record_type: RecordType | None = None
agency_ids: list[int]
agency_info: AnnotationPostAgencyInfo
location_ids: list[int]
name_info: AnnotationPostNameInfo = AnnotationPostNameInfo()

Expand All @@ -30,8 +33,8 @@
return self
if self.record_type is not None:
raise FailedValidationException("record_type must be None if suggested_status is NOT RELEVANT")
if len(self.agency_ids) > 0:
raise FailedValidationException("agency_ids must be empty if suggested_status is NOT RELEVANT")
if not self.agency_info.empty:
raise FailedValidationException("agency_info must be empty if suggested_status is NOT RELEVANT")
if len(self.location_ids) > 0:
raise FailedValidationException("location_ids must be empty if suggested_status is NOT RELEVANT")
return self
Expand Down
4 changes: 3 additions & 1 deletion src/api/endpoints/annotate/all/post/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ async def run(self, session: AsyncSession) -> None:
# TODO (TEST): Add test for submitting Meta URL validation
requester.optionally_add_record_type(self.post_info.record_type)

requester.add_agency_ids(self.post_info.agency_ids)
requester.add_agency_ids(self.post_info.agency_info.agency_ids)

await requester.optionally_add_new_agency_suggestion(self.post_info.agency_info.new_agency_suggestion)
16 changes: 16 additions & 0 deletions src/api/endpoints/annotate/all/post/requester.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from sqlalchemy.ext.asyncio import AsyncSession

from src.api.endpoints.annotate.all.post.models.agency import AnnotationNewAgencySuggestionInfo
from src.api.endpoints.annotate.all.post.models.name import AnnotationPostNameInfo
from src.core.enums import RecordType
from src.db.models.impl.agency.suggestion.sqlalchemy import NewAgencySuggestion
from src.db.models.impl.flag.url_validated.enums import URLType
from src.db.models.impl.link.user_name_suggestion.sqlalchemy import LinkUserNameSuggestion
from src.db.models.impl.url.suggestion.agency.user import UserUrlAgencySuggestion
Expand Down Expand Up @@ -93,3 +95,17 @@
suggestion_id=name_suggestion.id,
)
self.session.add(link)

async def optionally_add_new_agency_suggestion(

Check warning on line 99 in src/api/endpoints/annotate/all/post/requester.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/post/requester.py#L99 <102>

Missing docstring in public method
Raw output
./src/api/endpoints/annotate/all/post/requester.py:99:1: D102 Missing docstring in public method
self,
suggestion_info: AnnotationNewAgencySuggestionInfo | None
) -> None:
if suggestion_info is None:
return
new_agency_suggestion = NewAgencySuggestion(
name=suggestion_info.name,
location_id=suggestion_info.location_id,
jurisdiction_type=suggestion_info.jurisdiction_type,
agency_type=suggestion_info.agency_type,
)
self.session.add(new_agency_suggestion)

Check warning on line 111 in src/api/endpoints/annotate/all/post/requester.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/post/requester.py#L111 <292>

no newline at end of file
Raw output
./src/api/endpoints/annotate/all/post/requester.py:111:48: W292 no newline at end of file
Empty file.
17 changes: 17 additions & 0 deletions src/db/models/impl/agency/suggestion/pydantic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pydantic import BaseModel

Check warning on line 1 in src/db/models/impl/agency/suggestion/pydantic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/models/impl/agency/suggestion/pydantic.py#L1 <100>

Missing docstring in public module
Raw output
./src/db/models/impl/agency/suggestion/pydantic.py:1:1: D100 Missing docstring in public module

from src.db.models.impl.agency.enums import JurisdictionType, AgencyType
from src.db.models.impl.agency.suggestion.sqlalchemy import NewAgencySuggestion
from src.db.models.templates_.base import Base


class NewAgencySuggestionPydantic(BaseModel):

Check warning on line 8 in src/db/models/impl/agency/suggestion/pydantic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/models/impl/agency/suggestion/pydantic.py#L8 <101>

Missing docstring in public class
Raw output
./src/db/models/impl/agency/suggestion/pydantic.py:8:1: D101 Missing docstring in public class

name: str
location_id: int
jurisdiction_type: JurisdictionType | None
agency_type: AgencyType | None

@classmethod
def sa_model(cls) -> type[Base]:

Check warning on line 16 in src/db/models/impl/agency/suggestion/pydantic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/models/impl/agency/suggestion/pydantic.py#L16 <102>

Missing docstring in public method
Raw output
./src/db/models/impl/agency/suggestion/pydantic.py:16:1: D102 Missing docstring in public method
return NewAgencySuggestion

Check warning on line 17 in src/db/models/impl/agency/suggestion/pydantic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/models/impl/agency/suggestion/pydantic.py#L17 <292>

no newline at end of file
Raw output
./src/db/models/impl/agency/suggestion/pydantic.py:17:35: W292 no newline at end of file
19 changes: 19 additions & 0 deletions src/db/models/impl/agency/suggestion/sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from sqlalchemy import String, Column

Check warning on line 1 in src/db/models/impl/agency/suggestion/sqlalchemy.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/models/impl/agency/suggestion/sqlalchemy.py#L1 <100>

Missing docstring in public module
Raw output
./src/db/models/impl/agency/suggestion/sqlalchemy.py:1:1: D100 Missing docstring in public module

from src.db.models.helpers import enum_column
from src.db.models.impl.agency.enums import JurisdictionType, AgencyType
from src.db.models.mixins import CreatedAtMixin, LocationDependentMixin
from src.db.models.templates_.with_id import WithIDBase


class NewAgencySuggestion(

Check warning on line 9 in src/db/models/impl/agency/suggestion/sqlalchemy.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/models/impl/agency/suggestion/sqlalchemy.py#L9 <101>

Missing docstring in public class
Raw output
./src/db/models/impl/agency/suggestion/sqlalchemy.py:9:1: D101 Missing docstring in public class
WithIDBase,
CreatedAtMixin,
LocationDependentMixin,
):

__tablename__ = 'new_agency_suggestions'

name = Column(String)
jurisdiction_type = enum_column(JurisdictionType, name='jurisdiction_type_enum', nullable=True)
agency_type = enum_column(AgencyType, name='agency_type_enum', nullable=True)

Check warning on line 19 in src/db/models/impl/agency/suggestion/sqlalchemy.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/models/impl/agency/suggestion/sqlalchemy.py#L19 <292>

no newline at end of file
Raw output
./src/db/models/impl/agency/suggestion/sqlalchemy.py:19:82: W292 no newline at end of file
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from src.api.endpoints.annotate.all.get.models.location import LocationAnnotationUserSuggestion
from src.api.endpoints.annotate.all.get.models.response import GetNextURLForAllAnnotationResponse
from src.api.endpoints.annotate.all.get.queries.core import GetNextURLForAllAnnotationQueryBuilder
from src.api.endpoints.annotate.all.post.models.agency import AnnotationPostAgencyInfo
from src.api.endpoints.annotate.all.post.models.name import AnnotationPostNameInfo
from src.api.endpoints.annotate.all.post.models.request import AllAnnotationPostInfo
from src.core.enums import RecordType
Expand Down Expand Up @@ -64,7 +65,7 @@ async def test_annotate_all(
all_annotations_post_info=AllAnnotationPostInfo(
suggested_status=URLType.DATA_SOURCE,
record_type=RecordType.ACCIDENT_REPORTS,
agency_ids=[agency_id],
agency_info=AnnotationPostAgencyInfo(agency_ids=[agency_id]),
location_ids=[
california.location_id,
pennsylvania.location_id,
Expand All @@ -85,7 +86,7 @@ async def test_annotate_all(
all_annotations_post_info=AllAnnotationPostInfo(
suggested_status=URLType.NOT_RELEVANT,
location_ids=[],
agency_ids=[],
agency_info=AnnotationPostAgencyInfo(agency_ids=[]),
name_info=AnnotationPostNameInfo(
existing_name_id=setup_info_2.name_suggestion_id
)
Expand Down
64 changes: 64 additions & 0 deletions tests/automated/integration/api/annotate/all/test_new_agency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest

Check warning on line 1 in tests/automated/integration/api/annotate/all/test_new_agency.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/annotate/all/test_new_agency.py#L1 <100>

Missing docstring in public module
Raw output
./tests/automated/integration/api/annotate/all/test_new_agency.py:1:1: D100 Missing docstring in public module

from src.api.endpoints.annotate.all.post.models.agency import AnnotationPostAgencyInfo, \
AnnotationNewAgencySuggestionInfo
from src.api.endpoints.annotate.all.post.models.name import AnnotationPostNameInfo
from src.api.endpoints.annotate.all.post.models.request import AllAnnotationPostInfo
from src.core.enums import RecordType
from src.db.models.impl.agency.enums import JurisdictionType, AgencyType
from src.db.models.impl.agency.suggestion.sqlalchemy import NewAgencySuggestion
from src.db.models.impl.flag.url_validated.enums import URLType
from tests.helpers.data_creator.models.creation_info.us_state import USStateCreationInfo
from tests.helpers.setup.final_review.core import setup_for_get_next_url_for_final_review
from tests.helpers.setup.final_review.model import FinalReviewSetupInfo


@pytest.mark.asyncio
async def test_add_new_agency(
api_test_helper,
pennsylvania: USStateCreationInfo,
):
"""
Test the process for adding a new agency
Confirm a new agency suggestion is successfully added in the database.
"""
ath = api_test_helper
adb_client = ath.adb_client()

setup_info_1: FinalReviewSetupInfo = await setup_for_get_next_url_for_final_review(

Check failure on line 28 in tests/automated/integration/api/annotate/all/test_new_agency.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/annotate/all/test_new_agency.py#L28 <272>

multiple spaces before keyword
Raw output
./tests/automated/integration/api/annotate/all/test_new_agency.py:28:41: E272 multiple spaces before keyword

Check failure on line 28 in tests/automated/integration/api/annotate/all/test_new_agency.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/annotate/all/test_new_agency.py#L28 <222>

multiple spaces after operator
Raw output
./tests/automated/integration/api/annotate/all/test_new_agency.py:28:41: E222 multiple spaces after operator
db_data_creator=ath.db_data_creator,
include_user_annotations=True
)
url_mapping_1 = setup_info_1.url_mapping

post_response_1 = await ath.request_validator.post_all_annotations_and_get_next(

Check warning on line 34 in tests/automated/integration/api/annotate/all/test_new_agency.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/annotate/all/test_new_agency.py#L34 <841>

local variable 'post_response_1' is assigned to but never used
Raw output
./tests/automated/integration/api/annotate/all/test_new_agency.py:34:5: F841 local variable 'post_response_1' is assigned to but never used
url_id=url_mapping_1.url_id,
all_annotations_post_info=AllAnnotationPostInfo(
suggested_status=URLType.DATA_SOURCE,
record_type=RecordType.ACCIDENT_REPORTS,
agency_info=AnnotationPostAgencyInfo(
new_agency_suggestion=AnnotationNewAgencySuggestionInfo(
name="New Agency",
location_id=pennsylvania.location_id,
jurisdiction_type=JurisdictionType.STATE,
agency_type=AgencyType.LAW_ENFORCEMENT,
)
),
location_ids=[
pennsylvania.location_id,
],
name_info=AnnotationPostNameInfo(
new_name="New Name"
)
)
)

# Check for existence of new agency suggestion

suggestions: list[NewAgencySuggestion] = await adb_client.get_all(NewAgencySuggestion)
assert len(suggestions) == 1
suggestion: NewAgencySuggestion = suggestions[0]
assert suggestion.name == "New Agency"
assert suggestion.location_id == pennsylvania.location_id
assert suggestion.jurisdiction_type == JurisdictionType.STATE
assert suggestion.agency_type == AgencyType.LAW_ENFORCEMENT

Check warning on line 64 in tests/automated/integration/api/annotate/all/test_new_agency.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/annotate/all/test_new_agency.py#L64 <292>

no newline at end of file
Raw output
./tests/automated/integration/api/annotate/all/test_new_agency.py:64:64: W292 no newline at end of file
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from src.api.endpoints.annotate.all.post.models.agency import AnnotationPostAgencyInfo
from src.api.endpoints.annotate.all.post.models.request import AllAnnotationPostInfo
from src.db.models.impl.flag.url_validated.enums import URLType
from tests.helpers.setup.final_review.core import setup_for_get_next_url_for_final_review
Expand Down Expand Up @@ -31,7 +32,7 @@ async def test_annotate_all_post_batch_filtering(api_test_helper):
all_annotations_post_info=AllAnnotationPostInfo(
suggested_status=URLType.NOT_RELEVANT,
location_ids=[],
agency_ids=[]
agency_info=AnnotationPostAgencyInfo(agency_ids=[])
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from src.api.endpoints.annotate.all.post.models.agency import AnnotationPostAgencyInfo
from src.api.endpoints.annotate.all.post.models.request import AllAnnotationPostInfo
from src.core.enums import RecordType
from src.core.exceptions import FailedValidationException
Expand All @@ -25,6 +26,6 @@ async def test_annotate_all_validation_error(api_test_helper):
suggested_status=URLType.NOT_RELEVANT,
record_type=RecordType.ACCIDENT_REPORTS,
location_ids=[],
agency_ids=[]
agency_info=AnnotationPostAgencyInfo(agency_ids=[])
)
)
5 changes: 3 additions & 2 deletions tests/automated/unit/api/test_all_annotation_post_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from pydantic import BaseModel

from src.api.endpoints.annotate.all.post.models.agency import AnnotationPostAgencyInfo
from src.api.endpoints.annotate.all.post.models.request import AllAnnotationPostInfo
from src.core.enums import RecordType
from src.core.exceptions import FailedValidationException
Expand Down Expand Up @@ -94,13 +95,13 @@ def test_all_annotation_post_info(
AllAnnotationPostInfo(
suggested_status=params.suggested_status,
record_type=params.record_type,
agency_ids=params.agency_ids,
agency_info=AnnotationPostAgencyInfo(agency_ids=params.agency_ids),
location_ids=params.location_ids
)
else:
AllAnnotationPostInfo(
suggested_status=params.suggested_status,
record_type=params.record_type,
agency_ids=params.agency_ids,
agency_info=AnnotationPostAgencyInfo(agency_ids=params.agency_ids),
location_ids=params.location_ids
)