Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/api/endpoints/annotate/all/get/queries/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
self,
batch_id: int | None,
user_id: int,
url_id: int | None = None
url_id: int | None = None,
offset: int | None = None

Check warning on line 26 in src/api/endpoints/annotate/all/get/queries/core.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/get/queries/core.py#L26 <100>

Unused argument 'offset'
Raw output
./src/api/endpoints/annotate/all/get/queries/core.py:26:9: U100 Unused argument 'offset'
):
super().__init__()
self.batch_id = batch_id
Expand Down
10 changes: 9 additions & 1 deletion src/api/endpoints/annotate/anonymous/get/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class GetNextURLForAnonymousAnnotationQueryBuilder(QueryBuilderBase):

def __init__(
self,
session_id: UUID
session_id: UUID,
offset: int | None = None
):
super().__init__()
self.session_id = session_id
self.offset = offset

async def run(self, session: AsyncSession) -> GetNextURLForAnonymousAnnotationResponse:
base_cte = select(
Expand Down Expand Up @@ -66,11 +68,17 @@ async def run(self, session: AsyncSession) -> GetNextURLForAnonymousAnnotationRe
)
query = add_common_where_conditions(query)
query = add_load_options(query)
if self.offset is not None:
offset = 0
else:
offset = self.offset

query = (
# Sorting Priority
query.order_by(
*common_sorts(base_cte)
)
.offset(offset)
# Limit to 1 result
.limit(1)
)
Expand Down
51 changes: 43 additions & 8 deletions src/api/endpoints/annotate/routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import uuid
from http import HTTPStatus
from uuid import UUID

from fastapi import APIRouter, Depends, Query
from fastapi import APIRouter, Depends, Query, HTTPException

from src.api.dependencies import get_async_core
from src.api.endpoints.annotate.all.get.models.agency import AgencyAnnotationResponseOuterInfo
Expand Down Expand Up @@ -40,7 +41,11 @@
@annotate_router.get("/anonymous")
async def get_next_url_for_all_annotations_anonymous(
async_core: AsyncCore = Depends(get_async_core),
session_id: UUID | None = Query(description="The session id of the anonymous user.", default=None)
session_id: UUID | None = Query(description="The session id of the anonymous user.", default=None),
offset: int | None = Query(
description="Offset for annotation",
default=None
)
) -> GetNextURLForAnonymousAnnotationResponse:
# If session_id is not provided, generate new UUID
if session_id is None:
Expand All @@ -49,16 +54,23 @@
)

return await async_core.adb_client.run_query_builder(
GetNextURLForAnonymousAnnotationQueryBuilder(session_id=session_id)
GetNextURLForAnonymousAnnotationQueryBuilder(
session_id=session_id,
offset=offset
)
)


