From a97333c4d6536d28aedc0d0b787e9bdf0864f6ae Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Sat, 8 Feb 2025 15:19:16 +0000 Subject: [PATCH] drops /sheet/archive API token endpoint --- src/endpoints/sheet.py | 18 +++----------- src/tests/endpoints/test_sheet.py | 40 ------------------------------- 2 files changed, 3 insertions(+), 55 deletions(-) diff --git a/src/endpoints/sheet.py b/src/endpoints/sheet.py index 95731f0..e479ee9 100644 --- a/src/endpoints/sheet.py +++ b/src/endpoints/sheet.py @@ -7,7 +7,7 @@ from sqlalchemy.orm import Session from db.user_state import UserState from shared.task_messaging import get_celery -from web.security import token_api_key_auth, get_user_state +from web.security import get_user_state from db import schemas, crud from db.database import get_db_dependency @@ -74,18 +74,6 @@ def archive_user_sheet( if not user.can_manually_trigger(sheet.group_id): raise HTTPException(status_code=429, detail="User cannot manually trigger sheet archiving in this group.") - task = celery.signature("create_sheet_task", args=[schemas.SubmitSheet(sheet_id=id, author_id=user.email, group=sheet.group_id).model_dump_json()]).delay() + task = celery.signature("create_sheet_task", args=[schemas.SubmitSheet(sheet_id=id, author_id=user.email, group_id=sheet.group_id).model_dump_json()]).delay() - return JSONResponse({"id": task.id}, status_code=201) - - -@sheet_router.post("/archive", status_code=201, summary="Trigger an archiving task for any GSheet with an API token.", response_description="task_id for the archiving task.") -def archive_sheet( - sheet: schemas.SubmitSheet, - auth=Depends(token_api_key_auth) -) -> schemas.Task: - sheet.author_id = sheet.author_id or "api-endpoint" - if not sheet.sheet_id: - raise HTTPException(status_code=422, detail=f"sheet id is required") - task = celery.signature("create_sheet_task", args=[sheet.model_dump_json()]).delay() - return JSONResponse({"id": task.id}, status_code=201) + return JSONResponse({"id": task.id}, status_code=201) \ No newline at end of file diff --git a/src/tests/endpoints/test_sheet.py b/src/tests/endpoints/test_sheet.py index 81d2cc3..5d43b65 100644 --- a/src/tests/endpoints/test_sheet.py +++ b/src/tests/endpoints/test_sheet.py @@ -12,7 +12,6 @@ def test_endpoints_no_auth(client, test_no_auth): test_no_auth(client.get, "/sheet/mine") test_no_auth(client.delete, "/sheet/123-sheet-id") test_no_auth(client.post, "/sheet/123-sheet-id/archive") - test_no_auth(client.post, "/sheet/archive") def test_create_sheet_endpoint(app_with_auth, db_session): @@ -192,42 +191,3 @@ class TestArchiveUserSheetEndpoint: r = client_with_auth.post("/sheet/123-sheet-id/archive") assert r.status_code == 429 assert r.json() == {"detail": "User cannot manually trigger sheet archiving in this group."} - - -class TestTokenArchiveEndpoint: - - def test_user_auth(self, client_with_auth, test_no_auth): - test_no_auth(client_with_auth.post, "/sheet/archive") - - def test_missing_data(self, client_with_token): - r = client_with_token.post("/sheet/archive", json={}) - assert r.status_code == 422 - assert r.json() == {"detail": "sheet id is required"} - - @patch("endpoints.sheet.celery", return_value=MagicMock()) - def test_normal_flow(self, m_celery, client_with_token): - m_signature = MagicMock() - m_signature.delay.return_value = TaskResult(id="123-456-789", status="PENDING", result="") - m_celery.signature.return_value = m_signature - - # minimum data - response = client_with_token.post("/sheet/archive", json={"sheet_id": "123-sheet-id"}) - assert response.status_code == 201 - assert response.json() == {'id': '123-456-789'} - - m_celery.signature.assert_called_once() - m_signature.delay.assert_called_once() - called_val = m_celery.signature.call_args - assert called_val[0][0] == "create_sheet_task" - assert json.loads(called_val[1]['args'][0]) == {"sheet_id": "123-sheet-id", "sheet_name": None, "public": False, "author_id": "api-endpoint", "group_id": None, "tags": [], "columns": {}, "header": 1} - - # maximum data - response = client_with_token.post("/sheet/archive", json={"sheet_id": "123-sheet-id", "sheet_name": "768-sheet-name", "author_id": "birdman@example.com", "header": 2, "public": True, "group_id": "456-group-id", "tags": ["tag1"], "columns": {"col1": "type1"}}) - assert response.status_code == 201 - assert response.json() == {'id': '123-456-789'} - - m_celery.signature.call_count == 2 - m_signature.delay.call_count == 2 - called_val = m_celery.signature.call_args - assert called_val[0][0] == "create_sheet_task" - assert json.loads(called_val[1]['args'][0]) == {"sheet_id": "123-sheet-id", "sheet_name": "768-sheet-name", "public": True, "author_id": "birdman@example.com", "group_id": "456-group-id", "tags": ["tag1"], "columns": {"col1": "type1"}, "header": 2}