mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-11 21:18:35 +03:00
new tests and abstractions
This commit is contained in:
19
src/tests/endpoints/test_interopreability.py
Normal file
19
src/tests/endpoints/test_interopreability.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import json
|
||||
|
||||
|
||||
def test_submit_manual_archive_unauthenticated(client, test_no_auth):
|
||||
test_no_auth(client.post, "/interop/submit-archive")
|
||||
|
||||
|
||||
def test_submit_manual_archive(client_with_auth):
|
||||
aa_metadata = json.dumps({"status": "test: success", "metadata": {"url": "http://example.com"}, "media": []})
|
||||
|
||||
r = client_with_auth.post("/interop/submit-archive", json={"result": aa_metadata, "public": False, "author_id": "jerry@gmail.com", "group_id": None, "tags": ["test"]})
|
||||
assert r.status_code == 201
|
||||
assert "id" in r.json()
|
||||
|
||||
# cannot have the same URL twice
|
||||
aa_metadata = json.dumps({"status": "test: success", "metadata": {"url": "http://example.com"}, "media": [{"filename": "fn1", "urls": ["http://example.com", "http://example.com"]}]})
|
||||
r = client_with_auth.post("/interop/submit-archive", json={"result": aa_metadata, "public": False, "author_id": "jerry@gmail.com", "group_id": None, "tags": ["test"]})
|
||||
assert r.status_code == 422
|
||||
assert r.json() == {"detail": "Cannot insert into DB due to integrity error"}
|
||||
@@ -6,18 +6,9 @@ from unittest.mock import patch
|
||||
|
||||
from db.schemas import ArchiveCreate, TaskResult
|
||||
|
||||
NO_AUTH = {'detail': 'Not authenticated'}
|
||||
|
||||
|
||||
def test_archive_url_unauthenticated(client):
|
||||
response = client.post("/url/archive")
|
||||
assert response.status_code == 403
|
||||
assert response.json() == NO_AUTH
|
||||
|
||||
# this will call archive/{id}
|
||||
response = client.get("/url/archive")
|
||||
assert response.status_code == 403
|
||||
assert response.json() == NO_AUTH
|
||||
def test_archive_url_unauthenticated(client, test_no_auth):
|
||||
test_no_auth(client.post, "/url/archive")
|
||||
test_no_auth(client.get, "/url/archive")
|
||||
|
||||
|
||||
@patch("worker.create_archive_task.delay", return_value=TaskResult(id="123-456-789", status="PENDING", result=""))
|
||||
@@ -36,10 +27,8 @@ def test_archive_url(m1, client_with_auth):
|
||||
assert json.loads(called_val) == {"id": None, "url": "https://example.com", "result": None, "public": True, "author_id": "rick@example.com", "group_id": None, "tags": [], "rearchive": True}
|
||||
|
||||
|
||||
def test_search_by_url_unauthenticated(client):
|
||||
response = client.get("/url/search")
|
||||
assert response.status_code == 403
|
||||
assert response.json() == NO_AUTH
|
||||
def test_search_by_url_unauthenticated(client, test_no_auth):
|
||||
test_no_auth(client.get, "/url/search")
|
||||
|
||||
|
||||
def test_search_by_url(client_with_auth, db_session):
|
||||
@@ -81,10 +70,8 @@ def test_search_by_url(client_with_auth, db_session):
|
||||
assert len(response.json()) == 10
|
||||
|
||||
|
||||
def test_latest_unauthenticated(client):
|
||||
response = client.get("/url/latest")
|
||||
assert response.status_code == 403
|
||||
assert response.json() == NO_AUTH
|
||||
def test_latest_unauthenticated(client, test_no_auth):
|
||||
test_no_auth(client.get, "/url/latest")
|
||||
|
||||
|
||||
def test_latest(client_with_auth, db_session):
|
||||
@@ -116,10 +103,8 @@ def test_latest(client_with_auth, db_session):
|
||||
assert len(response.json()) == 2
|
||||
|
||||
|
||||
def test_lookup_unauthenticated(client):
|
||||
response = client.get("/url/123-456-789")
|
||||
assert response.status_code == 403
|
||||
assert response.json() == NO_AUTH
|
||||
def test_lookup_unauthenticated(client, test_no_auth):
|
||||
test_no_auth(client.get, "/url/123-456-789")
|
||||
|
||||
|
||||
def test_lookup(client_with_auth, db_session):
|
||||
@@ -144,10 +129,8 @@ def test_lookup(client_with_auth, db_session):
|
||||
assert j["rearchive"] == True
|
||||
|
||||
|
||||
def test_delete_task_unauthenticated(client):
|
||||
response = client.delete("/url/123-456-789")
|
||||
assert response.status_code == 403
|
||||
assert response.json() == NO_AUTH
|
||||
def test_delete_task_unauthenticated(client, test_no_auth):
|
||||
test_no_auth(client.delete, "/url/123-456-789")
|
||||
|
||||
|
||||
def test_delete_task(client_with_auth, db_session):
|
||||
|
||||
Reference in New Issue
Block a user