8f729c0d068360779f40f4d2578e7d6481d9322f
[releng.git] / utils / test / result_collection_api / opnfv_testapi / tests / unit / test_dashboard.py
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 ##############################################################################
9 import unittest
10
11 from test_result import TestResultBase
12 from opnfv_testapi.common.constants import HTTP_NOT_FOUND, HTTP_OK
13
14
15 class TestDashboardBase(TestResultBase):
16     def setUp(self):
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)
21         self.list_res = None
22
23
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)
29
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)
34
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),
40                       body)
41
42     def test_testcaseNotReady(self):
43         code, body = self.query(self._set_query(case='notReadyCase'))
44         self.assertEqual(code, HTTP_NOT_FOUND)
45         self.assertIn(
46             'Test case [notReadyCase] not dashboard ready for project [%s]'
47             % self.project,
48             body)
49
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)
54
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)
59
60     def _set_query(self, project=None, case=None):
61         uri = ''
62         for k, v in list(locals().iteritems()):
63             if k == 'self' or k == 'uri':
64                 continue
65             if v is None:
66                 v = eval('self.' + k)
67             if v != 'missing':
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)
73         return uri[0:-1]
74
75
76 if __name__ == '__main__':
77     unittest.main()