forked from yoheinakajima/mindgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_app.py
139 lines (120 loc) · 4.7 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import unittest
from app import create_app
from app.models import graph, add_entity, get_entity, update_entity, delete_entity, add_relationship
class FlaskTestCase(unittest.TestCase):
def setUp(self):
# Create the Flask application for testing
self.app = create_app()
self.app_context = self.app.app_context()
self.app_context.push()
self.client = self.app.test_client()
# Initialize the in-memory data store
graph['people'] = {}
graph['organizations'] = {}
graph['events'] = {}
graph['relationships'] = []
# Create initial test data
self.person_id = add_entity('people', {
'name': 'John Doe',
'email': '[email protected]'
})
self.organization_id = add_entity('organizations', {
'name': 'Doe Enterprises'
})
self.event_id = add_entity('events', {
'name': 'Annual Meeting',
'location': 'Conference Center'
})
self.relationship_id = add_relationship({
'type': 'employment',
'person_id': self.person_id,
'organization_id': self.organization_id
})
def tearDown(self):
# Clear the in-memory data store
self.app_context.pop()
def test_create_person(self):
response = self.client.post('/people', json={
'name': 'Jane Doe',
'email': '[email protected]'
})
self.assertEqual(response.status_code, 201)
data = response.get_json()
self.assertIn('id', data)
def test_get_person(self):
response = self.client.get(f'/people/{self.person_id}')
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertIn('name', data)
def test_update_person(self):
response = self.client.put(f'/people/{self.person_id}', json={
'name': 'John Doe Updated'
})
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertTrue(data['success'])
def test_delete_person(self):
response = self.client.delete(f'/people/{self.person_id}')
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertTrue(data['success'])
def test_create_organization(self):
response = self.client.post('/organizations', json={
'name': 'New Org'
})
self.assertEqual(response.status_code, 201)
data = response.get_json()
self.assertIn('id', data)
def test_get_organization(self):
response = self.client.get(f'/organizations/{self.organization_id}')
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertIn('name', data)
def test_update_organization(self):
response = self.client.put(f'/organizations/{self.organization_id}', json={
'name': 'Doe Enterprises Updated'
})
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertTrue(data['success'])
def test_delete_organization(self):
response = self.client.delete(f'/organizations/{self.organization_id}')
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertTrue(data['success'])
def test_create_event(self):
response = self.client.post('/events', json={
'name': 'New Event',
'location': 'New Venue'
})
self.assertEqual(response.status_code, 201)
data = response.get_json()
self.assertIn('id', data)
def test_get_event(self):
response = self.client.get(f'/events/{self.event_id}')
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertIn('name', data)
def test_update_event(self):
response = self.client.put(f'/events/{self.event_id}', json={
'name': 'Annual Meeting Updated'
})
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertTrue(data['success'])
def test_delete_event(self):
response = self.client.delete(f'/events/{self.event_id}')
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertTrue(data['success'])
def test_create_relationship(self):
response = self.client.post('/relationship', json={
'type': 'partnership',
'person_id': self.person_id,
'organization_id': self.organization_id
})
self.assertEqual(response.status_code, 201)
data = response.get_json()
self.assertIn('id', data)
if __name__ == '__main__':
unittest.main()