getting started with backend and uploader
This commit is contained in:
commit
1e1000268a
50 files changed
+2237
No files matched your search
@@ -0,0 +1,38 @@
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from fdhview.core.config import settings
|
||||
|
||||
AUTH = ("username", settings.api_password)
|
||||
|
||||
|
||||
def test_upload_requires_auth(client: TestClient):
|
||||
response = client.post("/admin/upload")
|
||||
assert response.status_code == 401
|
||||
|
||||
|
||||
def test_upload_requests_wrong_ext(client: TestClient):
|
||||
response = client.post(
|
||||
"/admin/upload",
|
||||
auth=AUTH,
|
||||
files={"file": ("test.txt", b"not xml", "text/plain")})
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_upload_requests_bad_xml(client: TestClient):
|
||||
response = client.post(
|
||||
"/admin/upload",
|
||||
auth=AUTH,
|
||||
files={"file": ("test.xml", b"not xml", "application/xml")})
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_upload_succeeds_with_valid_xml(client: TestClient):
|
||||
minimal_xml = Path("tests/data/minimal.xml").read_bytes()
|
||||
response = client.post(
|
||||
"/admin/upload",
|
||||
auth=AUTH,
|
||||
files={"file": ("minimal.xml", minimal_xml, "application/xml")})
|
||||
assert response.status_code == 200
|
||||
assert response.json()['filename'] == "minimal.xml"
|
||||
Reference in new issue
Block a user