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 opnfv_testapi.common.constants import HTTP_NOT_FOUND, HTTP_OK
13 from test_result import TestResultBase
16 class TestDashboardBase(TestResultBase):
18 super(TestDashboardBase, self).setUp()
19 self.basePath = '/dashboard/v1/results'
20 self.create_help('/api/v1/results', self.req_d)
21 self.create_help('/api/v1/results', self.req_d)
25 class TestDashboardQuery(TestDashboardBase):
26 def test_projectMissing(self):
27 code, body = self.query(self._set_query(project='missing'))
28 self.assertEqual(code, HTTP_NOT_FOUND)
29 self.assertIn('Project name missing', body)
31 def test_projectNotReady(self):
32 code, body = self.query(self._set_query(project='notReadyProject'))
33 self.assertEqual(code, HTTP_NOT_FOUND)
34 self.assertIn('Project [notReadyProject] not dashboard ready', body)
36 def test_testcaseMissing(self):
37 code, body = self.query(self._set_query(case='missing'))
38 self.assertEqual(code, HTTP_NOT_FOUND)
39 self.assertIn('Test case missing for project [{}]'
40 .format(self.project),
43 def test_testcaseNotReady(self):
44 code, body = self.query(self._set_query(case='notReadyCase'))
45 self.assertEqual(code, HTTP_NOT_FOUND)
47 'Test case [notReadyCase] not dashboard ready for project [%s]'
51 def test_success(self):
52 code, body = self.query(self._set_query())
53 self.assertEqual(code, HTTP_OK)
54 self.assertIn('{"description": "vPing results for Dashboard"}', body)
56 def test_caseIsStatus(self):
57 code, body = self.query(self._set_query(case='status'))
58 self.assertEqual(code, HTTP_OK)
59 self.assertIn('{"description": "Functest status"}', body)
61 def _set_query(self, project=None, case=None):
63 for k, v in list(locals().iteritems()):
64 if k == 'self' or k == 'uri':
67 v = self.__getattribute__(k)
69 uri += '{}={}&'.format(k, v)
70 uri += 'pod={}&'.format(self.pod)
71 uri += 'version={}&'.format(self.version)
72 uri += 'installer={}&'.format(self.installer)
73 uri += 'period={}&'.format(5)
77 if __name__ == '__main__':