From d344e42cc42e418003199c53228ef6f2d611f8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9la=20Vancsics?= Date: Mon, 1 Aug 2016 10:04:05 +0200 Subject: [PATCH] Use assertIn, assertNotIn and assertIsNotNone Instead of using assertTrue(A * B) / assertFalse(A * B) developers should use assertNotIn, assertIn and assertIsNotNone. Change-Id: I20eb9d15fda7aadb64dea6bf33960f64bec243b0 --- murano/tests/unit/db/test_catalog.py | 2 +- .../unit/packages/versions/test_hot_v1.py | 2 +- .../unit/packages/versions/test_mpl_v1.py | 2 +- .../tests/unit/policy/test_congress_rules.py | 70 +++++++++---------- .../unit/policy/test_model_policy_enforcer.py | 8 +-- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/murano/tests/unit/db/test_catalog.py b/murano/tests/unit/db/test_catalog.py index 307860068..0fe225765 100644 --- a/murano/tests/unit/db/test_catalog.py +++ b/murano/tests/unit/db/test_catalog.py @@ -380,7 +380,7 @@ class CatalogDBTestCase(base.MuranoWithDBTestCase): self.assertEqual(2, len(res)) for cat in res: - self.assertTrue(cat.id is not None) + self.assertIsNotNone(cat.id) self.assertTrue(cat.name.startswith('cat')) def test_package_upload(self): diff --git a/murano/tests/unit/packages/versions/test_hot_v1.py b/murano/tests/unit/packages/versions/test_hot_v1.py index f755fa22e..e11acb20b 100644 --- a/murano/tests/unit/packages/versions/test_hot_v1.py +++ b/murano/tests/unit/packages/versions/test_hot_v1.py @@ -27,7 +27,7 @@ class TestHotV1(test_base.MuranoTestCase): ) package = load_utils.load_from_dir(package_dir) - self.assertNotEqual(package.supplier, None) + self.assertIsNotNone(package.supplier) self.assertEqual('Supplier Name', package.supplier['Name']) self.assertEqual({'Link': 'http://example.com', 'Text': 'Example Company'}, diff --git a/murano/tests/unit/packages/versions/test_mpl_v1.py b/murano/tests/unit/packages/versions/test_mpl_v1.py index 57e55070b..865ab4e68 100644 --- a/murano/tests/unit/packages/versions/test_mpl_v1.py +++ b/murano/tests/unit/packages/versions/test_mpl_v1.py @@ -25,7 +25,7 @@ class TestMplV1(test_base.MuranoTestCase): ) package = load_utils.load_from_dir(package_dir) - self.assertNotEqual(package.supplier, None) + self.assertIsNotNone(package.supplier) self.assertEqual('Supplier Name', package.supplier['Name']) self.assertEqual({'Link': 'http://example.com', 'Text': 'Example Company'}, diff --git a/murano/tests/unit/policy/test_congress_rules.py b/murano/tests/unit/policy/test_congress_rules.py index 30005fc72..00284853a 100644 --- a/murano/tests/unit/policy/test_congress_rules.py +++ b/murano/tests/unit/policy/test_congress_rules.py @@ -111,8 +111,8 @@ class TestCongressRules(unittest.TestCase): def test_transitive_closure(self): closure = congress.CongressRulesManager.transitive_closure( [(1, 2), (2, 3), (3, 4)]) - self.assertTrue((1, 4) in closure) - self.assertTrue((2, 4) in closure) + self.assertIn((1, 4), closure) + self.assertIn((2, 4), closure) def test_empty_model(self): congress_rules = congress.CongressRulesManager() @@ -122,49 +122,49 @@ class TestCongressRules(unittest.TestCase): def test_convert_simple_app(self): rules_str = self._create_and_check_rules_str('model') - self.assertFalse("instance." in rules_str) + self.assertNotIn("instance.", rules_str) def test_convert_model_two_instances(self): rules_str = self._create_and_check_rules_str('model_two_instances') - self.assertFalse("\"instances\"" in rules_str) + self.assertNotIn("\"instances\"", rules_str) def test_convert_model_with_relations(self): rules_str = self._create_rules_str('model_with_relations.yaml') - self.assertFalse( + self.assertNotIn( 'murano:properties+("50fa68ff-cd9a-4845-b573-2c80879d158d", ' - '"server", "8ce94f23-f16a-40a1-9d9d-a877266c315d")' in rules_str) + '"server", "8ce94f23-f16a-40a1-9d9d-a877266c315d")', rules_str) - self.assertTrue( + self.assertIn( 'murano:relationships+("50fa68ff-cd9a-4845-b573-2c80879d158d", ' - '"8ce94f23-f16a-40a1-9d9d-a877266c315d", "server")' in rules_str) + '"8ce94f23-f16a-40a1-9d9d-a877266c315d", "server")', rules_str) - self.assertTrue( + self.assertIn( 'murano:relationships+("0aafd67e-72e9-4ae0-bb62-fe724f77df2a", ' - '"ed8df2b0-ddd2-4009-b3c9-2e7a368f3cb8", "instance")' in rules_str) + '"ed8df2b0-ddd2-4009-b3c9-2e7a368f3cb8", "instance")', rules_str) def test_convert_model_transitive_relationships(self): rules_str = self._create_rules_str('model_with_relations.yaml') - self.assertTrue( + self.assertIn( 'murano:connected+("50fa68ff-cd9a-4845-b573-2c80879d158d", ' - '"8ce94f23-f16a-40a1-9d9d-a877266c315d")' in rules_str) + '"8ce94f23-f16a-40a1-9d9d-a877266c315d")', rules_str) - self.assertTrue( + self.assertIn( 'murano:connected+("8ce94f23-f16a-40a1-9d9d-a877266c315d", ' - '"fc6b8c41-166f-4fc9-a640-d82009e0a03d")' in rules_str) + '"fc6b8c41-166f-4fc9-a640-d82009e0a03d")', rules_str) def test_convert_model_services_relationship(self): rules_str = self._create_rules_str('model_with_relations.yaml') - self.assertTrue( + self.assertIn( 'murano:relationships+("3409bdd0590e4c60b70fda5e6777ff96", ' - '"8ce94f23-f16a-40a1-9d9d-a877266c315d", "services")' in rules_str) + '"8ce94f23-f16a-40a1-9d9d-a877266c315d", "services")', rules_str) - self.assertTrue( + self.assertIn( 'murano:relationships+("3409bdd0590e4c60b70fda5e6777ff96", ' - '"50fa68ff-cd9a-4845-b573-2c80879d158d", "services")' in rules_str) + '"50fa68ff-cd9a-4845-b573-2c80879d158d", "services")', rules_str) def test_convert_model_complex(self): self._create_and_check_rules_str('model_complex') @@ -189,21 +189,21 @@ class TestCongressRules(unittest.TestCase): rules_str = self._create_rules_str('model.yaml', package_loader) - self.assertTrue( + self.assertIn( 'murano:parent_types+("0c810278-7282-4e4a-9d69-7b4c36b6ce6f",' - ' "parent1")' in rules_str) + ' "parent1")', rules_str) - self.assertTrue( + self.assertIn( 'murano:parent_types+("0c810278-7282-4e4a-9d69-7b4c36b6ce6f",' - ' "parent2")' in rules_str) + ' "parent2")', rules_str) - self.assertTrue( + self.assertIn( 'murano:parent_types+("0c810278-7282-4e4a-9d69-7b4c36b6ce6f",' - ' "grand-parent")' in rules_str) + ' "grand-parent")', rules_str) - self.assertTrue( + self.assertIn( 'murano:parent_types+("0c810278-7282-4e4a-9d69-7b4c36b6ce6f",' - ' "io.murano.apps.linux.Git")' in rules_str) + ' "io.murano.apps.linux.Git")', rules_str) def test_to_dictionary(self): """test to_dictionary @@ -235,18 +235,18 @@ class TestCongressRules(unittest.TestCase): rules = congress_rules.convert(model, tenant_id=tenant_id) rules_str = ", \n".join(map(str, rules)) - self.assertTrue('murano:objects+("1", "{0}", "t1")'.format(tenant_id) - in rules_str) - self.assertTrue('murano:objects+("2", "1", "t2")' in rules_str) - self.assertTrue('murano:objects+("3", "2", "t3")' in rules_str) + self.assertIn('murano:objects+("1", "{0}", "t1")'.format(tenant_id), + rules_str) + self.assertIn('murano:objects+("2", "1", "t2")', rules_str) + self.assertIn('murano:objects+("3", "2", "t3")', rules_str) def test_environment_owner(self): model = self._load_file("model.yaml") congress_rules = congress.CongressRulesManager() rules = congress_rules.convert(model, tenant_id='tenant1') rules_str = ", \n".join(map(str, rules)) - self.assertTrue('murano:objects+("c86104748a0c4907b4c5981e6d3bce9f", ' - '"tenant1", "io.murano.Environment")' in rules_str) + self.assertIn('murano:objects+("c86104748a0c4907b4c5981e6d3bce9f", ' + '"tenant1", "io.murano.Environment")', rules_str) def test_wordpress(self): package_loader = MockPackageLoader([ @@ -295,6 +295,6 @@ class TestCongressRules(unittest.TestCase): def test_state_rule(self): rules_str = self._create_rules_str('model.yaml') - self.assertTrue( - 'murano:states+("c86104748a0c4907b4c5981e6d3bce9f", "pending")' - in rules_str) + self.assertIn( + 'murano:states+("c86104748a0c4907b4c5981e6d3bce9f", "pending")', + rules_str) diff --git a/murano/tests/unit/policy/test_model_policy_enforcer.py b/murano/tests/unit/policy/test_model_policy_enforcer.py index cd737b6b5..028466b9d 100644 --- a/murano/tests/unit/policy/test_model_policy_enforcer.py +++ b/murano/tests/unit/policy/test_model_policy_enforcer.py @@ -111,10 +111,10 @@ class TestModelPolicyEnforcer(base.MuranoTestCase): result = enforcer._parse_simulation_result( 'predeploy_errors', 'env1', congress_response) - self.assertFalse("unexpected response" in result) - self.assertTrue("Instance 1 has problem" in result) - self.assertTrue("Instance 2 has problem" in result) - self.assertFalse("Instance 3 has problem" in result) + self.assertNotIn("unexpected response", result) + self.assertIn("Instance 1 has problem", result) + self.assertIn("Instance 2 has problem", result) + self.assertNotIn("Instance 3 has problem", result) def test_none_model(self): executor = engine.TaskExecutor(self.task)