Commit 912ea18c authored by Lucas Carvalho's avatar Lucas Carvalho

Don't use temporary files to log the method parameters.

It is better to have a class to store the parameters into a class attribute.
parent fe38481f
...@@ -6,13 +6,17 @@ import unittest ...@@ -6,13 +6,17 @@ import unittest
import tempfile import tempfile
import sys import sys
def mockBootstrapBuildout(*args, **kwargs):
print args, kwargs
utils.bootstrapBuildout = mockBootstrapBuildout
def mockLaunchBuildout(*args, **kwargs): class FakeCallAndRead:
print args, kwargs def __init__(self):
utils.launchBuildout = mockLaunchBuildout self.external_command_dict = {}
def __call__(self, *args, **kwargs):
self.external_command_dict.update(kwargs)
FakeCallAndRead = FakeCallAndRead()
utils.bootstrapBuildout = FakeCallAndRead
utils.launchBuildout = FakeCallAndRead
class TestSoftwareSlapObject(BasicMixin, unittest.TestCase): class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
""" """
...@@ -22,24 +26,13 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase): ...@@ -22,24 +26,13 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
def setUp(self): def setUp(self):
BasicMixin.setUp(self) BasicMixin.setUp(self)
os.mkdir(self.software_root) os.mkdir(self.software_root)
self.output_file = tempfile.NamedTemporaryFile()
self.stdout = sys.stdout
self.signature_private_key_file = '/signature/private/key_file' self.signature_private_key_file = '/signature/private/key_file'
self.upload_cache_url = 'http://example.com/uploadcache' self.upload_cache_url = 'http://example.com/uploadcache'
self.upload_dir_url = 'http://example.com/uploaddir' self.upload_dir_url = 'http://example.com/uploaddir'
def tearDown(self): def tearDown(self):
BasicMixin.tearDown(self) BasicMixin.tearDown(self)
self.output_file.close() FakeCallAndRead.external_command_dict = {}
# Utils methods
def _printToFile(self):
self.output_file.seek(0)
sys.stdout = self.output_file
def _printToScreen(self):
self.output_file.seek(0)
sys.stdout = self.stdout
# Test methods # Test methods
def test_software_install_with_networkcache(self): def test_software_install_with_networkcache(self):
...@@ -55,15 +48,15 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase): ...@@ -55,15 +48,15 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
upload_cache_url='http://example.com/uploadcache', upload_cache_url='http://example.com/uploadcache',
upload_dir_url='http://example.com/uploaddir') upload_dir_url='http://example.com/uploaddir')
self._printToFile()
software.install() software.install()
self._printToScreen()
content = self.output_file.read() additional_buildout_parameter = ' '.join(
self.assertTrue('networkcache' in content) FakeCallAndRead.external_command_dict.\
self.assertTrue(self.upload_cache_url in content) get('additional_buildout_parametr_list'))
self.assertTrue(self.upload_dir_url in content) self.assertTrue('networkcache' in additional_buildout_parameter)
self.assertTrue(self.signature_private_key_file in content) self.assertTrue(self.upload_cache_url in additional_buildout_parameter)
self.assertTrue(self.upload_dir_url in additional_buildout_parameter)
self.assertTrue(self.signature_private_key_file in additional_buildout_parameter)
def test_software_install_without_networkcache(self): def test_software_install_without_networkcache(self):
""" """
...@@ -76,12 +69,12 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase): ...@@ -76,12 +69,12 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
console=False, console=False,
buildout=self.buildout) buildout=self.buildout)
self._printToFile()
software.install() software.install()
self._printToScreen()
content = self.output_file.read() additional_buildout_parameter = ' '.join(FakeCallAndRead.\
self.assertFalse('networkcache' in content) external_command_dict.\
self.assertFalse(self.upload_cache_url in content) get('additional_buildout_parametr_list'))
self.assertFalse(self.upload_dir_url in content) self.assertFalse('networkcache' in additional_buildout_parameter)
self.assertFalse(self.signature_private_key_file in content) self.assertFalse(self.upload_cache_url in additional_buildout_parameter)
self.assertFalse(self.upload_dir_url in additional_buildout_parameter)
self.assertFalse(self.signature_private_key_file in additional_buildout_parameter)
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