Commit 0e0e240f authored by Jérome Perrin's avatar Jérome Perrin

testERP5TestNode: make tests properly isolated

Some tests where patching SlapOSControler to replace methods by a no-op,
but this was never reset. I believe we should rewrite this using mock
which takes care of un-doing the patches for us and makes this testing
easier, but for now I'm just reseting the missing methods like all
others were already reseted.
parent 4b752bdb
...@@ -624,25 +624,33 @@ shared = true ...@@ -624,25 +624,33 @@ shared = true
"kw": kw}) "kw": kw})
return {"status_code": self.status_code} return {"status_code": self.status_code}
SlapOSControler.initializeSlapOSControler = Patch("initializeSlapOSControler") original_SlapOSControler_initializeSlapOSControler = SlapOSControler.initializeSlapOSControler
SlapOSControler.runSoftwareRelease = Patch("runSoftwareRelease") original_SlapOSControler_runSoftwareRelease = SlapOSControler.runSoftwareRelease
SlapOSControler.runComputerPartition = Patch("runComputerPartition") original_SlapOSControler_runComputerPartition = SlapOSControler.runComputerPartition
method_list_for_prepareSlapOSForTestNode = ["initializeSlapOSControler", try:
"runSoftwareRelease"] SlapOSControler.initializeSlapOSControler = Patch("initializeSlapOSControler")
method_list_for_prepareSlapOSForTestSuite = ["initializeSlapOSControler", SlapOSControler.runSoftwareRelease = Patch("runSoftwareRelease")
"runSoftwareRelease", "runComputerPartition"] SlapOSControler.runComputerPartition = Patch("runComputerPartition")
runner.prepareSlapOSForTestNode(test_node_slapos) method_list_for_prepareSlapOSForTestNode = ["initializeSlapOSControler",
self.assertEqual(method_list_for_prepareSlapOSForTestNode, "runSoftwareRelease"]
[x["method_name"] for x in call_list]) method_list_for_prepareSlapOSForTestSuite = ["initializeSlapOSControler",
call_list = [] "runSoftwareRelease", "runComputerPartition"]
runner.prepareSlapOSForTestSuite(node_test_suite) runner.prepareSlapOSForTestNode(test_node_slapos)
self.assertEqual(method_list_for_prepareSlapOSForTestSuite, self.assertEqual(method_list_for_prepareSlapOSForTestNode,
[x["method_name"] for x in call_list]) [x["method_name"] for x in call_list])
call_list = [] call_list = []
SlapOSControler.runSoftwareRelease = Patch("runSoftwareRelease", status_code=1) runner.prepareSlapOSForTestSuite(node_test_suite)
# TODO : write a test for scalability case self.assertEqual(method_list_for_prepareSlapOSForTestSuite,
self.assertRaises(SubprocessError, runner.prepareSlapOSForTestSuite, [x["method_name"] for x in call_list])
node_test_suite) call_list = []
SlapOSControler.runSoftwareRelease = Patch("runSoftwareRelease", status_code=1)
# TODO : write a test for scalability case
self.assertRaises(SubprocessError, runner.prepareSlapOSForTestSuite,
node_test_suite)
finally:
SlapOSControler.initializeSlapOSControler = original_SlapOSControler_initializeSlapOSControler
SlapOSControler.runSoftwareRelease = original_SlapOSControler_runSoftwareRelease
SlapOSControler.runComputerPartition = original_SlapOSControler_runComputerPartition
def test_11_run(self, my_test_type='UnitTest', grade='master'): def test_11_run(self, my_test_type='UnitTest', grade='master'):
def doNothing(self, *args, **kw): def doNothing(self, *args, **kw):
...@@ -738,6 +746,8 @@ shared = true ...@@ -738,6 +746,8 @@ shared = true
RunnerClass._updateInstanceXML = doNothing RunnerClass._updateInstanceXML = doNothing
SlapOSMasterCommunicator.__init__ = doNothing SlapOSMasterCommunicator.__init__ = doNothing
original_generateConfiguration = TaskDistributor.generateConfiguration original_generateConfiguration = TaskDistributor.generateConfiguration
original_initializeSlapOSControler = SlapOSControler.initializeSlapOSControler
TaskDistributor.generateConfiguration = patch_generateConfiguration TaskDistributor.generateConfiguration = patch_generateConfiguration
original_startTestSuite = TaskDistributor.startTestSuite original_startTestSuite = TaskDistributor.startTestSuite
original_subscribeNode = TaskDistributor.subscribeNode original_subscribeNode = TaskDistributor.subscribeNode
...@@ -778,6 +788,7 @@ shared = true ...@@ -778,6 +788,7 @@ shared = true
TaskDistributor.getTestType = original_getTestType TaskDistributor.getTestType = original_getTestType
RunnerClass._prepareSlapOS = original_prepareSlapOS RunnerClass._prepareSlapOS = original_prepareSlapOS
RunnerClass.runTestSuite = original_runTestSuite RunnerClass.runTestSuite = original_runTestSuite
SlapOSControler.initializeSlapOSControler = original_initializeSlapOSControler
def test_12_spawn(self): def test_12_spawn(self):
def _checkCorrectStatus(expected_status,*args): def _checkCorrectStatus(expected_status,*args):
...@@ -911,8 +922,8 @@ shared = true ...@@ -911,8 +922,8 @@ shared = true
del test_node.suiteLog del test_node.suiteLog
# Change UnitTestRunner class methods # Change UnitTestRunner class methods
original_prepareSlapOS = RunnerClass._prepareSlapOS original_prepareSlapOS = RunnerClass._prepareSlapOS
original_runTestSuite = RunnerClass.runTestSuite original_runTestSuite = RunnerClass.runTestSuite
original_initializeSlapOSControler = SlapOSControler.initializeSlapOSControler
if my_test_type == "ScalabilityTest": if my_test_type == "ScalabilityTest":
RunnerClass.runTestSuite = patch_runTestSuite RunnerClass.runTestSuite = patch_runTestSuite
...@@ -945,6 +956,7 @@ shared = true ...@@ -945,6 +956,7 @@ shared = true
TaskDistributor.getTestType = original_getTestType TaskDistributor.getTestType = original_getTestType
RunnerClass._prepareSlapOS = original_prepareSlapOS RunnerClass._prepareSlapOS = original_prepareSlapOS
RunnerClass.runTestSuite = original_runTestSuite RunnerClass.runTestSuite = original_runTestSuite
SlapOSControler.initializeSlapOSControler = original_initializeSlapOSControler
def test_16_cleanupLogDirectory(self): def test_16_cleanupLogDirectory(self):
# Make sure that we are able to cleanup old log folders # Make sure that we are able to cleanup old log folders
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment