Commit 32833df9 authored by Marco Mariani's avatar Marco Mariani

assertTrue -> assertIn

parent aec034d4
...@@ -107,7 +107,7 @@ class TestcheckOption (BasicMixin, unittest.TestCase): ...@@ -107,7 +107,7 @@ class TestcheckOption (BasicMixin, unittest.TestCase):
option = "--logfile /opt/slapgrid/slapformat.log" option = "--logfile /opt/slapgrid/slapformat.log"
entry.checkOption(option) entry.checkOption(option)
self.assertNotEqual(original_sysargv, sys.argv) self.assertNotEqual(original_sysargv, sys.argv)
self.assertTrue(option in " ".join(sys.argv)) self.assertIn(option, ' '.join(sys.argv))
class TestCall (BasicMixin, unittest.TestCase): class TestCall (BasicMixin, unittest.TestCase):
...@@ -133,7 +133,7 @@ class TestCall (BasicMixin, unittest.TestCase): ...@@ -133,7 +133,7 @@ class TestCall (BasicMixin, unittest.TestCase):
self.assertEqual(e[0], 0) self.assertEqual(e[0], 0)
self.assertNotEqual(original_sysargv, sys.argv) self.assertNotEqual(original_sysargv, sys.argv)
for x in options: for x in options:
self.assertTrue(x in " ".join(sys.argv)) self.assertIn(x, ' '.join(sys.argv))
self.assertEqual(config_path, sys.argv[1]) self.assertEqual(config_path, sys.argv[1])
def test_config_and_missing_option_are_added(self): def test_config_and_missing_option_are_added(self):
...@@ -158,7 +158,7 @@ class TestCall (BasicMixin, unittest.TestCase): ...@@ -158,7 +158,7 @@ class TestCall (BasicMixin, unittest.TestCase):
self.assertEqual(e[0], 0) self.assertEqual(e[0], 0)
self.assertNotEqual(original_sysargv, sys.argv) self.assertNotEqual(original_sysargv, sys.argv)
for x in (missing_option, present_option): for x in (missing_option, present_option):
self.assertTrue(x in " ".join(sys.argv)) self.assertIn(x, ' '.join(sys.argv))
self.assertFalse(default_present_option in " ".join(sys.argv)) self.assertFalse(default_present_option in " ".join(sys.argv))
self.assertEqual(config_path, sys.argv[1]) self.assertEqual(config_path, sys.argv[1])
......
...@@ -91,10 +91,8 @@ class TestSlap(SlapMixin): ...@@ -91,10 +91,8 @@ class TestSlap(SlapMixin):
""" """
slap_instance = slapos.slap.slap() slap_instance = slapos.slap.slap()
slap_instance.initializeConnection(self.server_url) slap_instance.initializeConnection(self.server_url)
self.assertTrue( self.assertIn(slap_instance._connection_helper.host, self.server_url)
slap_instance._connection_helper.host in self.server_url) self.assertIn(slap_instance._connection_helper.path, self.server_url)
self.assertTrue(
slap_instance._connection_helper.path in self.server_url)
def test_slap_initialisation_wrong_url(self): def test_slap_initialisation_wrong_url(self):
""" """
......
...@@ -541,7 +541,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest2.TestCase): ...@@ -541,7 +541,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest2.TestCase):
if os.path.getsize(wrapper_log) > 0: if os.path.getsize(wrapper_log) > 0:
break break
time.sleep(0.1) time.sleep(0.1)
self.assertTrue('Working' in open(wrapper_log).read()) self.assertIn('Working', open(wrapper_log).read())
self.assertItemsEqual(os.listdir(self.software_root), [partition.software.software_hash]) self.assertItemsEqual(os.listdir(self.software_root), [partition.software.software_hash])
self.assertEqual(computer.sequence, self.assertEqual(computer.sequence,
['getFullComputerInformation', 'availableComputerPartition', ['getFullComputerInformation', 'availableComputerPartition',
...@@ -584,7 +584,7 @@ chmod 755 etc/run/wrapper ...@@ -584,7 +584,7 @@ chmod 755 etc/run/wrapper
break break
time.sleep(0.1) time.sleep(0.1)
os.path.getsize(wrapper_log) os.path.getsize(wrapper_log)
self.assertTrue('Working' in open(wrapper_log).read()) self.assertIn('Working', open(wrapper_log).read())
self.assertItemsEqual(os.listdir(self.software_root), [instance.software.software_hash]) self.assertItemsEqual(os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence, self.assertEqual(computer.sequence,
['getFullComputerInformation', 'availableComputerPartition', ['getFullComputerInformation', 'availableComputerPartition',
...@@ -651,7 +651,7 @@ chmod 755 etc/run/wrapper ...@@ -651,7 +651,7 @@ chmod 755 etc/run/wrapper
break break
time.sleep(0.1) time.sleep(0.1)
os.path.getsize(wrapper_log) os.path.getsize(wrapper_log)
self.assertTrue('Working' in open(wrapper_log).read()) self.assertIn('Working', open(wrapper_log).read())
self.assertItemsEqual(os.listdir(self.software_root), self.assertItemsEqual(os.listdir(self.software_root),
[instance.software.software_hash]) [instance.software.software_hash])
self.assertEqual(computer.sequence, self.assertEqual(computer.sequence,
...@@ -718,7 +718,7 @@ exit 1 ...@@ -718,7 +718,7 @@ exit 1
if os.path.getsize(wrapper_log) > 0: if os.path.getsize(wrapper_log) > 0:
break break
time.sleep(0.1) time.sleep(0.1)
self.assertTrue('Working' in open(wrapper_log).read()) self.assertIn('Working', open(wrapper_log).read())
self.assertEqual(computer.sequence, self.assertEqual(computer.sequence,
['getFullComputerInformation', 'availableComputerPartition', ['getFullComputerInformation', 'availableComputerPartition',
'startedComputerPartition']) 'startedComputerPartition'])
...@@ -794,7 +794,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase): ...@@ -794,7 +794,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
break break
time.sleep(0.1) time.sleep(0.1)
time.sleep(0.1) time.sleep(0.1)
self.assertTrue('Failing' in open(daemon_log).read()) self.assertIn('Failing', open(daemon_log).read())
tries = 200 tries = 200
while tries > 0: while tries > 0:
tries -= 1 tries -= 1
...@@ -802,7 +802,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase): ...@@ -802,7 +802,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
break break
time.sleep(0.1) time.sleep(0.1)
self.assertTrue(os.path.exists(self.watchdog_banged)) self.assertTrue(os.path.exists(self.watchdog_banged))
self.assertTrue('daemon' in open(self.watchdog_banged).read()) self.assertIn('daemon', open(self.watchdog_banged).read())
def test_one_failing_daemon_in_run_will_not_bang_with_watchdog(self): def test_one_failing_daemon_in_run_will_not_bang_with_watchdog(self):
""" """
...@@ -846,7 +846,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase): ...@@ -846,7 +846,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
break break
time.sleep(0.1) time.sleep(0.1)
time.sleep(0.1) time.sleep(0.1)
self.assertTrue('Failing' in open(daemon_log).read()) self.assertIn('Failing', open(daemon_log).read())
tries = 200 tries = 200
while tries > 0: while tries > 0:
tries -= 1 tries -= 1
...@@ -947,7 +947,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase): ...@@ -947,7 +947,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
timestamp_path = os.path.join(instance.partition_path, '.timestamp') timestamp_path = os.path.join(instance.partition_path, '.timestamp')
self.setSlapgrid() self.setSlapgrid()
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertTrue(timestamp in open(timestamp_path).read()) self.assertIn(timestamp, open(timestamp_path).read())
self.assertEqual(instance.sequence, self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition']) ['availableComputerPartition', 'stoppedComputerPartition'])
...@@ -1301,9 +1301,9 @@ echo %s; echo %s; exit 42""" % (line1, line2)) ...@@ -1301,9 +1301,9 @@ echo %s; echo %s; exit 42""" % (line1, line2))
self.launchSlapgrid() self.launchSlapgrid()
self.assertEqual(instance.sequence, ['softwareInstanceError']) self.assertEqual(instance.sequence, ['softwareInstanceError'])
# We don't care of actual formatting, we just want to have full log # We don't care of actual formatting, we just want to have full log
self.assertTrue(line1 in instance.error_log) self.assertIn(line1, instance.error_log)
self.assertTrue(line2 in instance.error_log) self.assertIn(line2, instance.error_log)
self.assertTrue("Failed to run buildout" in instance.error_log) self.assertIn('Failed to run buildout', instance.error_log)
class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase): class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
...@@ -1330,7 +1330,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase): ...@@ -1330,7 +1330,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
if os.path.getsize(wrapper_log) > 0: if os.path.getsize(wrapper_log) > 0:
break break
time.sleep(0.1) time.sleep(0.1)
self.assertTrue('Working' in open(wrapper_log).read()) self.assertIn('Working', open(wrapper_log).read())
self.assertItemsEqual(os.listdir(self.software_root), [instance.software.software_hash]) self.assertItemsEqual(os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence, self.assertEqual(computer.sequence,
['getFullComputerInformation', ['getFullComputerInformation',
...@@ -1421,7 +1421,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase): ...@@ -1421,7 +1421,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
if os.path.getsize(wrapper_log) > 0: if os.path.getsize(wrapper_log) > 0:
break break
time.sleep(0.1) time.sleep(0.1)
self.assertTrue('Working' in open(wrapper_log).read()) self.assertIn('Working', open(wrapper_log).read())
self.assertItemsEqual(os.listdir(self.software_root), [instance.software.software_hash]) self.assertItemsEqual(os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence, self.assertEqual(computer.sequence,
['getFullComputerInformation', ['getFullComputerInformation',
...@@ -1442,7 +1442,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase): ...@@ -1442,7 +1442,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
if os.path.getsize(wrapper_log) > 0: if os.path.getsize(wrapper_log) > 0:
break break
time.sleep(0.1) time.sleep(0.1)
self.assertTrue('Working' in open(wrapper_log).read()) self.assertIn('Working', open(wrapper_log).read())
self.assertItemsEqual(os.listdir(self.instance_root), ['0', 'etc', 'var']) self.assertItemsEqual(os.listdir(self.instance_root), ['0', 'etc', 'var'])
self.assertItemsEqual(os.listdir(instance.partition_path), self.assertItemsEqual(os.listdir(instance.partition_path),
['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked']) ['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
...@@ -1513,9 +1513,9 @@ echo %s; echo %s; exit 42""" % (line1, line2)) ...@@ -1513,9 +1513,9 @@ echo %s; echo %s; exit 42""" % (line1, line2))
self.assertEqual(software.sequence, self.assertEqual(software.sequence,
['buildingSoftwareRelease', 'softwareReleaseError']) ['buildingSoftwareRelease', 'softwareReleaseError'])
# We don't care of actual formatting, we just want to have full log # We don't care of actual formatting, we just want to have full log
self.assertTrue(line1 in software.error_log) self.assertIn(line1, software.error_log)
self.assertTrue(line2 in software.error_log) self.assertIn(line2, software.error_log)
self.assertTrue("Failed to run buildout" in software.error_log) self.assertIn('Failed to run buildout', software.error_log)
class SlapgridInitialization(unittest2.TestCase): class SlapgridInitialization(unittest2.TestCase):
""" """
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
import logging import logging
import os import os
import unittest import unittest2
from slapos.grid import SlapObject from slapos.grid import SlapObject
from slapos.grid import utils from slapos.grid import utils
...@@ -53,7 +53,7 @@ originalBootstrapBuildout = utils.bootstrapBuildout ...@@ -53,7 +53,7 @@ originalBootstrapBuildout = utils.bootstrapBuildout
originalLaunchBuildout = utils.launchBuildout originalLaunchBuildout = utils.launchBuildout
originalUploadSoftwareRelease = SlapObject.Software.uploadSoftwareRelease originalUploadSoftwareRelease = SlapObject.Software.uploadSoftwareRelease
class TestSoftwareSlapObject(BasicMixin, unittest.TestCase): class TestSoftwareSlapObject(BasicMixin, unittest2.TestCase):
""" """
Test for Software class. Test for Software class.
""" """
...@@ -107,22 +107,14 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase): ...@@ -107,22 +107,14 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
software.install() software.install()
command_list = FakeCallAndRead.external_command_list command_list = FakeCallAndRead.external_command_list
self.assertTrue('buildout:networkcache-section=networkcache' self.assertIn('buildout:networkcache-section=networkcache', command_list)
in command_list) self.assertIn('networkcache:signature-private-key-file=%s' % self.signature_private_key_file, command_list)
self.assertTrue('networkcache:signature-private-key-file=%s' % self.assertIn('networkcache:upload-cache-url=%s' % self.upload_cache_url, command_list)
self.signature_private_key_file in command_list) self.assertIn('networkcache:upload-dir-url=%s' % self.upload_dir_url, command_list)
self.assertTrue('networkcache:upload-cache-url=%s' % self.upload_cache_url self.assertIn('networkcache:shacache-cert-file=%s' % self.shacache_cert_file, command_list)
in command_list) self.assertIn('networkcache:shacache-key-file=%s' % self.shacache_key_file, command_list)
self.assertTrue('networkcache:upload-dir-url=%s' % self.upload_dir_url self.assertIn('networkcache:shadir-cert-file=%s' % self.shadir_cert_file, command_list)
in command_list) self.assertIn('networkcache:shadir-key-file=%s' % self.shadir_key_file, command_list)
self.assertTrue('networkcache:shacache-cert-file=%s' % self.shacache_cert_file
in command_list)
self.assertTrue('networkcache:shacache-key-file=%s' % self.shacache_key_file
in command_list)
self.assertTrue('networkcache:shadir-cert-file=%s' % self.shadir_cert_file
in command_list)
self.assertTrue('networkcache:shadir-key-file=%s' % self.shadir_key_file
in command_list)
def test_software_install_without_networkcache(self): def test_software_install_without_networkcache(self):
""" """
......
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