pssecret-server/tests/integration/test_api.py
Ivan Golikov 8266c95cd9 Integration tests (#3)
Reviewed-on: root/pssecret#3
Co-authored-by: Ivan Golikov <root@ivnglkv.me>
Co-committed-by: Ivan Golikov <root@ivnglkv.me>
2025-01-01 18:18:38 +00:00

33 lines
965 B
Python

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