pssecret-server/tests/integration/test_api.py

41 lines
1.1 KiB
Python
Raw Permalink Normal View History

from fastapi.testclient import TestClient
from tests.factories import SecretFactory
2025-01-06 16:27:20 +00:00
def test_empty_secret_is_not_accepted(client: TestClient):
response = client.post("/secret", json={"data": ""})
assert response.status_code == 422
assert "data" in response.text
def test_store_secret_returns_key(client: TestClient):
response = client.post("/secret", json=dict(SecretFactory().build()))
assert response.json()["key"]
def test_stored_secret_could_be_retrieved(client: TestClient):
secret = SecretFactory().build()
response = client.post("/secret", json=dict(secret))
retrieval_key: str = response.json()["key"]
response = client.get(f"/secret/{retrieval_key}")
assert response.json()["data"] == secret.data
def test_stored_secret_could_be_retrieved_only_once(client: TestClient):
secret = SecretFactory().build()
response = client.post("/secret", json=dict(secret))
retrieval_key: str = response.json()["key"]
client.get(f"/secret/{retrieval_key}")
response = client.get(f"/secret/{retrieval_key}")
assert response.status_code == 404
assert secret.data not in response.text