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
4 changes: 3 additions & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from api.routes.collector import collector_router
from api.routes.review import review_router
from api.routes.root import root_router
from api.routes.search import search_router
from api.routes.task import task_router
from api.routes.url import url_router
from collector_db.AsyncDatabaseClient import AsyncDatabaseClient
Expand Down Expand Up @@ -128,7 +129,8 @@ async def redirect_docs():
annotate_router,
url_router,
task_router,
review_router
review_router,
search_router
]

for router in routers:
Expand Down
20 changes: 20 additions & 0 deletions api/routes/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from fastapi import APIRouter, Query, Depends

Check warning on line 1 in api/routes/search.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] api/routes/search.py#L1 <100>

Missing docstring in public module
Raw output
./api/routes/search.py:1:1: D100 Missing docstring in public module

from api.dependencies import get_async_core
from core.AsyncCore import AsyncCore
from core.DTOs.SearchURLResponse import SearchURLResponse
from security_manager.SecurityManager import get_access_info, AccessInfo

search_router = APIRouter(prefix="/search", tags=["search"])


@search_router.get("/url")
async def search_url(
url: str = Query(description="The URL to search for"),
access_info: AccessInfo = Depends(get_access_info),

Check warning on line 14 in api/routes/search.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] api/routes/search.py#L14 <100>

Unused argument 'access_info'
Raw output
./api/routes/search.py:14:5: U100 Unused argument 'access_info'
async_core: AsyncCore = Depends(get_async_core),
) -> SearchURLResponse:
"""
Search for a URL in the database
"""
return await async_core.search_for_url(url)

Check warning on line 20 in api/routes/search.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] api/routes/search.py#L20 <292>

no newline at end of file
Raw output
./api/routes/search.py:20:48: W292 no newline at end of file
16 changes: 16 additions & 0 deletions collector_db/AsyncDatabaseClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
GetURLsResponseInnerInfo
from core.DTOs.ManualBatchInputDTO import ManualBatchInputDTO
from core.DTOs.ManualBatchResponseDTO import ManualBatchResponseDTO
from core.DTOs.SearchURLResponse import SearchURLResponse
from core.DTOs.URLAgencySuggestionInfo import URLAgencySuggestionInfo
from core.DTOs.task_data_objects.AgencyIdentificationTDO import AgencyIdentificationTDO
from core.DTOs.task_data_objects.SubmitApprovedURLTDO import SubmitApprovedURLTDO, SubmittedURLInfo
Expand Down Expand Up @@ -1778,3 +1779,18 @@
duplicate_urls=duplicate_urls
)

@session_manager
async def search_for_url(self, session: AsyncSession, url: str) -> SearchURLResponse:

Check warning on line 1783 in collector_db/AsyncDatabaseClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/AsyncDatabaseClient.py#L1783 <102>

Missing docstring in public method
Raw output
./collector_db/AsyncDatabaseClient.py:1783:1: D102 Missing docstring in public method
query = select(URL).where(URL.url == url)
raw_results = await session.execute(query)
url = raw_results.scalars().one_or_none()
if url is None:
return SearchURLResponse(
found=False,
url_id=None
)
return SearchURLResponse(
found=True,
url_id=url.id
)

Check warning on line 1796 in collector_db/AsyncDatabaseClient.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/AsyncDatabaseClient.py#L1796 <391>

blank line at end of file
Raw output
./collector_db/AsyncDatabaseClient.py:1796:1: W391 blank line at end of file
3 changes: 3 additions & 0 deletions core/AsyncCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from core.DTOs.ManualBatchInputDTO import ManualBatchInputDTO
from core.DTOs.ManualBatchResponseDTO import ManualBatchResponseDTO
from core.DTOs.MessageResponse import MessageResponse
from core.DTOs.SearchURLResponse import SearchURLResponse
from core.TaskManager import TaskManager
from core.enums import BatchStatus, RecordType

Expand Down Expand Up @@ -282,3 +283,5 @@
dto=dto
)

async def search_for_url(self, url: str) -> SearchURLResponse:

Check warning on line 286 in core/AsyncCore.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] core/AsyncCore.py#L286 <102>

