Skip to content

Commit f4d6f69

Browse files
Merge pull request #27 from A91y/testenhancement1
fix: create separate test file, which will be deleted later
2 parents 80faa42 + 82948d6 commit f4d6f69

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

tests/test_api.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
client = TestClient(app)
55

6+
file = None
7+
68

79
def test_get_health_route():
810
data = {"status": "ok"}
@@ -38,12 +40,46 @@ def test_post_web_route():
3840
data = 'This is a test data'
3941
form_data = {'content': data}
4042
response = client.post("/web", data=form_data)
43+
global file
44+
file = str(response.url).split("/")[-1]
4145
assert response.status_code == 200
4246
assert response.text == data
4347

4448

4549
def test_delete_paste_route():
46-
expected_response = "File successfully deleted test"
47-
response = client.delete("/paste/test")
50+
expected_response = f"File successfully deleted {file}"
51+
response = client.delete(f"/paste/{file}")
4852
assert response.status_code == 200
4953
assert response.text == expected_response
54+
55+
56+
def test_post_file_route():
57+
response = client.post(
58+
"/file", files={"file": ("test.txt", b"test file content")})
59+
assert response.status_code == 201
60+
response_file_uuid = response.text
61+
response = client.get(f"/paste/{response_file_uuid}")
62+
assert response.status_code == 200
63+
assert response.text == "test file content"
64+
response = client.delete(f"/paste/{response_file_uuid}")
65+
assert response.status_code == 200
66+
assert response.text == f"File successfully deleted {response_file_uuid}"
67+
68+
69+
def test_post_file_route_failure():
70+
response = client.post("/file")
71+
assert response.status_code == 422 # Unprocessable Entity
72+
assert response.json() == {
73+
"detail": [
74+
{
75+
"type": "missing",
76+
"loc": [
77+
"body",
78+
"file"
79+
],
80+
"msg": "Field required",
81+
"input": None,
82+
"url": "https://errors.pydantic.dev/2.5/v/missing"
83+
}
84+
]
85+
}

0 commit comments

Comments
 (0)