summaryrefslogtreecommitdiffstats
path: root/tests/unit/common
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/common')
-rw-r--r--tests/unit/common/config_sample.yaml2
-rw-r--r--tests/unit/common/test_httpClient.py33
-rw-r--r--tests/unit/common/test_utils.py27
3 files changed, 62 insertions, 0 deletions
diff --git a/tests/unit/common/config_sample.yaml b/tests/unit/common/config_sample.yaml
new file mode 100644
index 000000000..8caa19ec6
--- /dev/null
+++ b/tests/unit/common/config_sample.yaml
@@ -0,0 +1,2 @@
+releng:
+ dir: /home/opnfv/repos/releng
diff --git a/tests/unit/common/test_httpClient.py b/tests/unit/common/test_httpClient.py
new file mode 100644
index 000000000..b39dc2332
--- /dev/null
+++ b/tests/unit/common/test_httpClient.py
@@ -0,0 +1,33 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# 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
+import mock
+import json
+
+from yardstick.common import httpClient
+
+
+class HttpClientTestCase(unittest.TestCase):
+
+ @mock.patch('yardstick.common.httpClient.requests')
+ def test_post(self, mock_requests):
+ url = 'http://localhost:5000/hello'
+ data = {'hello': 'world'}
+ headers = {'Content-Type': 'application/json'}
+ httpClient.HttpClient().post(url, data)
+ mock_requests.post.assert_called_with(url, data=json.dumps(data),
+ headers=headers)
+
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/common/test_utils.py b/tests/unit/common/test_utils.py
index 002d0494c..a64c1f1ab 100644
--- a/tests/unit/common/test_utils.py
+++ b/tests/unit/common/test_utils.py
@@ -83,6 +83,33 @@ class ImportModulesFromPackageTestCase(unittest.TestCase):
mock_importutils.import_module.assert_called_with('bar.baz')
+class GetParaFromYaml(unittest.TestCase):
+
+ def test_get_para_from_yaml_file_not_exist(self):
+ file_path = '/etc/yardstick/hello.yaml'
+ args = 'hello.world'
+ para = utils.get_para_from_yaml(file_path, args)
+ self.assertIsNone(para)
+
+ def test_get_para_from_yaml_para_not_found(self):
+ file_path = 'config_sample.yaml'
+ file_path = self._get_file_abspath(file_path)
+ args = 'releng.file'
+ self.assertIsNone(utils.get_para_from_yaml(file_path, args))
+
+ def test_get_para_from_yaml_para_exists(self):
+ file_path = 'config_sample.yaml'
+ file_path = self._get_file_abspath(file_path)
+ args = 'releng.dir'
+ para = '/home/opnfv/repos/releng'
+ self.assertEqual(para, utils.get_para_from_yaml(file_path, args))
+
+ def _get_file_abspath(self, filename):
+ curr_path = os.path.dirname(os.path.abspath(__file__))
+ file_path = os.path.join(curr_path, filename)
+ return file_path
+
+
def main():
unittest.main()