Missing docstring in public method
Raw output
./core/AsyncCore.py:286:1: D102 Missing docstring in public method
return await self.adb_client.search_for_url(url)
8 changes: 8 additions & 0 deletions core/DTOs/SearchURLResponse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Optional

Check warning on line 1 in core/DTOs/SearchURLResponse.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] core/DTOs/SearchURLResponse.py#L1 <100>

Missing docstring in public module
Raw output
./core/DTOs/SearchURLResponse.py:1:1: D100 Missing docstring in public module

from pydantic import BaseModel


class SearchURLResponse(BaseModel):

Check warning on line 6 in core/DTOs/SearchURLResponse.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] core/DTOs/SearchURLResponse.py#L6 <101>

Missing docstring in public class
Raw output
./core/DTOs/SearchURLResponse.py:6:1: D101 Missing docstring in public class
found: bool
url_id: Optional[int] = None

Check warning on line 8 in core/DTOs/SearchURLResponse.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] core/DTOs/SearchURLResponse.py#L8 <292>

no newline at end of file
Raw output
./core/DTOs/SearchURLResponse.py:8:33: W292 no newline at end of file
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from core.DTOs.MessageResponse import MessageResponse
from core.DTOs.RecordTypeAnnotationPostInfo import RecordTypeAnnotationPostInfo
from core.DTOs.RelevanceAnnotationPostInfo import RelevanceAnnotationPostInfo
from core.DTOs.SearchURLResponse import SearchURLResponse
from core.enums import BatchStatus
from util.helper_functions import update_if_not_none

Expand Down Expand Up @@ -385,4 +386,11 @@
url="/collector/manual",
json=dto.model_dump(mode='json'),
)
return ManualBatchResponseDTO(**data)
return ManualBatchResponseDTO(**data)

async def search_url(self, url: str) -> SearchURLResponse:

Check warning on line 391 in tests/test_automated/integration/api/helpers/RequestValidator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/api/helpers/RequestValidator.py#L391 <102>

Missing docstring in public method
Raw output
./tests/test_automated/integration/api/helpers/RequestValidator.py:391:1: D102 Missing docstring in public method
data = self.get(
url=f"/search/url",

Check warning on line 393 in tests/test_automated/integration/api/helpers/RequestValidator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/api/helpers/RequestValidator.py#L393 <541>

f-string is missing placeholders
Raw output
./tests/test_automated/integration/api/helpers/RequestValidator.py:393:17: F541 f-string is missing placeholders
params={"url": url}
)
return SearchURLResponse(**data)

Check warning on line 396 in tests/test_automated/integration/api/helpers/RequestValidator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/api/helpers/RequestValidator.py#L396 <292>

no newline at end of file
Raw output
./tests/test_automated/integration/api/helpers/RequestValidator.py:396:41: W292 no newline at end of file
23 changes: 23 additions & 0 deletions tests/test_automated/integration/api/test_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest

Check warning on line 1 in tests/test_automated/integration/api/test_search.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/api/test_search.py#L1 <100>

Missing docstring in public module
Raw output
./tests/test_automated/integration/api/test_search.py:1:1: D100 Missing docstring in public module

from core.DTOs.SearchURLResponse import SearchURLResponse


@pytest.mark.asyncio
async def test_search_url(api_test_helper):

Check warning on line 7 in tests/test_automated/integration/api/test_search.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/api/test_search.py#L7 <103>

Missing docstring in public function
Raw output
./tests/test_automated/integration/api/test_search.py:7:1: D103 Missing docstring in public function
ath = api_test_helper

# Create a batch with 1 URL
creation_info = await ath.db_data_creator.batch_and_urls(url_count=1, with_html_content=False)

# Search for that URL and locate it
response: SearchURLResponse = await ath.request_validator.search_url(url=creation_info.urls[0])

assert response.found
assert response.url_id == creation_info.url_ids[0]

# Search for a non-existent URL
response: SearchURLResponse = await ath.request_validator.search_url(url="http://doesnotexist.com")

assert not response.found
assert response.url_id is None

Check warning on line 23 in tests/test_automated/integration/api/test_search.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/api/test_search.py#L23 <292>

no newline at end of file
Raw output
./tests/test_automated/integration/api/test_search.py:23:35: W292 no newline at end of file