Skip to content

Commit fee28dd

Browse files
author
Naor Livne
committed
adding a complete app flow unit test
1 parent 4344506 commit fee28dd

File tree

1 file changed

+46
-44
lines changed

1 file changed

+46
-44
lines changed

tests.py

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def create_temp_app(nebula_connection_object, app):
3333
reply = nebula_connection_object.create_app(app, app_conf)
3434
return reply
3535

36+
3637
class BaseTests(TestCase):
3738

3839
def test_check_api(self):
@@ -41,8 +42,10 @@ def test_check_api(self):
4142
self.assertEqual(reply["status_code"], 200)
4243
self.assertEqual(reply["reply"]["api_available"], True)
4344

44-
def test_app_creation_flow(self, app="unit_test_app"):
45+
def test_app_flow(self, app="unit_test_app"):
4546
nebula_connection_object = nebula_connection()
47+
# make sure app does not exist before the check starts
48+
nebula_connection_object.delete_app(app)
4649
# check app creation works
4750
reply = create_temp_app(nebula_connection_object, app)
4851
self.assertEqual(reply["status_code"], 200)
@@ -58,9 +61,43 @@ def test_app_creation_flow(self, app="unit_test_app"):
5861
self.assertTrue(reply["reply"]["running"])
5962
self.assertEqual(reply["reply"]["starting_ports"], [80])
6063
self.assertEqual(reply["reply"]["volumes"], [])
61-
# check that the reply in the case of trying to reuse an existing app name noting breaks
64+
# check app info works
65+
reply = nebula_connection_object.list_app_info(app)
66+
self.assertEqual(reply["status_code"], 200)
67+
self.assertEqual(reply["reply"]["app_id"], 1)
68+
self.assertEqual(reply["reply"]["containers_per"], {"server": 1})
69+
self.assertEqual(reply["reply"]["app_name"], app)
70+
self.assertEqual(reply["reply"]["devices"], [])
71+
self.assertEqual(reply["reply"]["docker_image"], "nginx")
72+
self.assertEqual(reply["reply"]["env_vars"], {"TEST": "test123"})
73+
self.assertEqual(reply["reply"]["networks"], ["nebula", "bridge"])
74+
self.assertFalse(reply["reply"]["privileged"])
75+
self.assertFalse(reply["reply"]["rolling_restart"])
76+
self.assertTrue(reply["reply"]["running"])
77+
self.assertEqual(reply["reply"]["starting_ports"], [80])
78+
self.assertEqual(reply["reply"]["volumes"], [])
79+
# check that the reply in the case of trying to reuse an existing app name works
6280
reply = create_temp_app(nebula_connection_object, app)
6381
self.assertEqual(reply["status_code"], 403)
82+
# check app stop works
83+
reply = nebula_connection_object.stop_app(app)
84+
self.assertEqual(reply["status_code"], 202)
85+
self.assertFalse(reply["reply"]["running"])
86+
self.assertEqual(reply["reply"]["app_id"], 2)
87+
# check app start works
88+
reply = nebula_connection_object.start_app(app)
89+
self.assertEqual(reply["status_code"], 202)
90+
self.assertTrue(reply["reply"]["running"])
91+
self.assertEqual(reply["reply"]["app_id"], 3)
92+
# check app restart works
93+
reply = nebula_connection_object.restart_app(app)
94+
self.assertEqual(reply["status_code"], 202)
95+
self.assertEqual(reply["reply"]["app_id"], 4)
96+
# check app update works
97+
reply = nebula_connection_object.update_app(app, {"docker_image": "httpd:alpine"})
98+
self.assertEqual(reply["status_code"], 202)
99+
self.assertEqual(reply["reply"]["app_id"], 5)
100+
self.assertEqual(reply["reply"]["docker_image"], "httpd:alpine")
64101
# check app deletion works
65102
reply = nebula_connection_object.delete_app(app)
66103
self.assertEqual(reply["status_code"], 200)
@@ -87,48 +124,14 @@ def test_list_apps(self):
87124
for app in app_list:
88125
self.assertTrue(isinstance(app, unicode))
89126

