dovetail tool: Add unit tests for 'parser' module 63/23763/1
authormathsyouth <linghui.zeng@huawei.com>
Sat, 29 Oct 2016 08:53:47 +0000 (16:53 +0800)
committermathsyouth <linghui.zeng@huawei.com>
Sat, 29 Oct 2016 09:23:52 +0000 (17:23 +0800)
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>
dovetail/tests/__init__.py [new file with mode: 0644]
dovetail/tests/unit/__init__.py [new file with mode: 0644]
dovetail/tests/unit/test_parser.py [new file with mode: 0644]
dovetail/tests/unit/test_testcase.yaml [new file with mode: 0644]

diff --git a/dovetail/tests/__init__.py b/dovetail/tests/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/dovetail/tests/unit/__init__.py b/dovetail/tests/unit/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/dovetail/tests/unit/test_parser.py b/dovetail/tests/unit/test_parser.py
new file mode 100644 (file)
index 0000000..5b003d1
--- /dev/null
@@ -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 (file)
index 0000000..1b03262
--- /dev/null
@@ -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