From 37508da788c5b2c2eadb36ef61d58836d93a3365 Mon Sep 17 00:00:00 2001 From: Ken Pepple Date: Sat, 20 Aug 2011 12:41:38 -0700 Subject: improve test coverage for instance types / flavors --- nova/tests/test_instance_types.py | 66 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py index ef271518c..989c6f32f 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_instance_types.py @@ -47,6 +47,29 @@ class InstanceTypeTestCase(test.TestCase): self.id = max_id["id"] + 1 self.name = str(int(time.time())) + def _nonexistant_flavor_name(self): + """return an instance type name not in the DB""" + nonexistant_flavor = "sdfsfsdf" + flavors = instance_types.get_all_types() + while flavors.has_key(nonexistant_flavor): + nonexistant_flavor = nonexistant_flavor.join("z") + else: + return nonexistant_flavor + + def _nonexistant_flavor_id(self): + """return an instance type ID not in the DB""" + nonexistant_flavor = 2700 + flavor_ids = [ value["id"] for key, value in\ + instance_types.get_all_types().iteritems() ] + while nonexistant_flavor in flavor_ids: + nonexistant_flavor += 1 + else: + return nonexistant_flavor + + def _existing_flavor(self): + """return first instance type name""" + return instance_types.get_all_types().keys()[0] + def test_instance_type_create_then_delete(self): """Ensure instance types can be created""" starting_inst_list = instance_types.get_all_types() @@ -87,7 +110,8 @@ class InstanceTypeTestCase(test.TestCase): def test_non_existant_inst_type_shouldnt_delete(self): """Ensures that instance type creation fails with invalid args""" self.assertRaises(exception.ApiError, - instance_types.destroy, "sfsfsdfdfs") + instance_types.destroy, + self._nonexistant_flavor_name()) def test_repeated_inst_types_should_raise_api_error(self): """Ensures that instance duplicates raises ApiError""" @@ -97,3 +121,43 @@ class InstanceTypeTestCase(test.TestCase): self.assertRaises( exception.ApiError, instance_types.create, new_name, 256, 1, 120, self.flavorid) + + def test_will_not_destroy_with_no_name(self): + """Ensure destroy sad path of no name raises error""" + self.assertRaises(exception.ApiError, + instance_types.destroy, + self._nonexistant_flavor_name()) + + def test_will_not_purge_without_name(self): + """Ensure purge without a name raises error""" + self.assertRaises(exception.InvalidInstanceType, + instance_types.purge, None) + + def test_will_not_purge_with_wrong_name(self): + """Ensure purge without correct name raises error""" + self.assertRaises(exception.ApiError, + instance_types.purge, + self._nonexistant_flavor_name()) + + def test_will_not_get_bad_default_instance_type(self): + """ensures error raised on bad default instance type""" + FLAGS.default_instance_type = self._nonexistant_flavor_name() + self.assertRaises(exception.InstanceTypeNotFoundByName, + instance_types.get_default_instance_type) + + def test_will_not_get_instance_type_by_name_with_no_name(self): + """Ensure get by name returns default flavor with no name""" + self.assertEqual(instance_types.get_default_instance_type(), + instance_types.get_instance_type_by_name(None)) + + def test_will_not_get_instance_type_with_bad_name(self): + """Ensure get by name returns default flavor with bad name""" + self.assertRaises(exception.InstanceTypeNotFound, + instance_types.get_instance_type, + self._nonexistant_flavor_name()) + + def test_will_not_get_flavor_by_bad_flavor_id(self): + """Ensure get by flavor raises error with wrong flavorid""" + self.assertRaises(exception.InstanceTypeNotFound, + instance_types.get_instance_type_by_name, + self._nonexistant_flavor_id()) -- cgit From 65b30ad73338fa481d1ab9155153b8265fbe8f90 Mon Sep 17 00:00:00 2001 From: Ken Pepple Date: Sat, 20 Aug 2011 12:43:50 -0700 Subject: pep8 --- nova/tests/test_instance_types.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py index 989c6f32f..556ba91a9 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_instance_types.py @@ -51,20 +51,20 @@ class InstanceTypeTestCase(test.TestCase): """return an instance type name not in the DB""" nonexistant_flavor = "sdfsfsdf" flavors = instance_types.get_all_types() - while flavors.has_key(nonexistant_flavor): - nonexistant_flavor = nonexistant_flavor.join("z") + while nonexistant_flavor in flavors: + nonexistant_flavor = nonexistant_flavor.join("z") else: - return nonexistant_flavor + return nonexistant_flavor def _nonexistant_flavor_id(self): """return an instance type ID not in the DB""" nonexistant_flavor = 2700 - flavor_ids = [ value["id"] for key, value in\ - instance_types.get_all_types().iteritems() ] + flavor_ids = [value["id"] for key, value in\ + instance_types.get_all_types().iteritems()] while nonexistant_flavor in flavor_ids: - nonexistant_flavor += 1 + nonexistant_flavor += 1 else: - return nonexistant_flavor + return nonexistant_flavor def _existing_flavor(self): """return first instance type name""" @@ -127,12 +127,12 @@ class InstanceTypeTestCase(test.TestCase): self.assertRaises(exception.ApiError, instance_types.destroy, self._nonexistant_flavor_name()) - + def test_will_not_purge_without_name(self): """Ensure purge without a name raises error""" self.assertRaises(exception.InvalidInstanceType, instance_types.purge, None) - + def test_will_not_purge_with_wrong_name(self): """Ensure purge without correct name raises error""" self.assertRaises(exception.ApiError, @@ -149,7 +149,7 @@ class InstanceTypeTestCase(test.TestCase): """Ensure get by name returns default flavor with no name""" self.assertEqual(instance_types.get_default_instance_type(), instance_types.get_instance_type_by_name(None)) - + def test_will_not_get_instance_type_with_bad_name(self): """Ensure get by name returns default flavor with bad name""" self.assertRaises(exception.InstanceTypeNotFound, -- cgit From e30d2c372cc36d7e9a6cf3af5016834b499a7b42 Mon Sep 17 00:00:00 2001 From: Ken Pepple Date: Wed, 24 Aug 2011 15:18:17 -0700 Subject: fixing inappropriate rubyism in test code --- nova/tests/test_instance_types.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py index 556ba91a9..409a22fb6 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_instance_types.py @@ -47,24 +47,24 @@ class InstanceTypeTestCase(test.TestCase): self.id = max_id["id"] + 1 self.name = str(int(time.time())) - def _nonexistant_flavor_name(self): + def _nonexistent_flavor_name(self): """return an instance type name not in the DB""" - nonexistant_flavor = "sdfsfsdf" + nonexistent_flavor = "sdfsfsdf" flavors = instance_types.get_all_types() - while nonexistant_flavor in flavors: - nonexistant_flavor = nonexistant_flavor.join("z") + while nonexistent_flavor in flavors: + nonexistent_flavor += "z" else: - return nonexistant_flavor + return nonexistent_flavor - def _nonexistant_flavor_id(self): + def _nonexistent_flavor_id(self): """return an instance type ID not in the DB""" - nonexistant_flavor = 2700 + nonexistent_flavor = 2700 flavor_ids = [value["id"] for key, value in\ instance_types.get_all_types().iteritems()] - while nonexistant_flavor in flavor_ids: - nonexistant_flavor += 1 + while nonexistent_flavor in flavor_ids: + nonexistent_flavor += 1 else: - return nonexistant_flavor + return nonexistent_flavor def _existing_flavor(self): """return first instance type name""" @@ -111,7 +111,7 @@ class InstanceTypeTestCase(test.TestCase): """Ensures that instance type creation fails with invalid args""" self.assertRaises(exception.ApiError, instance_types.destroy, - self._nonexistant_flavor_name()) + self._nonexistent_flavor_name()) def test_repeated_inst_types_should_raise_api_error(self): """Ensures that instance duplicates raises ApiError""" @@ -126,7 +126,7 @@ class InstanceTypeTestCase(test.TestCase): """Ensure destroy sad path of no name raises error""" self.assertRaises(exception.ApiError, instance_types.destroy, - self._nonexistant_flavor_name()) + self._nonexistent_flavor_name()) def test_will_not_purge_without_name(self): """Ensure purge without a name raises error""" @@ -137,11 +137,11 @@ class InstanceTypeTestCase(test.TestCase): """Ensure purge without correct name raises error""" self.assertRaises(exception.ApiError, instance_types.purge, - self._nonexistant_flavor_name()) + self._nonexistent_flavor_name()) def test_will_not_get_bad_default_instance_type(self): """ensures error raised on bad default instance type""" - FLAGS.default_instance_type = self._nonexistant_flavor_name() + FLAGS.default_instance_type = self._nonexistent_flavor_name() self.assertRaises(exception.InstanceTypeNotFoundByName, instance_types.get_default_instance_type) @@ -154,10 +154,10 @@ class InstanceTypeTestCase(test.TestCase): """Ensure get by name returns default flavor with bad name""" self.assertRaises(exception.InstanceTypeNotFound, instance_types.get_instance_type, - self._nonexistant_flavor_name()) + self._nonexistent_flavor_name()) def test_will_not_get_flavor_by_bad_flavor_id(self): """Ensure get by flavor raises error with wrong flavorid""" self.assertRaises(exception.InstanceTypeNotFound, instance_types.get_instance_type_by_name, - self._nonexistant_flavor_id()) + self._nonexistent_flavor_id()) -- cgit From dde9fdc6665e2562ec490fe43f46dcf945c59220 Mon Sep 17 00:00:00 2001 From: Ken Pepple Date: Wed, 24 Aug 2011 16:03:32 -0700 Subject: removes french spellings to satisfy american developers --- nova/tests/test_instance_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py index 409a22fb6..09f532239 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_instance_types.py @@ -107,7 +107,7 @@ class InstanceTypeTestCase(test.TestCase): exception.InvalidInput, instance_types.create, self.name, 256, 1, "aa", self.flavorid) - def test_non_existant_inst_type_shouldnt_delete(self): + def test_non_existent_inst_type_shouldnt_delete(self): """Ensures that instance type creation fails with invalid args""" self.assertRaises(exception.ApiError, instance_types.destroy, -- cgit