Skip to content

Commit 6742a01

Browse files
author
Naor Livne
committed
device group workflow work started
1 parent fee28dd commit 6742a01

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

tests.py

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ def test_check_api(self):
4444

4545
def test_app_flow(self, app="unit_test_app"):
4646
nebula_connection_object = nebula_connection()
47-
# make sure app does not exist before the check starts
47+
48+
# make sure app does not exist before the unit test runs
4849
nebula_connection_object.delete_app(app)
50+
4951
# check app creation works
5052
reply = create_temp_app(nebula_connection_object, app)
5153
self.assertEqual(reply["status_code"], 200)
@@ -61,6 +63,7 @@ def test_app_flow(self, app="unit_test_app"):
6163
self.assertTrue(reply["reply"]["running"])
6264
self.assertEqual(reply["reply"]["starting_ports"], [80])
6365
self.assertEqual(reply["reply"]["volumes"], [])
66+
6467
# check app info works
6568
reply = nebula_connection_object.list_app_info(app)
6669
self.assertEqual(reply["status_code"], 200)
@@ -76,32 +79,39 @@ def test_app_flow(self, app="unit_test_app"):
7679
self.assertTrue(reply["reply"]["running"])
7780
self.assertEqual(reply["reply"]["starting_ports"], [80])
7881
self.assertEqual(reply["reply"]["volumes"], [])
82+
7983
# check that the reply in the case of trying to reuse an existing app name works
8084
reply = create_temp_app(nebula_connection_object, app)
8185
self.assertEqual(reply["status_code"], 403)
86+
8287
# check app stop works
8388
reply = nebula_connection_object.stop_app(app)
8489
self.assertEqual(reply["status_code"], 202)
8590
self.assertFalse(reply["reply"]["running"])
8691
self.assertEqual(reply["reply"]["app_id"], 2)
92+
8793
# check app start works
8894
reply = nebula_connection_object.start_app(app)
8995
self.assertEqual(reply["status_code"], 202)
9096
self.assertTrue(reply["reply"]["running"])
9197
self.assertEqual(reply["reply"]["app_id"], 3)
98+
9299
# check app restart works
93100
reply = nebula_connection_object.restart_app(app)
94101
self.assertEqual(reply["status_code"], 202)
95102
self.assertEqual(reply["reply"]["app_id"], 4)
103+
96104
# check app update works
97105
reply = nebula_connection_object.update_app(app, {"docker_image": "httpd:alpine"})
98106
self.assertEqual(reply["status_code"], 202)
99107
self.assertEqual(reply["reply"]["app_id"], 5)
100108
self.assertEqual(reply["reply"]["docker_image"], "httpd:alpine")
109+
101110
# check app deletion works
102111
reply = nebula_connection_object.delete_app(app)
103112
self.assertEqual(reply["status_code"], 200)
104113
self.assertEqual(reply["reply"], {})
114+
105115
# check app creation failure with missing params
106116
reply = nebula_connection_object.create_app(app, {})
107117
self.assertEqual(reply["status_code"], 400)
@@ -130,18 +140,28 @@ def test_prune_images(self):
130140
self.assertEqual(reply["status_code"], 202)
131141
self.assertTrue(isinstance(reply["reply"]["prune_ids"], dict))
132142

133-
def test_prune_device_group_images(self, device_group="test"):
134-
# TODO - move to device_group_flow
143+
def test_device_group_flow(self, device_group="unit_test_device_group", app="unit_test_device_group_app"):
135144
nebula_connection_object = nebula_connection()
136-
reply = nebula_connection_object.prune__device_group_images(device_group)
137-
first_prune_id = reply["reply"]["prune_id"]
138-
reply = nebula_connection_object.prune__device_group_images(device_group)
139-
self.assertEqual(reply["status_code"], 202)
140-
self.assertEqual(reply["reply"]["prune_id"], first_prune_id + 1)
141145

142-
def test_list_device_group_info(self, device_group="test"):
143-
# TODO - move to device_group_flow
144-
nebula_connection_object = nebula_connection()
146+
# make sure app & device group don't exist before the unit test runs
147+
nebula_connection_object.delete_app(app)
148+
nebula_connection_object.delete_device_group(device_group)
149+
150+
# create app that will be part of the device group
151+
create_temp_app(nebula_connection_object, app)
152+
153+
# check device_group creation works
154+
device_group_config ={"apps": [app]}
155+
nebula_connection_object.create_device_group(device_group,device_group_config)
156+
157+
# check list device_group works
158+
reply = nebula_connection_object.list_device_group(device_group)
159+
self.assertEqual(reply["status_code"], 200)
160+
self.assertTrue(reply["reply"]["device_group_id"], 1)
161+
self.assertTrue(reply["reply"]["apps"], [app])
162+
self.assertEqual(reply["reply"]["prune_id"], 1)
163+
164+
# check device_group_info works
145165
reply = nebula_connection_object.list_device_group_info(device_group)
146166
self.assertEqual(reply["status_code"], 200)
147167
self.assertTrue(isinstance(reply["reply"]["prune_id"], int))
@@ -160,33 +180,27 @@ def test_list_device_group_info(self, device_group="test"):
160180
self.assertTrue(isinstance(app["starting_ports"], list))
161181
self.assertTrue(isinstance(app["volumes"], list))
162182

163-
def test_list_device_group(self, device_group="test"):
164-
# TODO - move to device_group_flow
165-
nebula_connection_object = nebula_connection()
166-
reply = nebula_connection_object.list_device_group(device_group)
167-
self.assertEqual(reply["status_code"], 200)
168-
self.assertTrue(isinstance(reply["reply"]["device_group_id"], int))
169-
self.assertTrue(isinstance(reply["reply"]["apps"], list))
170-
self.assertEqual(reply["reply"]["device_group"], device_group)
183+
# check prune device_group images works
184+
reply = nebula_connection_object.prune__device_group_images(device_group)
185+
first_prune_id = reply["reply"]["prune_id"]
186+
reply = nebula_connection_object.prune__device_group_images(device_group)
187+
self.assertEqual(reply["status_code"], 202)
188+
self.assertEqual(reply["reply"]["prune_id"], first_prune_id + 1)
189+
190+
# check update device_group works
191+
192+
# check device_group already exists works
193+
194+
# check delete device_group works
195+
196+
# clean up app created for the unit test
171197

172198
def test_list_device_groups(self):
173199
nebula_connection_object = nebula_connection()
174200
reply = nebula_connection_object.list_device_groups()
175201
self.assertEqual(reply["status_code"], 200)
176202
self.assertTrue(isinstance(reply["reply"]["device_groups"], list))
177203

178-
def test_create_device_group_success(self):
179-
# TODO - move to device_group_flow
180-
pass
181-
182-
def test_create_device_group_already_exists(self):
183-
# TODO - move to device_group_flow
184-
pass
185-
186-
def test_delete_device_group_success(self):
187-
# TODO - move to device_group_flow
188-
pass
189-
190204
def test_delete_device_group_does_not_exists(self, device_group="test_non_existing_group"):
191205
nebula_connection_object = nebula_connection()
192206
# deleting twice so even if the device_group doesn't exist prior to running the check prior to running the
@@ -195,7 +209,3 @@ def test_delete_device_group_does_not_exists(self, device_group="test_non_existi
195209
reply = nebula_connection_object.delete_device_group(device_group)
196210
self.assertEqual(reply["status_code"], 403)
197211
self.assertFalse(reply["reply"]["device_group_exists"])
198-
199-
def test_update_device_group(self):
200-
# TODO - move to device_group_flow
201-
pass

0 commit comments

Comments
 (0)