Skip to content

Commit 9ff1e31

Browse files
authored
Merge pull request #178 from Police-Data-Accessibility-Project/mc_177_validated_urls
fix(database): Fix bug causing validated URLs to show up for some annotations
2 parents 9dc2d1e + d99d189 commit 9ff1e31

3 files changed

Lines changed: 71 additions & 2 deletions

File tree

collector_db/AsyncDatabaseClient.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ async def get_next_url_for_user_annotation(
126126
select(
127127
URL,
128128
)
129+
.where(URL.outcome == URLStatus.PENDING.value)
129130
.where(exists(select(URLHTMLContent).where(URLHTMLContent.url_id == URL.id)))
130131
# URL must not have metadata annotation by this user
131132
.where(

collector_db/StatementComposer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ def exclude_urls_with_agency_suggestions(
5555
# Aliases for clarity
5656
AutomatedSuggestion = aliased(AutomatedUrlAgencySuggestion)
5757

58+
# Exclude if automated suggestions exist
5859
statement = statement.where(
5960
~exists().where(AutomatedSuggestion.url_id == URL.id)
60-
) # Exclude if automated suggestions exist
61+
)
62+
# Exclude if confirmed agencies exist
6163
statement = statement.where(
6264
~exists().where(ConfirmedURLAgency.url_id == URL.id)
6365
)

tests/test_automated/integration/collector_db/test_db_client.py

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
from collector_db.AsyncDatabaseClient import AsyncDatabaseClient
88
from collector_db.DTOs.BatchInfo import BatchInfo
9+
from collector_db.DTOs.InsertURLsInfo import InsertURLsInfo
910
from collector_db.DTOs.LogInfo import LogInfo
1011
from collector_db.DTOs.URLErrorInfos import URLErrorPydanticInfo
1112
from collector_db.DTOs.URLInfo import URLInfo
1213
from collector_db.DTOs.URLMetadataInfo import URLMetadataInfo
1314
from collector_db.enums import URLMetadataAttributeType, ValidationStatus, ValidationSource
14-
from collector_db.models import URL, ApprovingUserURL, URLOptionalDataSourceMetadata, ConfirmedURLAgency
15+
from collector_db.models import URL, ApprovingUserURL, URLOptionalDataSourceMetadata, ConfirmedURLAgency, \
16+
UserRelevantSuggestion
1517
from collector_manager.enums import URLStatus
1618
from core.DTOs.FinalReviewApprovalInfo import FinalReviewApprovalInfo
1719
from core.enums import BatchStatus, RecordType, SuggestionType
@@ -421,3 +423,67 @@ async def test_approval_url_error(db_data_creator: DBDataCreator):
421423
user_id=1
422424
)
423425

426+
@pytest.mark.asyncio
427+
async def test_get_next_url_for_user_relevance_annotation_pending(
428+
db_data_creator: DBDataCreator
429+
):
430+
431+
batch_id = db_data_creator.batch()
432+
433+
# Create 2 URLs with outcome `pending`
434+
iui: InsertURLsInfo = db_data_creator.urls(
435+
batch_id=batch_id,
436+
url_count=1,
437+
outcome=URLStatus.PENDING
438+
)
439+
440+
url_1 = iui.url_mappings[0]
441+
442+
# Add `Relevancy` attribute with value `True`
443+
await db_data_creator.auto_relevant_suggestions(
444+
url_id=url_1.url_id,
445+
relevant=True
446+
)
447+
448+
# Add HTML data
449+
await db_data_creator.html_data([url_1.url_id])
450+
451+
adb_client = db_data_creator.adb_client
452+
url = await adb_client.get_next_url_for_relevance_annotation(
453+
user_id=1
454+
)
455+
assert url is not None
456+
457+
@pytest.mark.asyncio
458+
async def test_get_next_url_for_user_relevance_annotation_validated(
459+
db_data_creator: DBDataCreator
460+
):
461+
"""
462+
A validated URL should not turn up in get_next_url_for_user_annotation
463+
"""
464+
465+
batch_id = db_data_creator.batch()
466+
467+
# Create 2 URLs with outcome `pending`
468+
iui: InsertURLsInfo = db_data_creator.urls(
469+
batch_id=batch_id,
470+
url_count=1,
471+
outcome=URLStatus.VALIDATED
472+
)
473+
474+
url_1 = iui.url_mappings[0]
475+
476+
# Add `Relevancy` attribute with value `True`
477+
await db_data_creator.auto_relevant_suggestions(
478+
url_id=url_1.url_id,
479+
relevant=True
480+
)
481+
482+
# Add HTML data
483+
await db_data_creator.html_data([url_1.url_id])
484+
485+
adb_client = db_data_creator.adb_client
486+
url = await adb_client.get_next_url_for_relevance_annotation(
487+
user_id=1
488+
)
489+
assert url is None

0 commit comments

Comments
 (0)