Update store image file tests
*Removed upload_image_file module -Updated and moved tests to store_image_file module *Removed upload_image_file_negative -Updated and moved tests to store_image_file_negative module *Updated store_image_file module -Updated method call -Updated image to be validated -Moved and updated immage creations to setup class *Added store_image_file_negative module -Removed unnecessary code -Moved image creations to setup class Change-Id: I8cb20c4c15493487876c7b23649e2235e6e1ae4f
This commit is contained in:
committed by
Luke Wollney
parent
5c1ba3985a
commit
cef3fc4f59
@@ -23,7 +23,12 @@ from cloudroast.images.fixtures import ImagesFixture
|
||||
|
||||
class TestStoreImageFile(ImagesFixture):
|
||||
|
||||
@tags(type='positive')
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestStoreImageFile, cls).setUpClass()
|
||||
cls.images = cls.images_behavior.create_new_images(count=2)
|
||||
|
||||
@tags(type='positive', regression='true')
|
||||
def test_store_image_file(self):
|
||||
"""
|
||||
@summary: Store image file
|
||||
@@ -37,27 +42,65 @@ class TestStoreImageFile(ImagesFixture):
|
||||
"""
|
||||
|
||||
file_data = StringIO.StringIO(('*' * 1024))
|
||||
image = self.images_behavior.create_new_image()
|
||||
|
||||
image = self.images.pop()
|
||||
|
||||
response = self.images_client.store_image_file(image.id_, file_data)
|
||||
self.assertEqual(response.status_code, 204)
|
||||
|
||||
response = self.images_client.get_image(image.id_)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
updated_image = response.entity
|
||||
self.assertIsNotNone(updated_image.checksum)
|
||||
self.assertEqual(updated_image.created_at, image.created_at)
|
||||
self.assertEqual(updated_image.file_, image.file_)
|
||||
self.assertEqual(updated_image.container_format,
|
||||
image.container_format)
|
||||
self.assertEqual(updated_image.disk_format, image.disk_format)
|
||||
self.assertEqual(updated_image.name, image.name)
|
||||
self.assertEqual(updated_image.id_, image.id_)
|
||||
self.assertEqual(updated_image.min_disk, image.min_disk)
|
||||
self.assertEqual(updated_image.min_ram, image.min_ram)
|
||||
self.assertEqual(updated_image.protected, image.protected)
|
||||
self.assertEqual(updated_image.schema, image.schema)
|
||||
self.assertEqual(updated_image.self_, image.self_)
|
||||
self.assertEqual(updated_image.size, 1024)
|
||||
self.assertEqual(updated_image.status, ImageStatus.ACTIVE)
|
||||
self.assertListEqual(updated_image.tags, image.tags)
|
||||
self.assertGreaterEqual(updated_image.updated_at, image.updated_at)
|
||||
self.assertEqual(updated_image.visibility, image.visibility)
|
||||
|
||||
errors = self.images_behavior.validate_image(updated_image)
|
||||
|
||||
if updated_image.checksum is None:
|
||||
errors.append(self.error_msg.format(
|
||||
'checksum', 'not None', updated_image.checksum))
|
||||
if updated_image.size != 1024:
|
||||
errors.append(self.error_msg.format(
|
||||
'size', 1024, updated_image.size))
|
||||
if updated_image.status != ImageStatus.ACTIVE:
|
||||
errors.append(self.error_msg.format(
|
||||
'status', ImageStatus.ACTIVE, updated_image.status))
|
||||
|
||||
self.assertEqual(errors, [])
|
||||
|
||||
@tags(type='positive', regression='true')
|
||||
def test_store_image_file_with_larger_file_size(self):
|
||||
"""
|
||||
@summary: Store image file with larger file size
|
||||
|
||||
1) Create image
|
||||
2) Store image file of a larger size
|
||||
3) Verify that the response code is 204
|
||||
4) Get image
|
||||
5) Verify that the response code is 200
|
||||
6) Verify that the image contains the correct updated properties
|
||||
"""
|
||||
|
||||
larger_file_data = StringIO.StringIO("*" * 10000 * 1024)
|
||||
|
||||
image = self.images.pop()
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
image_id=image.id_, file_data=larger_file_data)
|
||||
self.assertEqual(response.status_code, 204)
|
||||
|
||||
response = self.images_client.get_image(image_id=image.id_)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
updated_image = response.entity
|
||||
|
||||
errors = self.images_behavior.validate_image(updated_image)
|
||||
|
||||
if updated_image.checksum is None:
|
||||
errors.append(self.error_msg.format(
|
||||
'checksum', 'not None', updated_image.checksum))
|
||||
if updated_image.size != 10000 * 1024:
|
||||
errors.append(self.error_msg.format(
|
||||
'size', 10000 * 1024, updated_image.size))
|
||||
if updated_image.status != ImageStatus.ACTIVE:
|
||||
errors.append(self.error_msg.format(
|
||||
'status', ImageStatus.ACTIVE, updated_image.status))
|
||||
|
||||
self.assertEqual(errors, [])
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
"""
|
||||
Copyright 2013 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
import cStringIO as StringIO
|
||||
import unittest2 as unittest
|
||||
|
||||
from cafe.drivers.unittest.decorators import tags
|
||||
from cloudcafe.images.common.types import ImageStatus
|
||||
from cloudroast.images.fixtures import ImagesFixture
|
||||
|
||||
|
||||
class StoreImageFileNegativeTest(ImagesFixture):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(StoreImageFileNegativeTest, cls).setUpClass()
|
||||
cls.image = cls.images_behavior.create_new_image()
|
||||
cls.resources.add(cls.image.id_, cls.images_client.delete_image)
|
||||
cls.data_size = 1024
|
||||
cls.file_data = StringIO.StringIO("*" * cls.data_size)
|
||||
|
||||
@tags(type='negative', regression='true')
|
||||
def test_store_image_file_with_invalid_content_type(self):
|
||||
"""
|
||||
@summary: Store image file with invalid content type
|
||||
|
||||
1) Using a previously created image, store image file with invalid
|
||||
content type
|
||||
2) Verify response code is 415
|
||||
"""
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
image_id=self.image.id_, file_data=self.file_data,
|
||||
content_type="invalid_content_type")
|
||||
self.assertEqual(response.status_code, 415)
|
||||
|
||||
@tags(type='negative', regression='true')
|
||||
def test_store_image_file_with_blank_image_id(self):
|
||||
"""
|
||||
@summary: Store image file with blank image id
|
||||
|
||||
1) Store image file with blank image id
|
||||
2) Verify response code is 404
|
||||
"""
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
image_id="", file_data=self.file_data)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
@tags(type='negative', regression='true')
|
||||
def test_store_image_file_with_invalid_image_id(self):
|
||||
"""
|
||||
@summary: Store image file with invalid image id
|
||||
|
||||
1) Store image file with invalid image id
|
||||
2) Verify response code is 404
|
||||
"""
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
image_id="invalid_id", file_data=self.file_data)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
@unittest.skip('Bug, Redmine #3556')
|
||||
@tags(type='negative', regression='true')
|
||||
def test_store_image_file_with_duplicate_data(self):
|
||||
"""
|
||||
@summary: Store image file with duplicate data
|
||||
|
||||
1) Using a previously created image, store image file
|
||||
2) Verify response code is 204
|
||||
3) Get the image
|
||||
4) Verify that the response contains an image entity with the correct
|
||||
properties
|
||||
5) Try to store image file with duplicate data
|
||||
6) Verify response code is 409
|
||||
"""
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
self.image.id_, self.file_data)
|
||||
self.assertEqual(response.status_code, 204)
|
||||
|
||||
response = self.images_client.get_image(image_id=self.image.id_)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
updated_image = response.entity
|
||||
self.assertEqual(updated_image.id_, self.image.id_)
|
||||
self.assertEqual(updated_image.status, ImageStatus.ACTIVE)
|
||||
self.assertEqual(updated_image.size, self.data_size)
|
||||
self.assertIsNotNone(updated_image.checksum)
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
self.image.id_, self.file_data)
|
||||
self.assertEqual(response.status_code, 409)
|
||||
@@ -1,94 +0,0 @@
|
||||
"""
|
||||
Copyright 2013 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
import StringIO
|
||||
|
||||
from cafe.drivers.unittest.decorators import tags
|
||||
from cloudcafe.images.common.types import ImageStatus
|
||||
from cloudroast.images.fixtures import ImagesFixture
|
||||
|
||||
|
||||
class UploadImageFileTest(ImagesFixture):
|
||||
|
||||
@tags(type='positive', regression='true')
|
||||
def test_upload_image_file(self):
|
||||
"""
|
||||
@summary: Upload image file.
|
||||
|
||||
1. Create an image
|
||||
2. Verify that the image status is 'queued'
|
||||
3. Verify that the image size is None
|
||||
4. Verify that the image checksum is None
|
||||
5. Upload image file
|
||||
6. Verify response code is 204
|
||||
7. Get the image
|
||||
8. Verify that the response contains an image entity with the correct
|
||||
properties
|
||||
"""
|
||||
|
||||
file_data = StringIO.StringIO("*" * 1024)
|
||||
image = self.images_behavior.create_new_image()
|
||||
self.addCleanup(self.images_client.delete_image, image.id_)
|
||||
self.assertEqual(image.status, ImageStatus.QUEUED)
|
||||
self.assertIsNone(image.size)
|
||||
self.assertIsNone(image.checksum)
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
image_id=image.id_, file_data=file_data)
|
||||
self.assertEqual(response.status_code, 204)
|
||||
|
||||
response = self.images_client.get_image(image_id=image.id_)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
uploaded_image = response.entity
|
||||
self.assertEqual(uploaded_image.id_, image.id_)
|
||||
self.assertEqual(uploaded_image.status, ImageStatus.ACTIVE)
|
||||
self.assertEqual(uploaded_image.size, 1024)
|
||||
self.assertIsNotNone(uploaded_image.checksum)
|
||||
|
||||
@tags(type='positive', regression='true')
|
||||
def test_upload_image_file_with_larger_file_size(self):
|
||||
"""
|
||||
@summary: Upload image file with larger file size
|
||||
|
||||
1. Create an image
|
||||
2. Verify that the image status is 'queued'
|
||||
3. Verify that the image size is None
|
||||
4. Verify that the image checksum is None
|
||||
5. Upload image file with a larger size
|
||||
6. Verify response code is 204
|
||||
7. Get the image
|
||||
8. Verify that the response contains an image entity with the correct
|
||||
properties
|
||||
"""
|
||||
|
||||
larger_file_data = StringIO.StringIO("*" * 10000 * 1024)
|
||||
image = self.images_behavior.create_new_image()
|
||||
self.addCleanup(self.images_client.delete_image, image.id_)
|
||||
self.assertEqual(image.status, ImageStatus.QUEUED)
|
||||
self.assertIsNone(image.size)
|
||||
self.assertIsNone(image.checksum)
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
image_id=image.id_, file_data=larger_file_data)
|
||||
self.assertEqual(response.status_code, 204)
|
||||
|
||||
response = self.images_client.get_image(image_id=image.id_)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
uploaded_image = response.entity
|
||||
self.assertEqual(uploaded_image.id_, image.id_)
|
||||
self.assertEqual(uploaded_image.status, ImageStatus.ACTIVE)
|
||||
self.assertEqual(uploaded_image.size, 10000 * 1024)
|
||||
self.assertIsNotNone(uploaded_image.checksum)
|
||||
@@ -1,128 +0,0 @@
|
||||
"""
|
||||
Copyright 2013 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
import StringIO
|
||||
|
||||
from cafe.drivers.unittest.decorators import tags
|
||||
from cloudcafe.images.common.types import ImageStatus
|
||||
from cloudroast.images.fixtures import ImagesFixture
|
||||
|
||||
|
||||
class UploadImageFileNegativeTest(ImagesFixture):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(UploadImageFileNegativeTest, cls).setUpClass()
|
||||
cls.image = cls.images_behavior.create_new_image()
|
||||
cls.data_size = 1024
|
||||
cls.file_data = StringIO.StringIO("*" * cls.data_size)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super(UploadImageFileNegativeTest, cls).tearDownClass()
|
||||
cls.images_behavior.resources.release()
|
||||
|
||||
@tags(type='negative', regression='true')
|
||||
def test_upload_image_file_with_invalid_content_type(self):
|
||||
"""
|
||||
@summary: Upload image file with invalid content type
|
||||
|
||||
1. Create an image
|
||||
2. Verify that the image status is 'queued'
|
||||
3. Verify that the image size is None
|
||||
4. Verify that the image checksum is None
|
||||
5. Upload image file with invalid content type
|
||||
6. Verify response code is 415
|
||||
"""
|
||||
|
||||
self.assertEqual(self.image.status, ImageStatus.QUEUED)
|
||||
self.assertIsNone(self.image.size)
|
||||
self.assertIsNone(self.image.checksum)
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
image_id=self.image.id_, file_data=self.file_data,
|
||||
content_type="invalid_content_type")
|
||||
self.assertEqual(response.status_code, 415)
|
||||
|
||||
@tags(type='negative', regression='true')
|
||||
def test_upload_image_file_with_blank_image_id(self):
|
||||
"""
|
||||
@summary: Upload image file with blank image id
|
||||
|
||||
1. Create an image
|
||||
2. Upload image file with blank image id
|
||||
3. Verify response code is 404
|
||||
"""
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
image_id="", file_data=self.file_data)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
@tags(type='negative', regression='true')
|
||||
def test_upload_image_file_with_invalid_image_id(self):
|
||||
"""
|
||||
@summary: Upload image file with invalid image id
|
||||
|
||||
1. Create an image
|
||||
2. Upload image file with invalid image id
|
||||
3. Verify response code is 404
|
||||
"""
|
||||
|
||||
response = self.images_client.store_image_file(
|
||||
image_id="invalid_id", file_data=self.file_data)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
@tags(type='negative', regression='true')
|
||||
def test_upload_image_file_with_duplicate_data(self):
|
||||
"""
|
||||
@summary: Upload image file with duplicate data
|
||||
|
||||
1. Create an image
|
||||
2. Verify that the image status is 'queued'
|
||||
3. Verify that the image size is None
|
||||
4. Verify that the image checksum is None
|
||||
5. Upload image file
|
||||
6. Verify response code is 204
|
||||
7. Get the image
|
||||
8. Verify that the response contains an image entity with the correct
|
||||
properties
|
||||
9. Try to upload image file with duplicate data
|
||||
10. Verify response code is 409
|
||||
"""
|
||||
|
||||
self.assertEqual(self.image.status, ImageStatus.QUEUED)
|
||||
self.assertIsNone(self.image.size)
|
||||
self.assertIsNone(self.image.checksum)
|
||||
|
||||
file_data = StringIO.StringIO("*" * self.data_size)
|
||||
response = self.images_client.store_image_file(
|
||||
image_id=self.image.id_,
|
||||
file_data=file_data)
|
||||
self.assertEqual(response.status_code, 204)
|
||||
|
||||
response = self.images_client.get_image(image_id=self.image.id_)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
uploaded_image = response.entity
|
||||
self.assertEqual(uploaded_image.id_, self.image.id_)
|
||||
self.assertEqual(uploaded_image.status, ImageStatus.ACTIVE)
|
||||
self.assertEqual(uploaded_image.size, self.data_size)
|
||||
self.assertIsNotNone(uploaded_image.checksum)
|
||||
|
||||
duplicate_file = StringIO.StringIO("*" * self.data_size)
|
||||
response = self.images_client.store_image_file(
|
||||
image_id=self.image.id_,
|
||||
file_data=duplicate_file)
|
||||
self.assertEqual(response.status_code, 409)
|
||||
Reference in New Issue
Block a user