From d2ca9487038e41d28c96df7bed4965edb015dc6b Mon Sep 17 00:00:00 2001 From: melanie witt Date: Wed, 17 Dec 2014 00:13:50 +0000 Subject: [PATCH] initialize objects with context in Flavor object tests These changes aim to clean up the pattern of passing a context in object member functions create/destroy/refresh/save and instead initialize the object with the context when it's constructed. Related to blueprint kilo-objects Change-Id: I02458af37e0c39d9a9d7309a9a3cc1d2545f3da1 --- nova/tests/unit/objects/test_flavor.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/nova/tests/unit/objects/test_flavor.py b/nova/tests/unit/objects/test_flavor.py index a7189d4caa..9f303dcb91 100644 --- a/nova/tests/unit/objects/test_flavor.py +++ b/nova/tests/unit/objects/test_flavor.py @@ -86,13 +86,13 @@ class _TestFlavor(object): remove.assert_called_once_with(elevated, '123', '456') def test_create(self): - flavor = flavor_obj.Flavor() + flavor = flavor_obj.Flavor(context=self.context) flavor.name = 'm1.foo' flavor.extra_specs = fake_flavor['extra_specs'] with mock.patch.object(db, 'flavor_create') as create: create.return_value = fake_flavor - flavor.create(self.context) + flavor.create() self.assertEqual(self.context, flavor._context) # NOTE(danms): Orphan this to avoid lazy-loads @@ -101,7 +101,7 @@ class _TestFlavor(object): def test_create_with_projects(self): context = self.context.elevated() - flavor = flavor_obj.Flavor() + flavor = flavor_obj.Flavor(context=context) flavor.name = 'm1.foo' flavor.extra_specs = fake_flavor['extra_specs'] flavor.projects = ['project-1', 'project-2'] @@ -115,7 +115,7 @@ class _TestFlavor(object): methods['flavor_access_get_by_flavor_id'].return_value = [ {'project_id': 'project-1'}, {'project_id': 'project-2'}] - flavor.create(context) + flavor.create() methods['flavor_create'].assert_called_once_with( context, {'name': 'm1.foo', @@ -199,9 +199,9 @@ class _TestFlavor(object): self.assertRaises(exception.ObjectActionError, flavor.save) def test_destroy(self): - flavor = flavor_obj.Flavor(id=123, name='foo') + flavor = flavor_obj.Flavor(context=self.context, id=123, name='foo') with mock.patch.object(db, 'flavor_destroy') as destroy: - flavor.destroy(self.context) + flavor.destroy() destroy.assert_called_once_with(self.context, flavor.name) def test_load_projects(self):