Add Functional tests for bays and pods
Change-Id: Ic9e0a13ac5f8a4181f1da8e4211c9a212ba93eb5
This commit is contained in:
parent
d70a795b26
commit
1354546db1
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue