Skip to content

Commit

Permalink
Merge pull request #27 from A91y/testenhancement1
Browse files Browse the repository at this point in the history
fix: create separate test file, which will be deleted later
  • Loading branch information
Mr-Sunglasses authored Dec 28, 2023
2 parents 80faa42 + 82948d6 commit f4d6f69
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

client = TestClient(app)

file = None


def test_get_health_route():
data = {"status": "ok"}
Expand Down Expand Up @@ -38,12 +40,46 @@ def test_post_web_route():
data = 'This is a test data'
form_data = {'content': data}
response = client.post("/web", data=form_data)
global file
file = str(response.url).split("/")[-1]
assert response.status_code == 200
assert response.text == data


def test_delete_paste_route():
expected_response = "File successfully deleted test"
response = client.delete("/paste/test")
expected_response = f"File successfully deleted {file}"
response = client.delete(f"/paste/{file}")
assert response.status_code == 200
assert response.text == expected_response


def test_post_file_route():
response = client.post(
"/file", files={"file": ("test.txt", b"test file content")})
assert response.status_code == 201
response_file_uuid = response.text
response = client.get(f"/paste/{response_file_uuid}")
assert response.status_code == 200
assert response.text == "test file content"
response = client.delete(f"/paste/{response_file_uuid}")
assert response.status_code == 200
assert response.text == f"File successfully deleted {response_file_uuid}"


def test_post_file_route_failure():
response = client.post("/file")
assert response.status_code == 422 # Unprocessable Entity
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": [
"body",
"file"
],
"msg": "Field required",
"input": None,
"url": "https://errors.pydantic.dev/2.5/v/missing"
}
]
}

0 comments on commit f4d6f69

Please sign in to comment.