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
6 changes: 5 additions & 1 deletion src/api/endpoints/annotate/all/get/queries/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ class GetNextURLForAllAnnotationQueryBuilder(QueryBuilderBase):
def __init__(
self,
batch_id: int | None,
user_id: int
user_id: int,
url_id: int | None = None
):
super().__init__()
self.batch_id = batch_id
self.url_id = url_id
self.user_id = user_id

async def run(
Expand All @@ -65,6 +67,8 @@ async def run(
)
if self.batch_id is not None:
query = query.join(LinkBatchURL).where(LinkBatchURL.batch_id == self.batch_id)
if self.url_id is not None:
query = query.where(URL.id == self.url_id)
query = (
query
.where(
Expand Down
4 changes: 2 additions & 2 deletions src/api/endpoints/annotate/all/post/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class AllAnnotationPostInfo(BaseModel):

suggested_status: URLType
record_type: RecordType | None = None
agency_info: AnnotationPostAgencyInfo
location_info: AnnotationPostLocationInfo
agency_info: AnnotationPostAgencyInfo = AnnotationPostAgencyInfo()
location_info: AnnotationPostLocationInfo = AnnotationPostLocationInfo()
name_info: AnnotationPostNameInfo = AnnotationPostNameInfo()

@model_validator(mode="after")
Expand Down
18 changes: 13 additions & 5 deletions src/api/endpoints/annotate/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
"If not specified, defaults to first qualifying URL",
default=None
)

url_id_query = Query(
description="The URL id to annotate. " +

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

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/routes.py#L22 <504>

line break after binary operator
Raw output
./src/api/endpoints/annotate/routes.py:22:44: W504 line break after binary operator
"If not specified, defaults to first qualifying URL",
default=None
)


@annotate_router.get("/all")
async def get_next_url_for_all_annotations(
access_info: AccessInfo = Depends(get_access_info),
async_core: AsyncCore = Depends(get_async_core),
batch_id: int | None = batch_query
batch_id: int | None = batch_query,
anno_url_id: int | None = url_id_query
) -> GetNextURLForAllAnnotationResponse:
return await async_core.get_next_url_for_all_annotations(
batch_id=batch_id,
user_id=access_info.user_id
user_id=access_info.user_id,
url_id=anno_url_id
)

@annotate_router.post("/all/{url_id}")
Expand All @@ -38,7 +44,8 @@
all_annotation_post_info: AllAnnotationPostInfo,
async_core: AsyncCore = Depends(get_async_core),
access_info: AccessInfo = Depends(get_access_info),
batch_id: int | None = batch_query
batch_id: int | None = batch_query,
anno_url_id: int | None = url_id_query
) -> GetNextURLForAllAnnotationResponse:
"""
Post URL annotation and get next URL to annotate
Expand All @@ -50,5 +57,6 @@
)
return await async_core.get_next_url_for_all_annotations(
batch_id=batch_id,
user_id=access_info.user_id
user_id=access_info.user_id,
url_id=anno_url_id
)
6 changes: 4 additions & 2 deletions src/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,13 @@ async def get_next_source_for_review(
async def get_next_url_for_all_annotations(
self,
user_id: int,
batch_id: int | None
batch_id: int | None,
url_id: int | None
) -> GetNextURLForAllAnnotationResponse:
return await self.adb_client.get_next_url_for_all_annotations(
batch_id=batch_id,
user_id=user_id
user_id=user_id,
url_id=url_id
)

async def submit_url_for_all_annotations(
Expand Down
6 changes: 4 additions & 2 deletions src/db/client/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,11 +894,13 @@ async def delete_old_logs(self):
async def get_next_url_for_all_annotations(
self,
user_id: int,
batch_id: int | None = None
batch_id: int | None = None,
url_id: int | None = None
) -> GetNextURLForAllAnnotationResponse:
return await self.run_query_builder(GetNextURLForAllAnnotationQueryBuilder(
batch_id=batch_id,
user_id=user_id
user_id=user_id,
url_id=url_id
))

async def upload_manual_batch(
Expand Down
16 changes: 12 additions & 4 deletions tests/automated/integration/api/_helpers/RequestValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,16 @@ async def get_current_task_status(self) -> GetTaskStatusResponseInfo:

async def get_next_url_for_all_annotations(
self,
batch_id: Optional[int] = None
batch_id: int | None = None,
anno_url_id: int | None = None
) -> GetNextURLForAllAnnotationResponse:
params = {}
update_if_not_none(
target=params,
source={"batch_id": batch_id}
source={
"batch_id": batch_id,
"anno_url_id": anno_url_id
}
)
data = self.get(
url=f"/annotate/all",
Expand All @@ -333,12 +337,16 @@ async def post_all_annotations_and_get_next(
self,
url_id: int,
all_annotations_post_info: AllAnnotationPostInfo,
batch_id: Optional[int] = None,
batch_id: int | None = None,
anno_url_id: int | None = None
) -> GetNextURLForAllAnnotationResponse:
params = {}
update_if_not_none(
target=params,
source={"batch_id": batch_id}
source={
"batch_id": batch_id,
"anno_url_id": anno_url_id
}
)
data = self.post(
url=f"/annotate/all/{url_id}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def test_annotate_all(
response: GetNextURLForAllAnnotationResponse = await adb_client.run_query_builder(
GetNextURLForAllAnnotationQueryBuilder(
batch_id=None,
user_id=99
user_id=99,
)
)
user_suggestions: list[LocationAnnotationUserSuggestion] = \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest

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

View workflow job for this annotation

GitHub Actions / flake8

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

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

from src.api.endpoints.annotate.all.post.models.request import AllAnnotationPostInfo
from src.db.client.async_ import AsyncDatabaseClient
from src.db.models.impl.flag.url_validated.enums import URLType
from tests.helpers.api_test_helper import APITestHelper
from tests.helpers.setup.final_review.core import setup_for_get_next_url_for_final_review


@pytest.mark.asyncio
async def test_annotate_all_post_batch_filtering(api_test_helper: APITestHelper):
"""
Test that URL filtering works when getting and posting annotations
"""
ath = api_test_helper
adb_client: AsyncDatabaseClient = ath.adb_client()

Check warning on line 16 in tests/automated/integration/api/annotate/all/test_url_filtering.py

View workflow job for this annotation

GitHub Actions / flake8

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

local variable 'adb_client' is assigned to but never used
Raw output
./tests/automated/integration/api/annotate/all/test_url_filtering.py:16:5: F841 local variable 'adb_client' is assigned to but never used

setup_info_1 = await setup_for_get_next_url_for_final_review(

Check failure on line 18 in tests/automated/integration/api/annotate/all/test_url_filtering.py

View workflow job for this annotation

GitHub Actions / flake8

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

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

Check failure on line 18 in tests/automated/integration/api/annotate/all/test_url_filtering.py

View workflow job for this annotation

GitHub Actions / flake8

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

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

Check warning on line 22 in tests/automated/integration/api/annotate/all/test_url_filtering.py

View workflow job for this annotation

GitHub Actions / flake8

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

local variable 'setup_info_2' is assigned to but never used
Raw output
./tests/automated/integration/api/annotate/all/test_url_filtering.py:22:5: F841 local variable 'setup_info_2' is assigned to but never used
db_data_creator=ath.db_data_creator, include_user_annotations=False
)
setup_info_3 = await setup_for_get_next_url_for_final_review(
db_data_creator=ath.db_data_creator, include_user_annotations=False
)
url_mapping_3 = setup_info_3.url_mapping

get_response_2 = await ath.request_validator.get_next_url_for_all_annotations(
batch_id=setup_info_3.batch_id,
anno_url_id=url_mapping_3.url_id
)
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(
url_id=url_mapping_1.url_id,
anno_url_id=url_mapping_3.url_id,
all_annotations_post_info=AllAnnotationPostInfo(
suggested_status=URLType.NOT_RELEVANT,
)
)

assert post_response_3.next_annotation.url_info.url_id == url_mapping_3.url_id

Check warning on line 44 in tests/automated/integration/api/annotate/all/test_url_filtering.py

View workflow job for this annotation

GitHub Actions / flake8

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

no newline at end of file
Raw output
./tests/automated/integration/api/annotate/all/test_url_filtering.py:44:83: W292 no newline at end of file