From 600a67301db8f7739e7dfc74451a23a1f194a60c Mon Sep 17 00:00:00 2001 From: AlexandraAllakhverdieva Date: Fri, 15 Jan 2016 11:18:38 -0500 Subject: [PATCH] Add test_images_pagination() Test for images pagination has been added. Changes of TableRegion class: 1) Locators of 'Next' and 'Prev' links are added 2) Methods is_next_link_available() and is_prev_link_available() 3) Methods for pages navigation added: next_page() and prev_page()a 4) update assert_definition method to have list instead of srt for 'Names' key 5) change 'next' locator 6) Minor changes: remove unused class, rename next_page/prev_page methods Implements blueprint: horizon-integration-tests-coverage Change-Id: Ibaf9dd02a06cf9d945bc9b894394695512a934b9 --- .../test/integration_tests/config.py | 5 + .../test/integration_tests/horizon.conf | 3 + .../pages/admin/system/imagespage.py | 17 +++ .../pages/project/compute/imagespage.py | 1 + .../test/integration_tests/regions/tables.py | 34 +++++ .../tests/test_image_create_delete.py | 129 ++++++++++++++++++ 6 files changed, 189 insertions(+) create mode 100644 openstack_dashboard/test/integration_tests/pages/admin/system/imagespage.py diff --git a/openstack_dashboard/test/integration_tests/config.py b/openstack_dashboard/test/integration_tests/config.py index 399d15f3d2..b255e57b3e 100644 --- a/openstack_dashboard/test/integration_tests/config.py +++ b/openstack_dashboard/test/integration_tests/config.py @@ -47,6 +47,11 @@ ImageGroup = [ default='http://download.cirros-cloud.net/0.3.1/' 'cirros-0.3.1-x86_64-uec.tar.gz', help='http accessible image'), + cfg.ListOpt('images_list', + default=['cirros-0.3.4-x86_64-uec', + 'cirros-0.3.4-x86_64-uec-kernel', + 'cirros-0.3.4-x86_64-uec-ramdisk'], + help='default list of images') ] SeleniumGroup = [ diff --git a/openstack_dashboard/test/integration_tests/horizon.conf b/openstack_dashboard/test/integration_tests/horizon.conf index ffb5fc8e61..f44d304a47 100644 --- a/openstack_dashboard/test/integration_tests/horizon.conf +++ b/openstack_dashboard/test/integration_tests/horizon.conf @@ -32,6 +32,9 @@ explicit_wait=300 [image] # http accessible image (string value) http_image=http://download.cirros-cloud.net/0.3.1/cirros-0.3.1-x86_64-uec.tar.gz +images_list=cirros-0.3.4-x86_64-uec, + cirros-0.3.4-x86_64-uec-kernel, + cirros-0.3.4-x86_64-uec-ramdisk [identity] # Username to use for non-admin API requests. (string value) diff --git a/openstack_dashboard/test/integration_tests/pages/admin/system/imagespage.py b/openstack_dashboard/test/integration_tests/pages/admin/system/imagespage.py new file mode 100644 index 0000000000..4af2403e04 --- /dev/null +++ b/openstack_dashboard/test/integration_tests/pages/admin/system/imagespage.py @@ -0,0 +1,17 @@ +# 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. +from openstack_dashboard.test.integration_tests.pages.project.compute \ + import imagespage + + +class ImagesPage(imagespage.ImagesPage): + pass diff --git a/openstack_dashboard/test/integration_tests/pages/project/compute/imagespage.py b/openstack_dashboard/test/integration_tests/pages/project/compute/imagespage.py index 80a7882df3..0b79bec6a8 100644 --- a/openstack_dashboard/test/integration_tests/pages/project/compute/imagespage.py +++ b/openstack_dashboard/test/integration_tests/pages/project/compute/imagespage.py @@ -19,6 +19,7 @@ from openstack_dashboard.test.integration_tests.regions import tables class ImagesTable(tables.TableRegion): name = "images" + CREATE_IMAGE_FORM_FIELDS = ( "name", "description", "source_type", "image_url", "image_file", "kernel", "ramdisk", diff --git a/openstack_dashboard/test/integration_tests/regions/tables.py b/openstack_dashboard/test/integration_tests/regions/tables.py index a06f9919e1..a9ea0ea29d 100644 --- a/openstack_dashboard/test/integration_tests/regions/tables.py +++ b/openstack_dashboard/test/integration_tests/regions/tables.py @@ -53,6 +53,10 @@ class TableRegion(baseregion.BaseRegion): 'div.table_search.client > input') _search_button_locator = (by.By.CSS_SELECTOR, 'div.table_search.client > button') + _next_locator = (by.By.CSS_SELECTOR, + 'tfoot > tr > td > a[href^="?marker"]') + _prev_locator = (by.By.CSS_SELECTOR, + 'tfoot > tr > td > a[href*="prev_marker"]') def _table_locator(self, table_name): return by.By.CSS_SELECTOR, 'table#%s' % table_name @@ -124,6 +128,36 @@ class TableRegion(baseregion.BaseRegion): return [RowRegion(self.driver, self.conf, elem, self.column_names) for elem in self._get_elements(*self._rows_locator)] + def is_next_link_available(self): + return self._is_element_visible(*self._next_locator) + + def is_prev_link_available(self): + return self._is_element_visible(*self._prev_locator) + + def turn_next_page(self): + if self.is_next_link_available(): + lnk = self._get_element(*self._next_locator) + lnk.click() + + def turn_prev_page(self): + if self.is_prev_link_available(): + lnk = self._get_element(*self._prev_locator) + lnk.click() + + def assert_definition(self, expected_table_definition): + """Checks that actual image table is expected one. + Items to compare: 'next' and 'prev' links, count of rows and names of + images in list + :param expected_table_definition: expected values (dictionary) + :return: + """ + names = [row.cells['name'].text for row in self.rows] + actual_table = {'Next': self.is_next_link_available(), + 'Prev': self.is_prev_link_available(), + 'Count': len(self.rows), + 'Names': names} + self.assertDictEqual(actual_table, expected_table_definition) + def bind_table_action(action_name): """A decorator to bind table region method to an actual table action diff --git a/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py b/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py index c9eaa008eb..cff25ed756 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py +++ b/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py @@ -37,3 +37,132 @@ class TestImage(helpers.TestCase): 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(self.IMAGE_NAME)) + + def test_images_pagination(self): + """This test checks images pagination + Steps: + 1) Login to Horizon Dashboard as horizon user + 2) Navigate to user settings page + 3) Change 'Items Per Page' value to 1 + 4) Go to Project -> Compute -> Images page + 5) Check that only 'Next' link is available, only one image is + available (and it has correct name) + 6) Click 'Next' and check that both 'Prev' and 'Next' links are + available, only one image is available (and it has correct name) + 7) Click 'Next' and check that only 'Prev' link is available, + only one image is visible (and it has correct name) + 8) Click 'Prev' and check results (should be the same as for step6) + 9) Click 'Prev' and check results (should be the same as for step5) + 10) Go to user settings page and restore 'Items Per Page' + """ + default_image_list = self.CONFIG.image.images_list + items_per_page = 1 + first_page_definition = {'Next': True, 'Prev': False, + 'Count': items_per_page, + 'Names': [default_image_list[0]]} + second_page_definition = {'Next': True, 'Prev': True, + 'Count': items_per_page, + 'Names': [default_image_list[1]]} + third_page_definition = {'Next': False, 'Prev': True, + 'Count': items_per_page, + 'Names': [default_image_list[2]]} + + settings_page = self.home_pg.go_to_settings_usersettingspage() + settings_page.change_pagesize(items_per_page) + settings_page.find_message_and_dismiss(messages.SUCCESS) + + images_page = self.home_pg.go_to_compute_imagespage() + images_page.images_table.assert_definition(first_page_definition) + + images_page.images_table.turn_next_page() + images_page.images_table.assert_definition(second_page_definition) + + images_page.images_table.turn_next_page() + images_page.images_table.assert_definition(third_page_definition) + + images_page.images_table.turn_prev_page() + images_page.images_table.assert_definition(second_page_definition) + + images_page.images_table.turn_prev_page() + images_page.images_table.assert_definition(first_page_definition) + + settings_page = self.home_pg.go_to_settings_usersettingspage() + settings_page.change_pagesize() + settings_page.find_message_and_dismiss(messages.SUCCESS) + + +class TestImageAdmin(helpers.AdminTestCase): + IMAGE_NAME = helpers.gen_random_resource_name("image") + + def test_image_create_delete_under_admin(self): + """tests the image creation and deletion functionalities under Admin: + * creates a new image from horizon.conf http_image + * 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 + """ + + images_page = self.home_pg.go_to_system_imagespage() + + images_page.create_image(self.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(self.IMAGE_NAME)) + self.assertTrue(images_page.is_image_active(self.IMAGE_NAME)) + + images_page.delete_image(self.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(self.IMAGE_NAME)) + + def test_images_pagination_under_admin(self): + """This test checks images pagination under admin user + Steps: + 1) Login to Horizon Dashboard as admin user + 2) Navigate to user settings page + 3) Change 'Items Per Page' value to 1 + 4) Go to Admin -> System -> Images page + 5) Check that only 'Next' link is available, only one image is + available (and it has correct name) + 6) Click 'Next' and check that both 'Prev' and 'Next' links are + available, only one image is available (and it has correct name) + 7) Click 'Next' and check that only 'Prev' link is available, + only one image is visible (and it has correct name) + 8) Click 'Prev' and check results (should be the same as for step6) + 9) Click 'Prev' and check results (should be the same as for step5) + 10) Go to user settings page and restore 'Items Per Page' + """ + default_image_list = self.CONFIG.image.images_list + items_per_page = 1 + first_page_definition = {'Next': True, 'Prev': False, + 'Count': items_per_page, + 'Names': [default_image_list[0]]} + second_page_definition = {'Next': True, 'Prev': True, + 'Count': items_per_page, + 'Names': [default_image_list[1]]} + third_page_definition = {'Next': False, 'Prev': True, + 'Count': items_per_page, + 'Names': [default_image_list[2]]} + + settings_page = self.home_pg.go_to_settings_usersettingspage() + settings_page.change_pagesize(items_per_page) + settings_page.find_message_and_dismiss(messages.SUCCESS) + + images_page = self.home_pg.go_to_system_imagespage() + images_page.images_table.assert_definition(first_page_definition) + + images_page.images_table.turn_next_page() + images_page.images_table.assert_definition(second_page_definition) + + images_page.images_table.turn_next_page() + images_page.images_table.assert_definition(third_page_definition) + + images_page.images_table.turn_prev_page() + images_page.images_table.assert_definition(second_page_definition) + + images_page.images_table.turn_prev_page() + images_page.images_table.assert_definition(first_page_definition) + + settings_page = self.home_pg.go_to_settings_usersettingspage() + settings_page.change_pagesize() + settings_page.find_message_and_dismiss(messages.SUCCESS)