90-
def test_list_app_info(self, app="test"):
91-
# TODO - change the app default name to something that not likely to be used
92-
nebula_connection_object = nebula_connection()
93-
reply = nebula_connection_object.list_app_info(app)
94-
self.assertEqual(reply["status_code"], 200)
95-
self.assertTrue(isinstance(reply["reply"]["app_id"], int))
96-
self.assertTrue(isinstance(reply["reply"]["containers_per"], dict))
97-
self.assertEqual(reply["reply"]["app_name"], app)
98-
self.assertTrue(isinstance(reply["reply"]["devices"], list))
99-
self.assertTrue(isinstance(reply["reply"]["docker_image"], unicode))
100-
self.assertTrue(isinstance(reply["reply"]["env_vars"], dict))
101-
self.assertTrue(isinstance(reply["reply"]["networks"], list))
102-
self.assertTrue(isinstance(reply["reply"]["privileged"], bool))
103-
self.assertTrue(isinstance(reply["reply"]["rolling_restart"], bool))
104-
self.assertTrue(isinstance(reply["reply"]["running"], bool))
105-
self.assertTrue(isinstance(reply["reply"]["starting_ports"], list))
106-
self.assertTrue(isinstance(reply["reply"]["volumes"], list))
107-
108-
def test_stop_app(self):
109-
# TODO - finish the tests
110-
pass
111-
112-
def test_start_app(self):
113-
# TODO - finish the tests
114-
pass
115-
116-
def test_restart_app(self):
117-
# TODO - finish the tests
118-
pass
119-
120-
def test_update_app(self):
121-
# TODO - finish the tests
122-
pass
123-
124127
def test_prune_images(self):
125128
nebula_connection_object = nebula_connection()
126129
reply = nebula_connection_object.prune_images()
127130
self.assertEqual(reply["status_code"], 202)
128131
self.assertTrue(isinstance(reply["reply"]["prune_ids"], dict))
129132

130133
def test_prune_device_group_images(self, device_group="test"):
131-
# TODO - change device_group name to something that not likely to be used
134+
# TODO - move to device_group_flow
132135
nebula_connection_object = nebula_connection()
133136
reply = nebula_connection_object.prune__device_group_images(device_group)
134137
first_prune_id = reply["reply"]["prune_id"]
@@ -137,8 +140,7 @@ def test_prune_device_group_images(self, device_group="test"):
137140
self.assertEqual(reply["reply"]["prune_id"], first_prune_id + 1)
138141

139142
def test_list_device_group_info(self, device_group="test"):
140-
# TODO -change the app default name to something that not likely to be used
141-
# TODO - change device_group name to something that not likely to be used
143+
# TODO - move to device_group_flow
142144
nebula_connection_object = nebula_connection()
143145
reply = nebula_connection_object.list_device_group_info(device_group)
144146
self.assertEqual(reply["status_code"], 200)
@@ -159,7 +161,7 @@ def test_list_device_group_info(self, device_group="test"):
159161
self.assertTrue(isinstance(app["volumes"], list))
160162

161163
def test_list_device_group(self, device_group="test"):
162-
# TODO -change device_group name to something that not likely to be used
164+
# TODO - move to device_group_flow
163165
nebula_connection_object = nebula_connection()
164166
reply = nebula_connection_object.list_device_group(device_group)
165167
self.assertEqual(reply["status_code"], 200)
@@ -174,15 +176,15 @@ def test_list_device_groups(self):
174176
self.assertTrue(isinstance(reply["reply"]["device_groups"], list))
175177

176178
def test_create_device_group_success(self):
177-
# TODO - finish the tests
179+
# TODO - move to device_group_flow
178180
pass
179181

180182
def test_create_device_group_already_exists(self):
181-
# TODO - finish the tests
183+
# TODO - move to device_group_flow
182184
pass
183185

184186
def test_delete_device_group_success(self):
185-
# TODO - finish the tests
187+
# TODO - move to device_group_flow
186188
pass
187189

188190
def test_delete_device_group_does_not_exists(self, device_group="test_non_existing_group"):
@@ -195,5 +197,5 @@ def test_delete_device_group_does_not_exists(self, device_group="test_non_existi
195197
self.assertFalse(reply["reply"]["device_group_exists"])
196198

197199
def test_update_device_group(self):
198-
# TODO - finish the tests
200+
# TODO - move to device_group_flow
199201
pass

0 commit comments

Comments
 (0)