Change in vdsm[master]: tests: Separate tests with similar fixtures

nsoffer at redhat.com nsoffer at redhat.com
Sun May 24 15:13:08 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: tests: Separate tests with similar fixtures
......................................................................

tests: Separate tests with similar fixtures

The tests for exposed functions were testing multiple functions in one
test. This cause unrelated failure to fail the whole test. The correct
way to test this is having separate test for each function.

Now we have separate test case class for the positive and negative
tests, sharing the same configurators setup.

Change-Id: Id84236c1cb7ac065cec42ea08958efd8112ecbd8
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M tests/toolTests.py
1 file changed, 63 insertions(+), 53 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/64/41364/1

diff --git a/tests/toolTests.py b/tests/toolTests.py
index 9f6e43e..bff299a 100644
--- a/tests/toolTests.py
+++ b/tests/toolTests.py
@@ -194,59 +194,6 @@
             '--module=multipath'
         )
 
-    @ValidateRunningAsRoot
-    @patchConfigurators(
-        (
-            MockModuleConfigurator('a', should_succeed=False),
-            MockModuleConfigurator('b', should_succeed=False),
-
-        )
-    )
-    def testFailuresOnExposedFuncs(self):
-        self.assertRaises(
-            InvalidConfig,
-            configurator.validate_config,
-            'validate-config',
-        )
-        self.assertRaises(
-            InvalidRun,
-            configurator.isconfigured,
-            'is-configured',
-        )
-        # running configure with force flag to avoid validate check
-        self.assertRaises(
-            InvalidRun,
-            configurator.configure,
-            'configure',
-            '--force',
-        )
-        self.assertRaises(
-            InvalidRun,
-            configurator.remove_config,
-            'remove-config'
-        )
-
-    @ValidateRunningAsRoot
-    @patchConfigurators(
-        (
-            MockModuleConfigurator('a'),
-            MockModuleConfigurator('b'),
-        )
-    )
-    def testValidFlowOnExposedFuncs(self):
-        configurator.validate_config(
-            'validate-config',
-        )
-        configurator.isconfigured(
-            'is-configured',
-        )
-        configurator.configure(
-            'configure',
-        )
-        configurator.remove_config(
-            'remove-config',
-        )
-
     def testConfigureFiltering(self):
         class Dummy(object):
             pass
@@ -281,6 +228,69 @@
                 )
 
 
+class ExposedFunctionsTests(VdsmTestCase):
+
+    @ValidateRunningAsRoot
+    def setUp(self):
+        configurators = {
+            "a": MockModuleConfigurator("a"),
+            "b": MockModuleConfigurator("b"),
+        }
+        self.patch = monkeypatch.Patch([
+            (configurator, "_CONFIGURATORS", configurators),
+        ])
+        self.patch.apply()
+
+    def tearDown(self):
+        self.patch.revert()
+
+    def test_validate_config(self):
+        configurator.validate_config("validate-config")
+
+    def test_isconfigured(self):
+        configurator.isconfigured("is-configured")
+
+    def test_configure(self):
+        configurator.configure("configure")
+
+    def test_remove_config(self):
+        configurator.remove_config("remove-config")
+
+
+class ExposedFunctionsFailuresTests(VdsmTestCase):
+
+    @ValidateRunningAsRoot
+    def setUp(self):
+        configurators = {
+            "a": MockModuleConfigurator("a", should_succeed=False),
+            "b": MockModuleConfigurator("b", should_succeed=False),
+        }
+        self.patch = monkeypatch.Patch([
+            (configurator, "_CONFIGURATORS", configurators),
+        ])
+        self.patch.apply()
+
+    def tearDown(self):
+        self.patch.revert()
+
+    def test_validate_config(self):
+        self.assertRaises(InvalidConfig, configurator.validate_config,
+                          "validate-config")
+
+    def test_isconfigured(self):
+        self.assertRaises(InvalidRun, configurator.isconfigured,
+                          "is-configured")
+
+    def test_configure(self):
+        # Using --force to avoid validation
+        self.assertRaises(InvalidRun, configurator.configure,
+                          "configure", "--force")
+
+    def test_remove_config(self):
+        self.assertRaises(InvalidRun, configurator.remove_config,
+                          "remove-config")
+
+
 class LibvirtModuleConfigureTests(TestCase):
 
     test_env = {}


-- 
To view, visit https://gerrit.ovirt.org/41364
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id84236c1cb7ac065cec42ea08958efd8112ecbd8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list