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_result import TestResultBase
12 from opnfv_testapi.common.constants import HTTP_NOT_FOUND, HTTP_OK
15 class TestDashboardBase(TestResultBase):
17 super(TestDashboardBase, self).setUp()
18 self.basePath = '/dashboard/v1/results'
19 self.create_help('/api/v1/results', self.req_d)
20 self.create_help('/api/v1/results', self.req_d)
24 class TestDashboardQuery(TestDashboardBase):
25 def test_projectMissing(self):
26 code, body = self.query(self._set_query(project='missing'))
27 self.assertEqual(code, HTTP_NOT_FOUND)
28 self.assertIn('Project name missing', body)
30 def test_projectNotReady(self):
31 code, body = self.query(self._set_query(project='notReadyProject'))
32 self.assertEqual(code, HTTP_NOT_FOUND)
33 self.assertIn('Project [notReadyProject] not dashboard ready', body)
35 def test_testcaseMissing(self):
36 code, body = self.query(self._set_query(case='missing'))
37 self.assertEqual(code, HTTP_NOT_FOUND)
38 self.assertIn('Test case missing for project [{}]'
39 .format(self.project),
42 def test_testcaseNotReady(self):
43 code, body = self.query(self._set_query(case='notReadyCase'))
44 self.assertEqual(code, HTTP_NOT_FOUND)
46 'Test case [notReadyCase] not dashboard ready for project [%s]'
50 def test_success(self):
51 code, body = self.query(self._set_query())
52 self.assertEqual(code, HTTP_OK)
53 self.assertIn('{"description": "vPing results for Dashboard"}', body)
55 def test_caseIsStatus(self):
56 code, body = self.query(self._set_query(case='status'))
57 self.assertEqual(code, HTTP_OK)
58 self.assertIn('{"description": "Functest status"}', body)
60 def _set_query(self, project=None, case=None):
62 for k, v in list(locals().iteritems()):
63 if k == 'self' or k == 'uri':
68 uri += '{}={}&'.format(k, v)
69 uri += 'pod={}&'.format(self.pod)
70 uri += 'version={}&'.format(self.version)
71 uri += 'installer={}&'.format(self.installer)
72 uri += 'period={}&'.format(5)
76 if __name__ == '__main__':