40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
from tests.factories import SecretFactory
|
|
|
|
|
|
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
|