-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtest_app.py
63 lines (51 loc) · 1.74 KB
/
test_app.py
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
import pytest
from flask import Flask
from app_service import AppService
@pytest.fixture
def app():
app = Flask(__name__)
app.config['TESTING'] = True
return app
@pytest.fixture
def client(app):
return app.test_client()
def test_home_route(client):
response = client.get('/')
assert response.status_code == 200
assert b"App Works!!!" in response.data
def test_get_tasks(client):
appService = AppService()
expected_response = appService.get_tasks()
response = client.get('/api/tasks')
assert response.status_code == 200
assert response.get_json() == expected_response
def test_create_task(client):
appService = AppService()
new_task = {
'id': 4,
'name': 'task4',
'description': 'This is task 4'
}
expected_response = appService.create_task(new_task)
response = client.post('/api/task', json=new_task)
assert response.status_code == 200
assert response.get_json() == expected_response
# Similarly, write tests for update_task and delete_task routes
def test_update_task(client):
appService = AppService()
updated_task = {
'id': 1,
'name': 'task1_updated',
'description': 'This is the updated task 1'
}
expected_response = appService.update_task(updated_task)
response = client.put('/api/task', json=updated_task)
assert response.status_code == 200
assert response.get_json() == expected_response
def test_delete_task(client):
appService = AppService()
task_id_to_delete = 1
expected_response = appService.delete_task(task_id_to_delete)
response = client.delete(f'/api/task/{task_id_to_delete}')
assert response.status_code == 200
assert response.get_json() == expected_response