Use FakeImage in server test cases.

We have a class FakeImage to fake one or more images. So use it in
test_server.py.

Change-Id: I276e4ade5aecefbe66b9722c1dfbac10b3bd14b6
Implements: blueprint improve-image-unittest-framework
This commit is contained in:
Tang Chen 2015-12-08 10:05:36 +08:00
parent 481b711fae
commit a4696dce1e

View File

@ -107,11 +107,7 @@ class TestServerCreate(TestServer):
self.servers_mock.create.return_value = self.new_server
self.image = fakes.FakeResource(
None,
copy.deepcopy(image_fakes.IMAGE),
loaded=True,
)
self.image = image_fakes.FakeImage.create_one_image()
self.cimages_mock.get.return_value = self.image
self.flavor = compute_fakes.FakeFlavor.create_one_flavor()
@ -537,13 +533,9 @@ class TestServerImageCreate(TestServer):
# This is the return value for utils.find_resource()
self.servers_mock.get.return_value = self.server
self.servers_mock.create_image.return_value = image_fakes.image_id
self.images_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(image_fakes.IMAGE),
loaded=True,
)
self.image = image_fakes.FakeImage.create_one_image()
self.images_mock.get.return_value = self.image
self.servers_mock.create_image.return_value = self.image.id
# Get the command object to test
self.cmd = server.CreateServerImage(self.app, None)
@ -569,12 +561,12 @@ class TestServerImageCreate(TestServer):
collist = ('id', 'name', 'owner', 'protected', 'tags', 'visibility')
self.assertEqual(collist, columns)
datalist = (
image_fakes.image_id,
image_fakes.image_name,
image_fakes.image_owner,
image_fakes.image_protected,
image_fakes.image_tags,
image_fakes.image_visibility,
self.image.id,
self.image.name,
self.image.owner,
self.image.protected,
self.image.tags,
self.image.visibility,
)
self.assertEqual(datalist, data)
@ -601,12 +593,12 @@ class TestServerImageCreate(TestServer):
collist = ('id', 'name', 'owner', 'protected', 'tags', 'visibility')
self.assertEqual(collist, columns)
datalist = (
image_fakes.image_id,
image_fakes.image_name,
image_fakes.image_owner,
image_fakes.image_protected,
image_fakes.image_tags,
image_fakes.image_visibility,
self.image.id,
self.image.name,
self.image.owner,
self.image.protected,
self.image.tags,
self.image.visibility,
)
self.assertEqual(datalist, data)