pssecret-server/tests/integration/test_api.py

34 lines
965 B
Python
Raw Normal View History

from fastapi.testclient import TestClient
from tests.factories import SecretFactory
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