Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create separate test file, which will be deleted later #27

Merged
merged 3 commits into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
]
}