From bf32b9eb917c2f4d99f8e1a2d330c6df4f2c69bf Mon Sep 17 00:00:00 2001 From: TatyanaGladysheva Date: Tue, 19 Jan 2016 10:26:34 +0300 Subject: [PATCH] Added test for check instances pagination functionality -added test for instance creation/deletion functionality under regular user -updated test for instance creation/deletion functionality under admin -added tests for pagination instances under regular user and under admin -added test for pagination and filtration instances under regular user and under admin Changes in TableRegion class: 1) _search_field_locator has been modified (now it works with both classes: "table_search" and "table_search client") 2) _search_button_locator has been modified 3) filter() method has been updated 4) _search_option_locator and set_filter_value() method have been added Implements blueprint: horizon-integration-tests-coverage Change-Id: I6be5511e22644f85a53a781f417c5fde7fbf0275 --- .../pages/admin/system/instancespage.py | 18 ++ .../test/integration_tests/regions/tables.py | 20 +- .../integration_tests/tests/test_instances.py | 172 ++++++++++++++++-- 3 files changed, 191 insertions(+), 19 deletions(-) create mode 100644 openstack_dashboard/test/integration_tests/pages/admin/system/instancespage.py diff --git a/openstack_dashboard/test/integration_tests/pages/admin/system/instancespage.py b/openstack_dashboard/test/integration_tests/pages/admin/system/instancespage.py new file mode 100644 index 0000000000..94ed1d6591 --- /dev/null +++ b/openstack_dashboard/test/integration_tests/pages/admin/system/instancespage.py @@ -0,0 +1,18 @@ +# 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 instancespage + + +class InstancesPage(instancespage.InstancesPage): + pass diff --git a/openstack_dashboard/test/integration_tests/regions/tables.py b/openstack_dashboard/test/integration_tests/regions/tables.py index bc1d75cb91..879ac442ba 100644 --- a/openstack_dashboard/test/integration_tests/regions/tables.py +++ b/openstack_dashboard/test/integration_tests/regions/tables.py @@ -53,9 +53,11 @@ class TableRegion(baseregion.BaseRegion): _rows_locator = (by.By.CSS_SELECTOR, 'tbody > tr') _empty_table_locator = (by.By.CSS_SELECTOR, 'tbody > tr.empty') _search_field_locator = (by.By.CSS_SELECTOR, - 'div.table_search.client > input') + 'div.table_search input.form-control') _search_button_locator = (by.By.CSS_SELECTOR, - 'div.table_search.client > button') + 'div.table_search > button') + _search_option_locator = (by.By.CSS_SELECTOR, + 'div.table_search select.form-control') marker_name = 'marker' prev_marker_name = 'prev_marker' @@ -102,6 +104,10 @@ class TableRegion(baseregion.BaseRegion): self._set_search_field(value) self._click_search_btn() + def set_filter_value(self, value): + srch_option = self._get_element(*self._search_option_locator) + return self._select_dropdown_by_value(value, srch_option) + def get_row(self, column_name, text, exact_match=True): """Get row that contains specified text in specified column. @@ -127,6 +133,7 @@ class TableRegion(baseregion.BaseRegion): def _set_search_field(self, value): srch_field = self._get_element(*self._search_field_locator) + srch_field.clear() srch_field.send_keys(value) def _click_search_btn(self): @@ -177,14 +184,17 @@ class TableRegion(baseregion.BaseRegion): lnk = self._get_element(*self._prev_locator) lnk.click() - def assert_definition(self, expected_table_definition): - """Checks that actual image table is expected one. + def assert_definition(self, expected_table_definition, sorting=False): + """Checks that actual table is expected one. Items to compare: 'next' and 'prev' links, count of rows and names of - images in list + elements in list :param expected_table_definition: expected values (dictionary) + :param sorting: boolean arg specifying whether to sort actual names :return: """ names = [row.cells['name'].text for row in self.rows] + if sorting: + names.sort() actual_table = {'Next': self.is_next_link_available(), 'Prev': self.is_prev_link_available(), 'Count': len(self.rows), diff --git a/openstack_dashboard/test/integration_tests/tests/test_instances.py b/openstack_dashboard/test/integration_tests/tests/test_instances.py index 2f19c88c56..863e8fd4b7 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_instances.py +++ b/openstack_dashboard/test/integration_tests/tests/test_instances.py @@ -12,27 +12,171 @@ from openstack_dashboard.test.integration_tests import helpers from openstack_dashboard.test.integration_tests.regions import messages -INSTANCES_NAME = helpers.gen_random_resource_name('instance', - timestamp=False) +class TestInstances(helpers.TestCase): + INSTANCE_NAME = helpers.gen_random_resource_name('instance', + timestamp=False) -class TestInstances(helpers.AdminTestCase): - """This is a basic scenario to test: - * Create Instance and Delete Instance - """ + @property + def instances_page(self): + return self.home_pg.go_to_compute_instancespage() def test_create_delete_instance(self): + """tests the instance creation and deletion functionality: + * creates a new instance in Project > Compute > Instances page + * verifies the instance appears in the instances table as active + * deletes the newly created instance via proper page (depends on user) + * verifies the instance does not appear in the table after deletion + """ instances_page = self.home_pg.go_to_compute_instancespage() - instances_page.create_instance(INSTANCES_NAME) - self.assertTrue( - instances_page.find_message_and_dismiss(messages.SUCCESS)) - self.assertFalse( - instances_page.find_message_and_dismiss(messages.ERROR)) - self.assertTrue(instances_page.is_instance_active(INSTANCES_NAME)) - instances_page.delete_instance(INSTANCES_NAME) + instances_page.create_instance(self.INSTANCE_NAME) self.assertTrue( instances_page.find_message_and_dismiss(messages.SUCCESS)) self.assertFalse( instances_page.find_message_and_dismiss(messages.ERROR)) - self.assertTrue(instances_page.is_instance_deleted(INSTANCES_NAME)) + self.assertTrue(instances_page.is_instance_active(self.INSTANCE_NAME)) + + instances_page = self.instances_page + instances_page.delete_instance(self.INSTANCE_NAME) + self.assertTrue( + instances_page.find_message_and_dismiss(messages.SUCCESS)) + self.assertFalse( + instances_page.find_message_and_dismiss(messages.ERROR)) + self.assertTrue(instances_page.is_instance_deleted(self.INSTANCE_NAME)) + + def test_instances_pagination(self): + """This test checks instance pagination + Steps: + 1) Login to Horizon Dashboard as regular user + 2) Navigate to user settings page + 3) Change 'Items Per Page' value to 1 + 4) Go to Project > Compute > Instances page + 5) Create 2 instances + 6) Go to appropriate page (depends on user) + 7) Check that only 'Next' link is available, only one instance is + available (and it has correct name) on the first page + 8) Click 'Next' and check that on the second page only one instance is + available (and it has correct name), there is no 'Next' link on page + 9) Go to user settings page and restore 'Items Per Page' + 10) Delete created instances via proper page (depends on user) + """ + items_per_page = 1 + instance_count = 2 + instance_list = ["{0}-{1}".format(self.INSTANCE_NAME, item) + for item in range(1, instance_count + 1)] + first_page_definition = {'Next': True, 'Prev': False, + 'Count': items_per_page, + 'Names': [instance_list[1]]} + second_page_definition = {'Next': False, 'Prev': False, + 'Count': items_per_page, + 'Names': [instance_list[0]]} + + settings_page = self.home_pg.go_to_settings_usersettingspage() + settings_page.change_pagesize(items_per_page) + settings_page.find_message_and_dismiss(messages.SUCCESS) + + instances_page = self.home_pg.go_to_compute_instancespage() + instances_page.create_instance(self.INSTANCE_NAME, + instance_count=instance_count) + instances_page.find_message_and_dismiss(messages.SUCCESS) + self.assertTrue(instances_page.is_instance_active(instance_list[1])) + + instances_page = self.instances_page + instances_page.instances_table.assert_definition( + first_page_definition, sorting=True) + + instances_page.instances_table.turn_next_page() + instances_page.instances_table.assert_definition( + second_page_definition, sorting=True) + + instances_page = self.instances_page + instances_page.instances_table.assert_definition( + first_page_definition, sorting=True) + + settings_page = self.home_pg.go_to_settings_usersettingspage() + settings_page.change_pagesize() + settings_page.find_message_and_dismiss(messages.SUCCESS) + + instances_page = self.instances_page + for instance_name in instance_list: + instances_page.delete_instance(instance_name) + instances_page.find_message_and_dismiss(messages.SUCCESS) + self.assertTrue(instances_page.is_instance_deleted(instance_name)) + + def test_instances_pagination_and_filtration(self): + """This test checks instance pagination and filtration + Steps: + 1) Login to Horizon Dashboard as regular user + 2) Go to to user settings page + 3) Change 'Items Per Page' value to 1 + 4) Go to Project > Compute > Instances page + 5) Create 2 instances + 6) Go to appropriate page (depends on user) + 7) Check filter by Name of the first and the second instance in order + to have one instance in the list (and it should have correct name) and + no 'Next' link is available + 8) Check filter by common part of Name of in order to have one instance + in the list (and it should have correct name) and 'Next' link is + available on the first page and is not available on the second page + 9) Go to user settings page and restore 'Items Per Page' + 10) Delete created instances via proper page (depends on user) + + """ + items_per_page = 1 + instance_count = 2 + instance_list = ["{0}-{1}".format(self.INSTANCE_NAME, item) + for item in range(1, instance_count + 1)] + first_page_definition = {'Next': True, 'Prev': False, + 'Count': items_per_page, + 'Names': [instance_list[1]]} + second_page_definition = {'Next': False, 'Prev': False, + 'Count': items_per_page, + 'Names': [instance_list[0]]} + filter_first_page_definition = {'Next': False, 'Prev': False, + 'Count': items_per_page, + 'Names': [instance_list[1]]} + + settings_page = self.home_pg.go_to_settings_usersettingspage() + settings_page.change_pagesize(items_per_page) + settings_page.find_message_and_dismiss(messages.SUCCESS) + + instances_page = self.home_pg.go_to_compute_instancespage() + instances_page.create_instance(self.INSTANCE_NAME, + instance_count=instance_count) + instances_page.find_message_and_dismiss(messages.SUCCESS) + self.assertTrue(instances_page.is_instance_active(instance_list[1])) + + instances_page = self.instances_page + instances_page.instances_table.set_filter_value('name') + instances_page.instances_table.filter(instance_list[1]) + instances_page.instances_table.assert_definition( + filter_first_page_definition, sorting=True) + + instances_page.instances_table.filter(instance_list[0]) + instances_page.instances_table.assert_definition( + second_page_definition, sorting=True) + + instances_page.instances_table.filter(self.INSTANCE_NAME) + instances_page.instances_table.assert_definition( + first_page_definition, sorting=True) + instances_page.instances_table.filter('') + + settings_page = self.home_pg.go_to_settings_usersettingspage() + settings_page.change_pagesize() + settings_page.find_message_and_dismiss(messages.SUCCESS) + + instances_page = self.instances_page + for instance_name in instance_list: + instances_page.delete_instance(instance_name) + instances_page.find_message_and_dismiss(messages.SUCCESS) + self.assertTrue(instances_page.is_instance_deleted(instance_name)) + + +class TestAdminInstances(helpers.AdminTestCase, TestInstances): + INSTANCE_NAME = helpers.gen_random_resource_name('instance', + timestamp=False) + + @property + def instances_page(self): + return self.home_pg.go_to_system_instancespage()