-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
87 lines (77 loc) · 2.6 KB
/
test_app.py
File metadata and controls
87 lines (77 loc) · 2.6 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
77
78
79
80
81
82
83
84
85
86
87
import pytest
from app import app, db, HealthRecord
from datetime import datetime
@pytest.fixture
def client():
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
app.config['TESTING'] = True
with app.test_client() as client:
with app.app_context():
db.create_all()
yield client
db.session.remove()
db.drop_all()
def test_index_page(client):
response = client.get('/')
assert response.status_code == 200
def test_create_record(client):
data = {
'patient_name': 'John Doe',
'date_of_birth': '1990-01-01',
'medical_condition': 'Flu',
'treatment': 'Rest and fluids'
}
response = client.post('/record/new', data=data, follow_redirects=True)
assert response.status_code == 200
assert b'Health record created successfully!' in response.data
def test_view_record(client):
# Create a test record
record = HealthRecord(
patient_name='Jane Doe',
date_of_birth=datetime.strptime('1990-01-01', '%Y-%m-%d'),
medical_condition='Cold',
treatment='Rest'
)
with app.app_context():
db.session.add(record)
db.session.commit()
record_id = record.id
response = client.get(f'/record/{record_id}')
assert response.status_code == 200
assert b'Jane Doe' in response.data
def test_update_record(client):
# Create a test record
record = HealthRecord(
patient_name='Jane Doe',
date_of_birth=datetime.strptime('1990-01-01', '%Y-%m-%d'),
medical_condition='Cold',
treatment='Rest'
)
with app.app_context():
db.session.add(record)
db.session.commit()
record_id = record.id
data = {
'patient_name': 'Jane Smith',
'date_of_birth': '1990-01-01',
'medical_condition': 'Flu',
'treatment': 'Medicine'
}
response = client.post(f'/record/{record_id}/edit', data=data, follow_redirects=True)
assert response.status_code == 200
assert b'Health record updated successfully!' in response.data
def test_delete_record(client):
# Create a test record
record = HealthRecord(
patient_name='Jane Doe',
date_of_birth=datetime.strptime('1990-01-01', '%Y-%m-%d'),
medical_condition='Cold',
treatment='Rest'
)
with app.app_context():
db.session.add(record)
db.session.commit()
record_id = record.id
response = client.post(f'/record/{record_id}/delete', follow_redirects=True)
assert response.status_code == 200
assert b'Health record deleted successfully!' in response.data