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 ##############################################################################
11 from test_base import TestBase
12 from opnfv_testapi.resources.pod_models import PodCreateRequest, Pod, Pods
13 from opnfv_testapi.common.constants import HTTP_OK, HTTP_BAD_REQUEST, \
14 HTTP_FORBIDDEN, HTTP_NOT_FOUND
17 class TestPodBase(TestBase):
19 super(TestPodBase, self).setUp()
20 self.req_d = PodCreateRequest('zte-1', 'virtual',
21 'zte pod 1', 'ci-pod')
22 self.req_e = PodCreateRequest('zte-2', 'metal', 'zte pod 2')
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, HTTP_BAD_REQUEST)
43 def test_emptyName(self):
44 req_empty = PodCreateRequest('')
45 (code, body) = self.create(req_empty)
46 self.assertEqual(code, HTTP_BAD_REQUEST)
47 self.assertIn('name missing', body)
49 def test_noneName(self):
50 req_none = PodCreateRequest(None)
51 (code, body) = self.create(req_none)
52 self.assertEqual(code, HTTP_BAD_REQUEST)
53 self.assertIn('name missing', body)
55 def test_success(self):
56 code, body = self.create_d()
57 self.assertEqual(code, HTTP_OK)
58 self.assert_create_body(body)
60 def test_alreadyExist(self):
62 code, body = self.create_d()
63 self.assertEqual(code, HTTP_FORBIDDEN)
64 self.assertIn('already exists', body)
67 class TestPodGet(TestPodBase):
68 def test_notExist(self):
69 code, body = self.get('notExist')
70 self.assertEqual(code, HTTP_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__':