project-ize testAPI
[releng.git] / utils / test / result_collection_api / opnfv_testapi / tests / unit / test_dashboard.py
1 import unittest
2
3 from test_result import TestResultBase
4 from opnfv_testapi.common.constants import HTTP_NOT_FOUND, HTTP_OK
5
6 __author__ = '__serena__'
7
8
9 class TestDashboardBase(TestResultBase):
10     def setUp(self):
11         super(TestDashboardBase, self).setUp()
12         self.basePath = '/dashboard/v1/results'
13         self.create_help('/api/v1/results', self.req_d)
14         self.create_help('/api/v1/results', self.req_d)
15         self.list_res = None
16
17
18 class TestDashboardQuery(TestDashboardBase):
19     def test_projectMissing(self):
20         code, body = self.query(self._set_query(project='missing'))
21         self.assertEqual(code, HTTP_NOT_FOUND)
22         self.assertIn('Project name missing', body)
23
24     def test_projectNotReady(self):
25         code, body = self.query(self._set_query(project='notReadyProject'))
26         self.assertEqual(code, HTTP_NOT_FOUND)
27         self.assertIn('Project [notReadyProject] not dashboard ready', body)
28
29     def test_testcaseMissing(self):
30         code, body = self.query(self._set_query(case='missing'))
31         self.assertEqual(code, HTTP_NOT_FOUND)
32         self.assertIn('Test case missing for project [{}]'
33                       .format(self.project),
34                       body)
35
36     def test_testcaseNotReady(self):
37         code, body = self.query(self._set_query(case='notReadyCase'))
38         self.assertEqual(code, HTTP_NOT_FOUND)
39         self.assertIn(
40             'Test case [notReadyCase] not dashboard ready for project [%s]'
41             % self.project,
42             body)
43
44     def test_success(self):
45         code, body = self.query(self._set_query())
46         self.assertEqual(code, HTTP_OK)
47         self.assertIn('{"description": "vPing results for Dashboard"}', body)
48
49     def test_caseIsStatus(self):
50         code, body = self.query(self._set_query(case='status'))
51         self.assertEqual(code, HTTP_OK)
52         self.assertIn('{"description": "Functest status"}', body)
53
54     def _set_query(self, project=None, case=None):
55         uri = ''
56         for k, v in list(locals().iteritems()):
57             if k == 'self' or k == 'uri':
58                 continue
59             if v is None:
60                 v = eval('self.' + k)
61             if v != 'missing':
62                 uri += '{}={}&'.format(k, v)
63         uri += 'pod={}&'.format(self.pod)
64         uri += 'version={}&'.format(self.version)
65         uri += 'installer={}&'.format(self.installer)
66         uri += 'period={}&'.format(5)
67         return uri[0:-1]
68
69
70 if __name__ == '__main__':
71     unittest.main()