From 243394ae6120be0010790f8a91ef9fd03210c8e7 Mon Sep 17 00:00:00 2001 From: Yury Tregubov Date: Thu, 17 Mar 2016 13:23:50 +0400 Subject: [PATCH] Added test for image create from local file Implements blueprint: horizon-integration-tests-coverage Change-Id: Id1075a3812d4da020e78d2cd3266e7ab889cf2d5 --- .../test/integration_tests/helpers.py | 15 +++++++ .../integration_tests/tests/test_images.py | 45 ++++++++++++++----- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/openstack_dashboard/test/integration_tests/helpers.py b/openstack_dashboard/test/integration_tests/helpers.py index 64fdcdba1d..fb832bcdb4 100644 --- a/openstack_dashboard/test/integration_tests/helpers.py +++ b/openstack_dashboard/test/integration_tests/helpers.py @@ -14,6 +14,7 @@ import contextlib import datetime import os import socket +import tempfile import time import traceback import uuid @@ -51,6 +52,20 @@ def gen_random_resource_name(resource="", timestamp=True): 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): CONFIG = config.get_config() diff --git a/openstack_dashboard/test/integration_tests/tests/test_images.py b/openstack_dashboard/test/integration_tests/tests/test_images.py index 11735e8aa0..e181c791aa 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_images.py +++ b/openstack_dashboard/test/integration_tests/tests/test_images.py @@ -22,6 +22,27 @@ class TestImagesBasic(helpers.TestCase): def images_page(self): 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): """tests the image creation and deletion functionalities: * creates a new image from horizon.conf http_image @@ -29,18 +50,20 @@ class TestImagesBasic(helpers.TestCase): * deletes the newly created image * 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) - 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)) - - 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_from_local_file(self): + """tests the image creation and deletion functionalities: + * downloads image from horizon.conf stated in http_image + * creates the image from the downloaded file + * verifies the image appears in the images table as active + * deletes the newly created image + * verifies the image does not appear in the table after deletion + """ + with helpers.gen_temporary_file() as file_name: + self.image_create(local_file=file_name) + self.image_delete() def test_images_pagination(self): """This test checks images pagination