1 ##############################################################################
2 # Copyright (c) 2016 ZTE Corporation
3 # feng.xiaowei@zte.com.cn
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
12 from opnfv_testapi.resources import pod_models
13 import test_base as base
16 class TestPodBase(base.TestBase):
18 super(TestPodBase, self).setUp()
19 self.req_d = pod_models.PodCreateRequest('zte-1', 'virtual',
20 'zte pod 1', 'ci-pod')
21 self.req_e = pod_models.PodCreateRequest('zte-2', 'metal', 'zte pod 2')
22 self.get_res = pod_models.Pod
23 self.list_res = pod_models.Pods
24 self.basePath = '/api/v1/pods'
26 def assert_get_body(self, pod, req=None):
29 self.assertEqual(pod.name, req.name)
30 self.assertEqual(pod.mode, req.mode)
31 self.assertEqual(pod.details, req.details)
32 self.assertEqual(pod.role, req.role)
33 self.assertIsNotNone(pod.creation_date)
34 self.assertIsNotNone(pod._id)
37 class TestPodCreate(TestPodBase):
38 def test_withoutBody(self):
39 (code, body) = self.create()
40 self.assertEqual(code, httplib.BAD_REQUEST)
42 def test_emptyName(self):
43 req_empty = pod_models.PodCreateRequest('')
44 (code, body) = self.create(req_empty)
45 self.assertEqual(code, httplib.BAD_REQUEST)
46 self.assertIn('name missing', body)
48 def test_noneName(self):
49 req_none = pod_models.PodCreateRequest(None)
50 (code, body) = self.create(req_none)
51 self.assertEqual(code, httplib.BAD_REQUEST)
52 self.assertIn('name missing', body)
54 def test_success(self):
55 code, body = self.create_d()
56 self.assertEqual(code, httplib.OK)
57 self.assert_create_body(body)
59 def test_alreadyExist(self):
61 code, body = self.create_d()
62 self.assertEqual(code, httplib.FORBIDDEN)
63 self.assertIn('already exists', body)
66 class TestPodGet(TestPodBase):
67 def test_notExist(self):
68 code, body = self.get('notExist')
69 self.assertEqual(code, httplib.NOT_FOUND)
71 def test_getOne(self):
73 code, body = self.get(self.req_d.name)
74 self.assert_get_body(body)
79 code, body = self.get()
80 self.assertEqual(len(body.pods), 2)
82 if self.req_d.name == pod.name:
83 self.assert_get_body(pod)
85 self.assert_get_body(pod, self.req_e)
87 if __name__ == '__main__':