-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
76 lines (57 loc) · 2.1 KB
/
tests.py
File metadata and controls
76 lines (57 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import requests
import pytest
# CRUD
BASE_URL = "http://127.0.0.1:5000"
tasks = []
def test_create_task():
new_task_data = {
"title": "Test Task",
"description": "This is a test task.",
}
response = requests.post(f"{BASE_URL}/tasks", json=new_task_data)
assert response.status_code == 200
response_json = response.json()
assert "message" in response_json
assert "id" in response_json
tasks.append(response_json["id"])
def test_get_tasks():
response = requests.get(f"{BASE_URL}/tasks")
assert response.status_code == 200
response_json = response.json()
assert "tasks" in response_json
assert "total" in response_json
def test_get_task():
if tasks:
task_id = tasks[0]
response = requests.get(f"{BASE_URL}/tasks/{task_id}")
assert response.status_code == 200
response_json = response.json()
assert task_id == response_json["id"]
def test_update_task():
if tasks:
task_id = tasks[0]
payload = {
"title": "Updated Task",
"description": "This task has been updated.",
"completed": True,
}
response = requests.put(f"{BASE_URL}/tasks/{task_id}", json=payload)
assert response.status_code == 200
response_json = response.json()
assert "message" in response_json
# Nova requisição para garantir que a tarefa foi atualizada
response = requests.get(f"{BASE_URL}/tasks/{task_id}")
assert response.status_code == 200
response_json = response.json()
assert response_json["title"] == payload["title"]
assert response_json["description"] == payload["description"]
assert response_json["completed"] == payload["completed"]
def test_delete_task():
if tasks:
task_id = tasks[0]
response = requests.delete(f"{BASE_URL}/tasks/{task_id}")
assert response.status_code == 200
response_json = response.json()
assert "message" in response_json
response = requests.get(f"{BASE_URL}/tasks/{task_id}")
assert response.status_code == 404