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.common import message
13 from opnfv_testapi.resources import pod_models
14 import test_base as base
17 class TestPodBase(base.TestBase):
19 super(TestPodBase, self).setUp()
20 self.req_d = pod_models.PodCreateRequest('zte-1', 'virtual',
21 'zte pod 1', 'ci-pod')
22 self.req_e = pod_models.PodCreateRequest('zte-2', 'metal', 'zte pod 2')
23 self.get_res = pod_models.Pod
24 self.list_res = pod_models.Pods
25 self.basePath = '/api/v1/pods'
27 def assert_get_body(self, pod, req=None):
30 self.assertEqual(pod.name, req.name)
31 self.assertEqual(pod.mode, req.mode)
32 self.assertEqual(pod.details, req.details)
33 self.assertEqual(pod.role, req.role)
34 self.assertIsNotNone(pod.creation_date)
35 self.assertIsNotNone(pod._id)
38 class TestPodCreate(TestPodBase):
39 def test_withoutBody(self):
40 (code, body) = self.create()
41 self.assertEqual(code, httplib.BAD_REQUEST)
43 def test_emptyName(self):
44 req_empty = pod_models.PodCreateRequest('')
45 (code, body) = self.create(req_empty)
46 self.assertEqual(code, httplib.BAD_REQUEST)
47 self.assertIn(message.missing('name'), body)
49 def test_noneName(self):
50 req_none = pod_models.PodCreateRequest(None)
51 (code, body) = self.create(req_none)
52 self.assertEqual(code, httplib.BAD_REQUEST)
53 self.assertIn(message.missing('name'), body)
55 def test_success(self):
56 code, body = self.create_d()
57 self.assertEqual(code, httplib.OK)
58 self.assert_create_body(body)
60 def test_alreadyExist(self):
62 code, body = self.create_d()
63 self.assertEqual(code, httplib.FORBIDDEN)
64 self.assertIn(message.exist_base, body)
67 class TestPodGet(TestPodBase):
68 def test_notExist(self):
69 code, body = self.get('notExist')
70 self.assertEqual(code, httplib.NOT_FOUND)
72 def test_getOne(self):
74 code, body = self.get(self.req_d.name)
75 self.assert_get_body(body)
80 code, body = self.get()
81 self.assertEqual(len(body.pods), 2)
83 if self.req_d.name == pod.name:
84 self.assert_get_body(pod)
86 self.assert_get_body(pod, self.req_e)
88 if __name__ == '__main__':