1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
##############################################################################
# Copyright (c) 2016 ZTE Corporation
# feng.xiaowei@zte.com.cn
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import unittest
from test_result import TestResultBase
from opnfv_testapi.common.constants import HTTP_NOT_FOUND, HTTP_OK
class TestDashboardBase(TestResultBase):
def setUp(self):
super(TestDashboardBase, self).setUp()
self.basePath = '/dashboard/v1/results'
self.create_help('/api/v1/results', self.req_d)
self.create_help('/api/v1/results', self.req_d)
self.list_res = None
class TestDashboardQuery(TestDashboardBase):
def test_projectMissing(self):
code, body = self.query(self._set_query(project='missing'))
self.assertEqual(code, HTTP_NOT_FOUND)
self.assertIn('Project name missing', body)
def test_projectNotReady(self):
code, body = self.query(self._set_query(project='notReadyProject'))
self.assertEqual(code, HTTP_NOT_FOUND)
self.assertIn('Project [notReadyProject] not dashboard ready', body)
def test_testcaseMissing(self):
code, body = self.query(self._set_query(case='missing'))
self.assertEqual(code, HTTP_NOT_FOUND)
self.assertIn('Test case missing for project [{}]'
.format(self.project),
body)
def test_testcaseNotReady(self):
code, body = self.query(self._set_query(case='notReadyCase'))
self.assertEqual(code, HTTP_NOT_FOUND)
self.assertIn(
'Test case [notReadyCase] not dashboard ready for project [%s]'
% self.project,
body)
def test_success(self):
code, body = self.query(self._set_query())
self.assertEqual(code, HTTP_OK)
self.assertIn('{"description": "vPing results for Dashboard"}', body)
def test_caseIsStatus(self):
code, body = self.query(self._set_query(case='status'))
self.assertEqual(code, HTTP_OK)
self.assertIn('{"description": "Functest status"}', body)
def _set_query(self, project=None, case=None):
uri = ''
for k, v in list(locals().iteritems()):
if k == 'self' or k == 'uri':
continue
if v is None:
v = eval('self.' + k)
if v != 'missing':
uri += '{}={}&'.format(k, v)
uri += 'pod={}&'.format(self.pod)
uri += 'version={}&'.format(self.version)
uri += 'installer={}&'.format(self.installer)
uri += 'period={}&'.format(5)
return uri[0:-1]
if __name__ == '__main__':
unittest.main()
|