@annotate_router.post("/anonymous/{url_id}")
async def annotate_url_for_all_annotations_and_get_next_url_anonymous(
async def annotate_url_for_all_annotations(

Check warning on line 65 in src/api/endpoints/annotate/routes.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/routes.py#L65 <103>

Missing docstring in public function
Raw output
./src/api/endpoints/annotate/routes.py:65:1: D103 Missing docstring in public function
url_id: int,
all_annotation_post_info: AllAnnotationPostInfo,
async_core: AsyncCore = Depends(get_async_core),
session_id: UUID = Query(description="The session id of the anonymous user")
session_id: UUID = Query(description="The session id of the anonymous user"),
get_next_url: bool = Query(
description="Get next URL after submitting this URL",
default=True
)
) -> GetNextURLForAnonymousAnnotationResponse:
await async_core.adb_client.run_query_builder(
AddAnonymousAnnotationsToURLQueryBuilder(
Expand All @@ -67,6 +79,11 @@
session_id=session_id
)
)
if not get_next_url:
return GetNextURLForAnonymousAnnotationResponse(
next_annotation=None,
session_id=session_id
)

return await async_core.adb_client.run_query_builder(
GetNextURLForAnonymousAnnotationQueryBuilder(
Expand All @@ -81,22 +98,35 @@
access_info: AccessInfo = Depends(get_standard_user_access_info),
async_core: AsyncCore = Depends(get_async_core),
batch_id: int | None = batch_query,
anno_url_id: int | None = url_id_query
anno_url_id: int | None = url_id_query,
offset: int | None = Query(
description="Offset for annotation",
default=None
)
) -> GetNextURLForAllAnnotationResponse:
if anno_url_id is not None and offset is not None:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail="anno_url_id and offset query arguments cannot both be defined"
)
return await async_core.adb_client.get_next_url_for_all_annotations(
batch_id=batch_id,
user_id=access_info.user_id,
url_id=anno_url_id
)

@annotate_router.post("/all/{url_id}")
async def annotate_url_for_all_annotations_and_get_next_url(
async def annotate_url_for_all_annotations(

Check warning on line 119 in src/api/endpoints/annotate/routes.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/routes.py#L119 <811>

redefinition of unused 'annotate_url_for_all_annotations' from line 65
Raw output
./src/api/endpoints/annotate/routes.py:119:1: F811 redefinition of unused 'annotate_url_for_all_annotations' from line 65
url_id: int,
all_annotation_post_info: AllAnnotationPostInfo,
async_core: AsyncCore = Depends(get_async_core),
access_info: AccessInfo = Depends(get_standard_user_access_info),
batch_id: int | None = batch_query,
anno_url_id: int | None = url_id_query
anno_url_id: int | None = url_id_query,
get_next_url: bool = Query(
description="Get next URL after submitting this URL",
default=True
)
) -> GetNextURLForAllAnnotationResponse:
"""
Post URL annotation and get next URL to annotate
Expand All @@ -109,6 +139,11 @@
)
)

if not get_next_url:
return GetNextURLForAllAnnotationResponse(
next_annotation=None
)

return await async_core.adb_client.get_next_url_for_all_annotations(
batch_id=batch_id,
user_id=access_info.user_id,
Expand Down
14 changes: 9 additions & 5 deletions tests/automated/integration/api/_helpers/RequestValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,16 @@
async def get_next_url_for_all_annotations(
self,
batch_id: int | None = None,
anno_url_id: int | None = None
anno_url_id: int | None = None,
offset: int | None = None
) -> GetNextURLForAllAnnotationResponse:
params = {}
update_if_not_none(
target=params,
source={
"batch_id": batch_id,
"anno_url_id": anno_url_id
"anno_url_id": anno_url_id,
"offset": offset
}
)
data = self.get(
Expand All @@ -412,19 +414,21 @@
)
return GetNextURLForAllAnnotationResponse(**data)

async def post_all_annotations_and_get_next(
async def post_all_annotations(

Check warning on line 417 in tests/automated/integration/api/_helpers/RequestValidator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/_helpers/RequestValidator.py#L417 <102>

Missing docstring in public method
Raw output
./tests/automated/integration/api/_helpers/RequestValidator.py:417:1: D102 Missing docstring in public method
self,
url_id: int,
all_annotations_post_info: AllAnnotationPostInfo,
batch_id: int | None = None,
anno_url_id: int | None = None
anno_url_id: int | None = None,
get_next_url: bool = True
) -> GetNextURLForAllAnnotationResponse:
params = {}
update_if_not_none(
target=params,
source={
"batch_id": batch_id,
"anno_url_id": anno_url_id
"anno_url_id": anno_url_id,
"get_next_url": get_next_url
}
)
data = self.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
from src.db.models.impl.annotation.record_type.user.user import AnnotationRecordTypeUser
from src.db.models.impl.annotation.url_type.user.sqlalchemy import AnnotationURLTypeUser
from src.db.models.impl.flag.url_validated.enums import URLType
from tests.helpers.api_test_helper import APITestHelper
from tests.helpers.data_creator.models.creation_info.county import CountyCreationInfo
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


@pytest.mark.asyncio
async def test_annotate_all(
api_test_helper,
api_test_helper: APITestHelper,
pennsylvania: USStateCreationInfo,
allegheny_county: USStateCreationInfo,
allegheny_county: CountyCreationInfo,

Check warning on line 28 in tests/automated/integration/api/annotate/all/test_happy_path.py

View workflow job for this annotation

GitHub Actions / flake8

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

Unused argument 'allegheny_county'
Raw output
./tests/automated/integration/api/annotate/all/test_happy_path.py:28:5: U100 Unused argument 'allegheny_county'
california: USStateCreationInfo,
test_agency_id: int
):
Expand Down Expand Up @@ -63,7 +65,7 @@

# Annotate the first and submit
agency_id = await ath.db_data_creator.agency()
post_response_1 = await ath.request_validator.post_all_annotations_and_get_next(
post_response_1 = await ath.request_validator.post_all_annotations(
url_id=url_mapping_1.url_id,
all_annotations_post_info=AllAnnotationPostInfo(
suggested_status=URLType.DATA_SOURCE,
Expand All @@ -86,7 +88,7 @@
assert post_response_1.next_annotation.url_info.url_id == url_mapping_2.url_id

# Upon submitting the second, confirm that no more URLs are returned through either POST or GET
post_response_2 = await ath.request_validator.post_all_annotations_and_get_next(
post_response_2 = await ath.request_validator.post_all_annotations(
url_id=url_mapping_2.url_id,
all_annotations_post_info=AllAnnotationPostInfo(
suggested_status=URLType.NOT_RELEVANT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
db_data_creator=ath.db_data_creator, include_user_annotations=True
)

post_response_1 = await ath.request_validator.post_all_annotations_and_get_next(
post_response_1 = await ath.request_validator.post_all_annotations(

Check warning on line 27 in tests/automated/integration/api/annotate/all/test_not_found.py

View workflow job for this annotation

GitHub Actions / flake8

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

local variable 'post_response_1' is assigned to but never used
Raw output
./tests/automated/integration/api/annotate/all/test_not_found.py:27:5: F841 local variable 'post_response_1' is assigned to but never used
url_id=setup_info_1.url_mapping.url_id,
all_annotations_post_info=AllAnnotationPostInfo(
suggested_status=URLType.DATA_SOURCE,
Expand Down
38 changes: 38 additions & 0 deletions tests/automated/integration/api/annotate/all/test_offset.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/annotate/all/test_offset.py

View workflow job for this annotation

GitHub Actions / flake8

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

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

from src.api.endpoints.annotate.all.get.models.response import GetNextURLForAllAnnotationResponse
from src.db.dtos.url.mapping_.simple import SimpleURLMapping
from tests.helpers.api_test_helper import APITestHelper
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_offset(
api_test_helper: APITestHelper,
):
"""
Test that offset functionality works as expected when getting
user annotations
"""

ath = api_test_helper

# Set up URLs
setup_info_1: FinalReviewSetupInfo = await setup_for_get_next_url_for_final_review(

Check failure on line 22 in tests/automated/integration/api/annotate/all/test_offset.py

View workflow job for this annotation

GitHub Actions / flake8

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

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

Check failure on line 22 in tests/automated/integration/api/annotate/all/test_offset.py

View workflow job for this annotation

GitHub Actions / flake8

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

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

Check warning on line 25 in tests/automated/integration/api/annotate/all/test_offset.py

View workflow job for this annotation

GitHub Actions / flake8

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

local variable 'url_mapping_1' is assigned to but never used
Raw output
./tests/automated/integration/api/annotate/all/test_offset.py:25:5: F841 local variable 'url_mapping_1' is assigned to but never used
setup_info_2: FinalReviewSetupInfo = await setup_for_get_next_url_for_final_review(
db_data_creator=ath.db_data_creator, include_user_annotations=True
)
url_mapping_2: SimpleURLMapping = setup_info_2.url_mapping


get_response_1: GetNextURLForAllAnnotationResponse = await ath.request_validator.get_next_url_for_all_annotations(

Check failure on line 32 in tests/automated/integration/api/annotate/all/test_offset.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/annotate/all/test_offset.py#L32 <303>

too many blank lines (2)
Raw output
./tests/automated/integration/api/annotate/all/test_offset.py:32:5: E303 too many blank lines (2)
offset=1
)

# Check that response is the second URL, rather than the first
assert get_response_1.next_annotation.url_info.url_id == url_mapping_2.url_id

Check warning on line 38 in tests/automated/integration/api/annotate/all/test_offset.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/annotate/all/test_offset.py#L38 <391>

blank line at end of file
Raw output
./tests/automated/integration/api/annotate/all/test_offset.py:38:1: W391 blank line at end of file
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def test_annotate_all_post_batch_filtering(api_test_helper):
url_mapping_3 = setup_info_3.url_mapping

# Submit the first annotation, using the third batch id, and receive the third URL
post_response_1 = await ath.request_validator.post_all_annotations_and_get_next(
post_response_1 = await ath.request_validator.post_all_annotations(
url_id=url_mapping_1.url_id,
batch_id=setup_info_3.batch_id,
all_annotations_post_info=AllAnnotationPostInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import pytest

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

View workflow job for this annotation

GitHub Actions / flake8

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

Missing docstring in public module
Raw output
./tests/automated/integration/api/annotate/all/test_post_return_no_annotation.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.location import AnnotationPostLocationInfo
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.annotation.url_type.user.sqlalchemy import AnnotationURLTypeUser
from src.db.models.impl.flag.url_validated.enums import URLType
from tests.helpers.api_test_helper import APITestHelper
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


@pytest.mark.asyncio
async def test_post_annotate_return_no_annotation(
api_test_helper: APITestHelper,
pennsylvania: USStateCreationInfo,
test_agency_id: int
):
"""
If the `return_new_annotation` query arg is false,
do not return a new annotation.
"""
ath = api_test_helper
adb_client = ath.adb_client()

# Set up URLs
setup_info_1 = await setup_for_get_next_url_for_final_review(

Check failure on line 29 in tests/automated/integration/api/annotate/all/test_post_return_no_annotation.py

View workflow job for this annotation

GitHub Actions / flake8

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

multiple spaces before keyword
Raw output
./tests/automated/integration/api/annotate/all/test_post_return_no_annotation.py:29:19: E272 multiple spaces before keyword

Check failure on line 29 in tests/automated/integration/api/annotate/all/test_post_return_no_annotation.py

View workflow job for this annotation

GitHub Actions / flake8

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

multiple spaces after operator
Raw output
./tests/automated/integration/api/annotate/all/test_post_return_no_annotation.py:29:19: E222 multiple spaces after operator
db_data_creator=ath.db_data_creator, include_user_annotations=True
)
url_mapping_1 = setup_info_1.url_mapping
setup_info_2 = await setup_for_get_next_url_for_final_review(
db_data_creator=ath.db_data_creator, include_user_annotations=True
)
url_mapping_2 = setup_info_2.url_mapping

Check warning on line 36 in tests/automated/integration/api/annotate/all/test_post_return_no_annotation.py

View workflow job for this annotation

GitHub Actions / flake8

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

local variable 'url_mapping_2' is assigned to but never used
Raw output
./tests/automated/integration/api/annotate/all/test_post_return_no_annotation.py:36:5: F841 local variable 'url_mapping_2' is assigned to but never used

post_response_1 = await ath.request_validator.post_all_annotations(
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(agency_ids=[test_agency_id]),
location_info=AnnotationPostLocationInfo(
location_ids=[
pennsylvania.location_id,
]
),
name_info=AnnotationPostNameInfo(
new_name="New Name"
)
),
get_next_url=False
)
assert post_response_1.next_annotation is None

# Check annotation still posted to DB
# Check URL Type Suggestions
all_relevance_suggestions: list[AnnotationURLTypeUser] = await adb_client.get_all(AnnotationURLTypeUser)
assert len(all_relevance_suggestions) == 3
suggested_types: set[URLType] = {sugg.type for sugg in all_relevance_suggestions}
assert suggested_types == {URLType.DATA_SOURCE, URLType.NOT_RELEVANT}

Check warning on line 63 in tests/automated/integration/api/annotate/all/test_post_return_no_annotation.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/automated/integration/api/annotate/all/test_post_return_no_annotation.py#L63 <391>

blank line at end of file
Raw output
./tests/automated/integration/api/annotate/all/test_post_return_no_annotation.py:63:1: W391 blank line at end of file
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def test_annotate_all_post_batch_filtering(api_test_helper: APITestHelper)
)
assert get_response_2.next_annotation.url_info.url_id == url_mapping_3.url_id

post_response_3 = await ath.request_validator.post_all_annotations_and_get_next(
post_response_3 = await ath.request_validator.post_all_annotations(
url_id=url_mapping_1.url_id,
anno_url_id=url_mapping_3.url_id,
all_annotations_post_info=AllAnnotationPostInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
url_mapping_1 = setup_info_1.url_mapping

with pytest.raises(FailedValidationException) as e:
response = await ath.request_validator.post_all_annotations_and_get_next(
response = await ath.request_validator.post_all_annotations(

Check warning on line 24 in tests/automated/integration/api/annotate/all/test_validation_error.py

View workflow job for this annotation

GitHub Actions / flake8

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

local variable 'response' is assigned to but never used
Raw output
./tests/automated/integration/api/annotate/all/test_validation_error.py:24:9: F841 local variable 'response' is assigned to but never used
url_id=url_mapping_1.url_id,
all_annotations_post_info=AllAnnotationPostInfo(
suggested_status=URLType.NOT_RELEVANT,
Expand Down
Loading
Loading