Merge "Bugfix: the API to get result do not work due to can't parse $"
[yardstick.git] / tests / unit / api / test_views.py
1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
3 #
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 import mock
11 import json
12
13 from api.views import Test
14 from api.views import Result
15 from api.views import Env
16
17
18 class TestTestCase(unittest.TestCase):
19
20     @mock.patch('api.views.request')
21     def test_post(self, mock_request):
22         mock_request.json.get.side_effect = ['hello', {}]
23
24         result = json.loads(Test().post())
25
26         self.assertEqual('error', result['status'])
27
28
29 class ResultTestCase(unittest.TestCase):
30
31     @mock.patch('api.views.request')
32     def test_get(self, mock_request):
33         mock_request.args.get.return_value = 'hello'
34
35         print Result().get()
36         result = json.loads(Result().get())
37
38         self.assertEqual('error', result['status'])
39
40
41 class EnvTestCase(unittest.TestCase):
42
43     @mock.patch('api.views.request')
44     def test_post(self, mock_request):
45         mock_request.json.get.side_effect = ['hello', {}]
46
47         result = json.loads(Env().post())
48
49         self.assertEqual('error', result['status'])
50
51
52 def main():
53     unittest.main()
54
55
56 if __name__ == '__main__':
57     main()