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
1 change: 1 addition & 0 deletions collector_db/AsyncDatabaseClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async def get_next_url_for_user_annotation(
select(
URL,
)
.where(URL.outcome == URLStatus.PENDING.value)
.where(exists(select(URLHTMLContent).where(URLHTMLContent.url_id == URL.id)))
# URL must not have metadata annotation by this user
.where(
Expand Down
4 changes: 3 additions & 1 deletion collector_db/StatementComposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ def exclude_urls_with_agency_suggestions(
# Aliases for clarity
AutomatedSuggestion = aliased(AutomatedUrlAgencySuggestion)

# Exclude if automated suggestions exist
statement = statement.where(
~exists().where(AutomatedSuggestion.url_id == URL.id)
) # Exclude if automated suggestions exist
)
# Exclude if confirmed agencies exist
statement = statement.where(
~exists().where(ConfirmedURLAgency.url_id == URL.id)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

from collector_db.AsyncDatabaseClient import AsyncDatabaseClient
from collector_db.DTOs.BatchInfo import BatchInfo
from collector_db.DTOs.InsertURLsInfo import InsertURLsInfo
from collector_db.DTOs.LogInfo import LogInfo
from collector_db.DTOs.URLErrorInfos import URLErrorPydanticInfo
from collector_db.DTOs.URLInfo import URLInfo
from collector_db.DTOs.URLMetadataInfo import URLMetadataInfo
from collector_db.enums import URLMetadataAttributeType, ValidationStatus, ValidationSource
from collector_db.models import URL, ApprovingUserURL, URLOptionalDataSourceMetadata, ConfirmedURLAgency
from collector_db.models import URL, ApprovingUserURL, URLOptionalDataSourceMetadata, ConfirmedURLAgency, \

Check warning on line 15 in tests/test_automated/integration/collector_db/test_db_client.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/collector_db/test_db_client.py#L15 <401>

'collector_db.models.UserRelevantSuggestion' imported but unused
Raw output
./tests/test_automated/integration/collector_db/test_db_client.py:15:1: F401 'collector_db.models.UserRelevantSuggestion' imported but unused
UserRelevantSuggestion
from collector_manager.enums import URLStatus
from core.DTOs.FinalReviewApprovalInfo import FinalReviewApprovalInfo
from core.enums import BatchStatus, RecordType, SuggestionType
Expand Down Expand Up @@ -421,3 +423,67 @@
user_id=1
)

@pytest.mark.asyncio
async def test_get_next_url_for_user_relevance_annotation_pending(

Check warning on line 427 in tests/test_automated/integration/collector_db/test_db_client.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/collector_db/test_db_client.py#L427 <103>

Missing docstring in public function
Raw output
./tests/test_automated/integration/collector_db/test_db_client.py:427:1: D103 Missing docstring in public function
db_data_creator: DBDataCreator
):

batch_id = db_data_creator.batch()

# Create 2 URLs with outcome `pending`
iui: InsertURLsInfo = db_data_creator.urls(
batch_id=batch_id,
url_count=1,
outcome=URLStatus.PENDING
)

url_1 = iui.url_mappings[0]

# Add `Relevancy` attribute with value `True`
await db_data_creator.auto_relevant_suggestions(
url_id=url_1.url_id,
relevant=True
)

# Add HTML data
await db_data_creator.html_data([url_1.url_id])

adb_client = db_data_creator.adb_client
url = await adb_client.get_next_url_for_relevance_annotation(
user_id=1
)
assert url is not None

@pytest.mark.asyncio
async def test_get_next_url_for_user_relevance_annotation_validated(
db_data_creator: DBDataCreator
):
"""
A validated URL should not turn up in get_next_url_for_user_annotation
"""

batch_id = db_data_creator.batch()

# Create 2 URLs with outcome `pending`
iui: InsertURLsInfo = db_data_creator.urls(
batch_id=batch_id,
url_count=1,
outcome=URLStatus.VALIDATED
)

url_1 = iui.url_mappings[0]

# Add `Relevancy` attribute with value `True`
await db_data_creator.auto_relevant_suggestions(
url_id=url_1.url_id,
relevant=True
)

# Add HTML data
await db_data_creator.html_data([url_1.url_id])

adb_client = db_data_creator.adb_client
url = await adb_client.get_next_url_for_relevance_annotation(
user_id=1
)
assert url is None

Check warning on line 489 in tests/test_automated/integration/collector_db/test_db_client.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/collector_db/test_db_client.py#L489 <292>

no newline at end of file
Raw output
./tests/test_automated/integration/collector_db/test_db_client.py:489:23: W292 no newline at end of file