Added test for image create from local file

Implements blueprint: horizon-integration-tests-coverage

Change-Id: Id1075a3812d4da020e78d2cd3266e7ab889cf2d5
This commit is contained in:
Yury Tregubov 2016-03-17 13:23:50 +04:00
parent 4da4bf44c3
commit 243394ae61
2 changed files with 49 additions and 11 deletions

View File

@ -14,6 +14,7 @@ import contextlib
import datetime import datetime
import os import os
import socket import socket
import tempfile
import time import time
import traceback import traceback
import uuid import uuid
@ -51,6 +52,20 @@ def gen_random_resource_name(resource="", timestamp=True):
return "_".join(fields) return "_".join(fields)
@contextlib.contextmanager
def gen_temporary_file(name='', suffix='.qcow2', size=10485760):
"""Generate temporary file with provided parameters.
:param name: file name except the extension /suffix
:param suffix: file extension/suffix
:param size: size of the file to create, bytes are generated randomly
:return: path to the generated file
"""
with tempfile.NamedTemporaryFile(prefix=name, suffix=suffix) as tmp_file:
tmp_file.write(os.urandom(size))
yield tmp_file.name
class BaseTestCase(testtools.TestCase): class BaseTestCase(testtools.TestCase):
CONFIG = config.get_config() CONFIG = config.get_config()

View File

@ -22,6 +22,27 @@ class TestImagesBasic(helpers.TestCase):
def images_page(self): def images_page(self):
return self.home_pg.go_to_compute_imagespage() return self.home_pg.go_to_compute_imagespage()
def image_create(self, local_file=None):
images_page = self.images_page
if local_file:
images_page.create_image(IMAGE_NAME,
image_source_type='file',
image_file=local_file)
else:
images_page.create_image(IMAGE_NAME)
self.assertTrue(images_page.find_message_and_dismiss(messages.SUCCESS))
self.assertFalse(images_page.find_message_and_dismiss(messages.ERROR))
self.assertTrue(images_page.is_image_present(IMAGE_NAME))
self.assertTrue(images_page.is_image_active(IMAGE_NAME))
return images_page
def image_delete(self):
images_page = self.images_page
images_page.delete_image(IMAGE_NAME)
self.assertTrue(images_page.find_message_and_dismiss(messages.SUCCESS))
self.assertFalse(images_page.find_message_and_dismiss(messages.ERROR))
self.assertFalse(images_page.is_image_present(IMAGE_NAME))
def test_image_create_delete(self): def test_image_create_delete(self):
"""tests the image creation and deletion functionalities: """tests the image creation and deletion functionalities:
* creates a new image from horizon.conf http_image * creates a new image from horizon.conf http_image
@ -29,18 +50,20 @@ class TestImagesBasic(helpers.TestCase):
* deletes the newly created image * deletes the newly created image
* verifies the image does not appear in the table after deletion * verifies the image does not appear in the table after deletion
""" """
images_page = self.images_page self.image_create()
self.image_delete()
images_page.create_image(IMAGE_NAME) def test_image_create_delete_from_local_file(self):
self.assertTrue(images_page.find_message_and_dismiss(messages.SUCCESS)) """tests the image creation and deletion functionalities:
self.assertFalse(images_page.find_message_and_dismiss(messages.ERROR)) * downloads image from horizon.conf stated in http_image
self.assertTrue(images_page.is_image_present(IMAGE_NAME)) * creates the image from the downloaded file
self.assertTrue(images_page.is_image_active(IMAGE_NAME)) * verifies the image appears in the images table as active
* deletes the newly created image
images_page.delete_image(IMAGE_NAME) * verifies the image does not appear in the table after deletion
self.assertTrue(images_page.find_message_and_dismiss(messages.SUCCESS)) """
self.assertFalse(images_page.find_message_and_dismiss(messages.ERROR)) with helpers.gen_temporary_file() as file_name:
self.assertFalse(images_page.is_image_present(IMAGE_NAME)) self.image_create(local_file=file_name)
self.image_delete()
def test_images_pagination(self): def test_images_pagination(self):
"""This test checks images pagination """This test checks images pagination