eb09d1a529d00c7badec31cea6fdb4e25277adac
[yardstick.git] / yardstick / tests / unit / common / test_httpClient.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 from __future__ import absolute_import
10
11 import unittest
12
13 import mock
14 from oslo_serialization import jsonutils
15
16 from yardstick.common import httpClient
17
18
19 class HttpClientTestCase(unittest.TestCase):
20
21     @mock.patch('yardstick.common.httpClient.requests')
22     def test_post(self, mock_requests):
23         url = 'http://localhost:5000/hello'
24         data = {'hello': 'world'}
25         headers = {'Content-Type': 'application/json'}
26         httpClient.HttpClient().post(url, data)
27         mock_requests.post.assert_called_with(
28             url, data=jsonutils.dump_as_bytes(data),
29             headers=headers)
30
31     @mock.patch('yardstick.common.httpClient.requests')
32     def test_get(self, mock_requests):
33         url = 'http://localhost:5000/hello'
34         httpClient.HttpClient().get(url)
35         mock_requests.get.assert_called_with(url)
36
37
38 def main():
39     unittest.main()
40
41
42 if __name__ == '__main__':
43     main()