diff options
author | mathsyouth <linghui.zeng@huawei.com> | 2016-10-29 16:53:47 +0800 |
---|---|---|
committer | mathsyouth <linghui.zeng@huawei.com> | 2016-10-29 17:23:52 +0800 |
commit | b4e753f311517c97923591f20e85ae467e4d8b94 (patch) | |
tree | d2da22a09e2a6b6b45a24af15c3b95d63548c0f7 | |
parent | d8c7fcfd3dd2bf331ca65ca41b593d65e4c0d97a (diff) |
dovetail tool: Add unit tests for 'parser' module
JIRA: DOVETAIL-45
1. Add two '__init__.py' files for packages
2. Add two test functions in 'test_parser.py' to verify the function
of the method 'parser_cmd'
3. 'test_testcase.yaml' is used in 'test_parser.py'
Change-Id: Ic3e2e6e67bcac3276fe47ec5584c0d9632b5286a
Signed-off-by: mathsyouth <linghui.zeng@huawei.com>
-rw-r--r-- | dovetail/tests/__init__.py | 0 | ||||
-rw-r--r-- | dovetail/tests/unit/__init__.py | 0 | ||||
-rw-r--r-- | dovetail/tests/unit/test_parser.py | 57 | ||||
-rw-r--r-- | dovetail/tests/unit/test_testcase.yaml | 10 |
4 files changed, 67 insertions, 0 deletions
diff --git a/dovetail/tests/__init__.py b/dovetail/tests/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/dovetail/tests/__init__.py diff --git a/dovetail/tests/unit/__init__.py b/dovetail/tests/unit/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/dovetail/tests/unit/__init__.py diff --git a/dovetail/tests/unit/test_parser.py b/dovetail/tests/unit/test_parser.py new file mode 100644 index 00000000..5b003d1a --- /dev/null +++ b/dovetail/tests/unit/test_parser.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# +# lingui.zeng@huawei.com +# 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 +# +""" +Test 'parser' module + +""" + +import logging +import os +import unittest + +import yaml + +import dovetail.parser as dovetail_parser + + +class TestParser(unittest.TestCase): + + test_path = os.path.dirname(os.path.realpath(__file__)) + + def setUp(self): + """Test case setup""" + logging.disable(logging.CRITICAL) + + def test_parser_cmd(self): + """Test whether the command is correctly parsed.""" + mock_cmd = "python /functest/ci/run_tests.py -t {{script_testcase}} -r" + with open(os.path.join(self.test_path, 'test_testcase.yaml')) as f: + mock_testcase_yaml = yaml.safe_load(f) + MockTestcase = type('Testcase', (object,), {}) + mock_testcase = MockTestcase() + mock_testcase.testcase = mock_testcase_yaml.values()[0] + output = dovetail_parser.Parser.parse_cmd(mock_cmd, mock_testcase) + expected_output = ("python /functest/ci/run_tests.py -t " + "tempest_smoke_serial -r") + self.assertEqual(expected_output, output) + + def test_parser_cmd_fail(self): + """Test whether the command is correctly parsed.""" + mock_cmd = "python /functest/ci/run_tests.py -t {{script_testcase}} -r" + mock_testcase_yaml = {} + MockTestcase = type('Testcase', (object,), {}) + mock_testcase = MockTestcase() + mock_testcase.testcase = mock_testcase_yaml.values() + output = dovetail_parser.Parser.parse_cmd(mock_cmd, mock_testcase) + expected_output = ("python /functest/ci/run_tests.py -t " + "None -r") + self.assertEqual(expected_output, output) + +if __name__ == '__main__': + unittest.main() diff --git a/dovetail/tests/unit/test_testcase.yaml b/dovetail/tests/unit/test_testcase.yaml new file mode 100644 index 00000000..1b03262f --- /dev/null +++ b/dovetail/tests/unit/test_testcase.yaml @@ -0,0 +1,10 @@ +dovetail.ipv6.tc001: + name: dovetail.ipv6.tc001 + objective: VIM ipv6 operations, to create/delete network, port and subnet in bulk operation + scripts: + type: functest + testcase: tempest_smoke_serial + sub_testcase_list: + - tempest.api.network.test_networks.BulkNetworkOpsIpV6Test.test_bulk_create_delete_network + - tempest.api.network.test_networks.BulkNetworkOpsIpV7Test.test_bulk_create_delete_port + - tempest.api.network.test_networks.BulkNetworkOpsIpV6Test.test_bulk_create_delete_subnet |