|
3 | 3 |
|
4 | 4 | client = TestClient(app)
|
5 | 5 |
|
| 6 | +file = None |
| 7 | + |
6 | 8 |
|
7 | 9 | def test_get_health_route():
|
8 | 10 | data = {"status": "ok"}
|
@@ -38,12 +40,46 @@ def test_post_web_route():
|
38 | 40 | data = 'This is a test data'
|
39 | 41 | form_data = {'content': data}
|
40 | 42 | response = client.post("/web", data=form_data)
|
| 43 | + global file |
| 44 | + file = str(response.url).split("/")[-1] |
41 | 45 | assert response.status_code == 200
|
42 | 46 | assert response.text == data
|
43 | 47 |
|
44 | 48 |
|
45 | 49 | 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}") |
48 | 52 | assert response.status_code == 200
|
49 | 53 | 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