Commit 1f377fa7 authored by Łukasz Nowak's avatar Łukasz Nowak

tests/test_slapgrid: Simplify mocking

Context manager is not needed here and even makes more mess, just simply
patch all what is needed in setUp, then unpatch in tearDown.
parent b8785971
......@@ -3178,6 +3178,17 @@ class TestSlapgridWithDevPerm(MasterMixin, unittest.TestCase):
self.disk_device_filename = os.path.join(
self.partition.partition_path,
slapmanager.devperm.Manager.disk_device_filename)
self.patcher_list = [
patch.object(os.path, 'exists', new=self.os_path_exists),
patch.object(os, 'stat', new=self.os_stat),
patch.object(os, 'chown', new=self.os_chown),
patch.object(os, 'readlink', new=self.os_readlink),
patch.object(os.path, 'islink', new=self.os_path_islink)
]
[q.start() for q in self.patcher_list]
def tearDown(self):
[q.stop() for q in self.patcher_list]
def _mock_requests(self):
return httmock.HTTMock(self.computer.request_handler)
......@@ -3229,10 +3240,6 @@ class TestSlapgridWithDevPerm(MasterMixin, unittest.TestCase):
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
with \
patch.object(os.path, 'exists', new=self.os_path_exists), \
patch.object(os, 'stat', new=self.os_stat), \
patch.object(os, 'chown', new=self.os_chown):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(
......@@ -3248,12 +3255,6 @@ class TestSlapgridWithDevPerm(MasterMixin, unittest.TestCase):
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
with \
patch.object(os.path, 'exists', new=self.os_path_exists), \
patch.object(os, 'stat', new=self.os_stat), \
patch.object(os, 'chown', new=self.os_chown), \
patch.object(os, 'readlink', new=self.os_readlink), \
patch.object(os.path, 'islink', new=self.os_path_islink):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(
......@@ -3269,12 +3270,6 @@ class TestSlapgridWithDevPerm(MasterMixin, unittest.TestCase):
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
with \
patch.object(os.path, 'exists', new=self.os_path_exists), \
patch.object(os, 'stat', new=self.os_stat), \
patch.object(os, 'chown', new=self.os_chown), \
patch.object(os, 'readlink', new=self.os_readlink), \
patch.object(os.path, 'islink', new=self.os_path_islink):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(
......@@ -3290,10 +3285,6 @@ class TestSlapgridWithDevPerm(MasterMixin, unittest.TestCase):
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
with \
patch.object(os.path, 'exists', new=self.os_path_exists), \
patch.object(os, 'stat', new=self.os_stat), \
patch.object(os, 'chown', new=self.os_chown):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(
......@@ -3309,10 +3300,6 @@ class TestSlapgridWithDevPerm(MasterMixin, unittest.TestCase):
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
with \
patch.object(os.path, 'exists', new=self.os_path_exists), \
patch.object(os, 'stat', new=self.os_stat), \
patch.object(os, 'chown', new=self.os_chown):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(
......
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