From 1354546db15be7d6039e124508685822c4b01fe4 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Sun, 30 Nov 2014 11:48:23 -0500 Subject: [PATCH] Add Functional tests for bays and pods Change-Id: Ic9e0a13ac5f8a4181f1da8e4211c9a212ba93eb5 --- magnum/api/controllers/v1/bay.py | 8 ++-- magnum/api/controllers/v1/pod.py | 18 +++---- magnum/tests/test_functional.py | 80 ++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 13 deletions(-) diff --git a/magnum/api/controllers/v1/bay.py b/magnum/api/controllers/v1/bay.py index 5df71012f8..c6d1b5a2bc 100644 --- a/magnum/api/controllers/v1/bay.py +++ b/magnum/api/controllers/v1/bay.py @@ -220,7 +220,7 @@ class BayController(rest.RestController): """ pass - @wsme_pecan.wsexpose(Bay, wtypes.text) + @wsme_pecan.wsexpose(wtypes.text, wtypes.text) def delete(self, id): """Delete this bay. @@ -229,8 +229,8 @@ class BayController(rest.RestController): count = 0 for bay in self.bay_list: if bay.id == id: - self.bay_list.remove(count) - break + self.bay_list.remove(bay) + return id count = count + 1 - return 200 + return None diff --git a/magnum/api/controllers/v1/pod.py b/magnum/api/controllers/v1/pod.py index e0edb96706..b327c38468 100644 --- a/magnum/api/controllers/v1/pod.py +++ b/magnum/api/controllers/v1/pod.py @@ -165,9 +165,9 @@ class Pod(_Base): @classmethod def sample(cls): - return cls(id=str(uuid.uuid1(), - name="Docker", - desc='Docker Pods')) + return cls(id=str(uuid.uuid1()), + name="Docker", + desc='Docker Pods') class PodController(rest.RestController): @@ -200,12 +200,12 @@ class PodController(rest.RestController): return self.pod_list @wsme_pecan.wsexpose(Pod, wtypes.text, wtypes.text) - def post(self, name, type): + def post(self, name, desc): """Create a new pod. :param pod: a pod within the request body. """ - pod = Pod(id=str(uuid.uuid1()), name=name, type=type) + pod = Pod(id=str(uuid.uuid1()), name=name, desc=desc) self.pod_list.append(pod) return pod @@ -219,7 +219,7 @@ class PodController(rest.RestController): """ pass - @wsme_pecan.wsexpose(Pod, wtypes.text) + @wsme_pecan.wsexpose(wtypes.text, wtypes.text) def delete(self, id): """Delete this pod. @@ -228,8 +228,8 @@ class PodController(rest.RestController): count = 0 for pod in self.pod_list: if pod.id == id: - self.pod_list.remove(count) - break + self.pod_list.remove(pod) + return id count = count + 1 - return 200 + return None diff --git a/magnum/tests/test_functional.py b/magnum/tests/test_functional.py index 71c5610039..57de44d7f4 100644 --- a/magnum/tests/test_functional.py +++ b/magnum/tests/test_functional.py @@ -45,6 +45,86 @@ class TestRootController(tests.FunctionalTest): assert response.status_int == 404 +class TestBayController(tests.FunctionalTest): + def test_bay_api(self): + # Create a bay + params = '{"name": "bay_example_A", "type": "virt"}' + response = self.app.post('/v1/bays', + params=params, + content_type='application/json') + self.assertEqual(response.status_int, 200) + + # Get all bays + response = self.app.get('/v1/bays') + self.assertEqual(response.status_int, 200) + self.assertEqual(1, len(response.json)) + c = response.json[0] + self.assertIsNotNone(c.get('id')) + self.assertEqual('bay_example_A', c.get('name')) + self.assertEqual('virt', c.get('type')) + + # Get just the one we created + response = self.app.get('/v1/bays/%s' % c.get('id')) + self.assertEqual(response.status_int, 200) + + # Update the description + params = ('{"id":"' + c.get('id') + '", ' + '"type": "virt", ' + '"name": "bay_example_B"}') + response = self.app.put('/v1/bays', + params=params, + content_type='application/json') + self.assertEqual(response.status_int, 200) + + # Delete the bay we created + response = self.app.delete('/v1/bays/%s' % c.get('id')) + self.assertEqual(response.status_int, 200) + + response = self.app.get('/v1/bays') + self.assertEqual(response.status_int, 200) + self.assertEqual(0, len(response.json)) + + +class TestPodController(tests.FunctionalTest): + def test_pod_api(self): + # Create a pod + params = '{"desc": "my pod", "name": "pod_example_A"}' + response = self.app.post('/v1/pods', + params=params, + content_type='application/json') + self.assertEqual(response.status_int, 200) + + # Get all bays + response = self.app.get('/v1/pods') + self.assertEqual(response.status_int, 200) + self.assertEqual(1, len(response.json)) + c = response.json[0] + self.assertIsNotNone(c.get('id')) + self.assertEqual('pod_example_A', c.get('name')) + self.assertEqual('my pod', c.get('desc')) + + # Get just the one we created + response = self.app.get('/v1/pods/%s' % c.get('id')) + self.assertEqual(response.status_int, 200) + + # Update the description + params = ('{"id":"' + c.get('id') + '", ' + '"desc": "your pod", ' + '"name": "pod_example_A"}') + response = self.app.put('/v1/pods', + params=params, + content_type='application/json') + self.assertEqual(response.status_int, 200) + + # Delete the bay we created + response = self.app.delete('/v1/pods/%s' % c.get('id')) + self.assertEqual(response.status_int, 200) + + response = self.app.get('/v1/pods') + self.assertEqual(response.status_int, 200) + self.assertEqual(0, len(response.json)) + + class TestContainerController(tests.FunctionalTest): def test_container_api(self): # Create a container