-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
48 lines (38 loc) · 1.88 KB
/
tests.py
File metadata and controls
48 lines (38 loc) · 1.88 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
import unittest
import json
from app import app, db, ComplianceRecord
class ComplianceAppTestCase(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
self.app.testing = True
# Create a temporary database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
def test_get_compliance_records(self):
response = self.app.get('/compliance')
self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.data), [])
def test_add_compliance_record(self):
response = self.app.post('/compliance', json={'regulation': 'GDPR', 'status': 'Compliant'})
self.assertEqual(response.status_code, 201)
self.assertIn('id', json.loads(response.data))
def test_get_compliance_record(self):
self.app.post('/compliance', json={'regulation': 'GDPR', 'status': 'Compliant'})
response = self.app.get('/compliance/1')
self.assertEqual(response.status_code, 200)
self.assertIn('regulation', json.loads(response.data))
def test_update_compliance_record(self):
self.app.post('/compliance', json={'regulation': 'GDPR', 'status': 'Compliant'})
response = self.app.put('/compliance/1', json={'regulation': 'GDPR', 'status': 'Non-compliant'})
self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.data)['message'], 'Record updated successfully')
def test_delete_compliance_record(self):
self.app.post('/compliance', json={'regulation': 'GDPR', 'status': 'Compliant'})
response = self.app.delete('/compliance/1')
self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.data)['message'], 'Record deleted successfully')
if __name__ == '__main__':
unittest.main()