mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-12 13:38:33 +03:00
Standardize router names (#70)
This commit is contained in:
@@ -15,7 +15,7 @@ def test_submit_manual_archive_not_user_auth(client_with_auth, test_no_auth):
|
||||
|
||||
|
||||
@patch(
|
||||
"app.web.endpoints.interoperability.business_logic",
|
||||
"app.web.routers.interoperability.business_logic",
|
||||
return_value=MagicMock(
|
||||
get_store_archive_until=MagicMock(return_value=datetime)
|
||||
),
|
||||
@@ -103,7 +103,7 @@ def test_submit_manual_archive_invalid_json(client_with_token):
|
||||
|
||||
|
||||
@patch(
|
||||
"app.web.endpoints.interoperability.business_logic.get_store_archive_until",
|
||||
"app.web.routers.interoperability.business_logic.get_store_archive_until",
|
||||
side_effect=AssertionError("AssertionError"),
|
||||
)
|
||||
def test_submit_manual_archive_no_store_until(
|
||||
@@ -4,6 +4,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.shared.constants import STATUS_PENDING
|
||||
from app.shared.db import models
|
||||
from app.shared.schemas import TaskResult
|
||||
from app.web.db.user_state import UserState
|
||||
@@ -184,7 +185,7 @@ def test_delete_sheet_endpoint(client_with_auth, db_session):
|
||||
|
||||
|
||||
class TestArchiveUserSheetEndpoint:
|
||||
@patch("app.web.endpoints.sheet.celery", return_value=MagicMock())
|
||||
@patch("app.web.routers.sheet.celery", return_value=MagicMock())
|
||||
def test_normal_flow(self, m_celery, client_with_auth, db_session):
|
||||
db_session.add(
|
||||
models.Sheet(
|
||||
@@ -199,7 +200,7 @@ class TestArchiveUserSheetEndpoint:
|
||||
|
||||
m_signature = MagicMock()
|
||||
m_signature.apply_async.return_value = TaskResult(
|
||||
id="123-taskid", status="PENDING", result=""
|
||||
id="123-taskid", status=STATUS_PENDING, result=""
|
||||
)
|
||||
m_celery.signature.return_value = m_signature
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
from http import HTTPStatus
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.shared.constants import STATUS_FAILURE, STATUS_PENDING, STATUS_SUCCESS
|
||||
|
||||
|
||||
def test_endpoint_task_status_no_auth(client, test_no_auth):
|
||||
test_no_auth(client.get, "/task/test-task-id")
|
||||
|
||||
|
||||
@patch("app.web.endpoints.task.AsyncResult")
|
||||
@patch("app.web.routers.task.AsyncResult")
|
||||
def test_get_status_success(mock_async_result, client_with_auth):
|
||||
mock_async_result.return_value.status = "SUCCESS"
|
||||
mock_async_result.return_value.status = STATUS_SUCCESS
|
||||
mock_async_result.return_value.result = {"data": "some result"}
|
||||
|
||||
response = client_with_auth.get("/task/test-task-id")
|
||||
@@ -16,14 +18,14 @@ def test_get_status_success(mock_async_result, client_with_auth):
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json() == {
|
||||
"id": "test-task-id",
|
||||
"status": "SUCCESS",
|
||||
"status": STATUS_SUCCESS,
|
||||
"result": {"data": "some result"},
|
||||
}
|
||||
|
||||
|
||||
@patch("app.web.endpoints.task.AsyncResult")
|
||||
@patch("app.web.routers.task.AsyncResult")
|
||||
def test_get_status_failure(mock_async_result, client_with_auth):
|
||||
mock_async_result.return_value.status = "FAILURE"
|
||||
mock_async_result.return_value.status = STATUS_FAILURE
|
||||
mock_async_result.return_value.result = Exception("Some error")
|
||||
|
||||
response = client_with_auth.get("/task/test-task-id")
|
||||
@@ -31,14 +33,14 @@ def test_get_status_failure(mock_async_result, client_with_auth):
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json() == {
|
||||
"id": "test-task-id",
|
||||
"status": "FAILURE",
|
||||
"status": STATUS_FAILURE,
|
||||
"result": {"error": "Some error"},
|
||||
}
|
||||
|
||||
|
||||
@patch("app.web.endpoints.task.AsyncResult")
|
||||
@patch("app.web.routers.task.AsyncResult")
|
||||
def test_get_status_pending(mock_async_result, client_with_auth):
|
||||
mock_async_result.return_value.status = "PENDING"
|
||||
mock_async_result.return_value.status = STATUS_PENDING
|
||||
mock_async_result.return_value.result = None
|
||||
|
||||
response = client_with_auth.get("/task/test-task-id")
|
||||
@@ -46,6 +48,6 @@ def test_get_status_pending(mock_async_result, client_with_auth):
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json() == {
|
||||
"id": "test-task-id",
|
||||
"status": "PENDING",
|
||||
"status": STATUS_PENDING,
|
||||
"result": None,
|
||||
}
|
||||
@@ -3,6 +3,7 @@ from http import HTTPStatus
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from app.shared import schemas
|
||||
from app.shared.constants import STATUS_PENDING
|
||||
from app.shared.db import worker_crud
|
||||
from app.shared.schemas import ArchiveCreate, TaskResult
|
||||
from app.web.config import ALLOW_ANY_EMAIL
|
||||
@@ -12,12 +13,12 @@ def test_archive_url_unauthenticated(client, test_no_auth):
|
||||
test_no_auth(client.post, "/url/archive")
|
||||
|
||||
|
||||
@patch("app.web.endpoints.url.UserState")
|
||||
@patch("app.web.endpoints.url.celery", return_value=MagicMock())
|
||||
@patch("app.web.routers.url.UserState")
|
||||
@patch("app.web.routers.url.celery", return_value=MagicMock())
|
||||
def test_archive_url(m_celery, m2, client_with_auth):
|
||||
m_signature = MagicMock()
|
||||
m_signature.apply_async.return_value = TaskResult(
|
||||
id="123-456-789", status="PENDING", result=""
|
||||
id="123-456-789", status=STATUS_PENDING, result=""
|
||||
)
|
||||
m_celery.signature.return_value = m_signature
|
||||
|
||||
@@ -123,7 +124,7 @@ def test_archive_url(m_celery, m2, client_with_auth):
|
||||
assert m_signature.apply_async.call_count == 2
|
||||
|
||||
|
||||
@patch("app.web.endpoints.url.UserState")
|
||||
@patch("app.web.routers.url.UserState")
|
||||
def test_archive_url_quotas(m1, client_with_auth):
|
||||
m_user_state = MagicMock()
|
||||
m1.return_value = m_user_state
|
||||
@@ -152,11 +153,11 @@ def test_archive_url_quotas(m1, client_with_auth):
|
||||
m_user_state.has_quota_max_monthly_mbs.assert_called_once()
|
||||
|
||||
|
||||
@patch("app.web.endpoints.url.celery", return_value=MagicMock())
|
||||
@patch("app.web.routers.url.celery", return_value=MagicMock())
|
||||
def test_archive_url_with_api_token(m_celery, client_with_token):
|
||||
m_signature = MagicMock()
|
||||
m_signature.apply_async.return_value = TaskResult(
|
||||
id="123-456-789", status="PENDING", result=""
|
||||
id="123-456-789", status=STATUS_PENDING, result=""
|
||||
)
|
||||
m_celery.signature.return_value = m_signature
|
||||
response = client_with_token.post(
|
||||
@@ -274,7 +275,7 @@ def test_search_by_url(client_with_auth, client_with_token, db_session):
|
||||
assert len(response.json()) == 10
|
||||
|
||||
|
||||
@patch("app.web.endpoints.url.UserState")
|
||||
@patch("app.web.routers.url.UserState")
|
||||
def test_search_no_read_access(mock_user_state, client_with_auth):
|
||||
mock_user_state.return_value.read = False
|
||||
mock_user_state.return_value.read_public = False
|
||||
@@ -40,7 +40,7 @@ def test_alembic(db_session):
|
||||
|
||||
|
||||
@patch(
|
||||
"app.web.endpoints.url.crud.soft_delete_archive",
|
||||
"app.web.routers.url.crud.soft_delete_archive",
|
||||
side_effect=Exception("mocked error"),
|
||||
)
|
||||
def test_logging_middleware(m1, client_with_auth):
|
||||
|
||||
Reference in New Issue
Block a user