From 84032cbede6d6545bafc16af2ec6f524d7045773 Mon Sep 17 00:00:00 2001 From: MikhialLaptev Date: Fri, 15 Jan 2016 05:32:55 -0500 Subject: [PATCH] Added tests for check RC files from API Access page test_download_rc_v2_file() test_download_rc_v3_file() Tests check that RC files are downloaded successfully and some attributes of file's contents are correct. Implements blueprint: horizon-integration-tests-coverage Change-Id: Icef46863a6fb95600f7c98d5926cfb5b0dfa3d92 --- horizon/test/firefox_binary.py | 14 ++++ .../pages/identity/projectspage.py | 5 ++ .../access_and_security/apiaccesspage.py | 72 ++++++++++++++++++ .../tests/test_credentials.py | 74 +++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 openstack_dashboard/test/integration_tests/pages/project/compute/access_and_security/apiaccesspage.py create mode 100644 openstack_dashboard/test/integration_tests/tests/test_credentials.py diff --git a/horizon/test/firefox_binary.py b/horizon/test/firefox_binary.py index 2597789d31..ba67c7d10e 100644 --- a/horizon/test/firefox_binary.py +++ b/horizon/test/firefox_binary.py @@ -14,6 +14,7 @@ import platform import shutil import subprocess +import tempfile from selenium.common import exceptions as selenium_exceptions from selenium.webdriver.common import desired_capabilities as dc @@ -59,10 +60,15 @@ class FirefoxBinary(firefox.firefox_binary.FirefoxBinary): class WebDriver(firefox.webdriver.WebDriver): """Workarounds selenium firefox issues.""" + TEMPDIR = tempfile.mkdtemp(dir="/tmp") + def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30, desired_capabilities=dc.DesiredCapabilities.FIREFOX, proxy=None): try: + if firefox_profile is None: + firefox_profile = firefox.webdriver.FirefoxProfile() + self.setup_profile(firefox_profile) super(WebDriver, self).__init__( firefox_profile, FirefoxBinary(), timeout, desired_capabilities, proxy) @@ -72,3 +78,11 @@ class WebDriver(firefox.webdriver.WebDriver): if self.profile.tempfolder is not None: shutil.rmtree(self.profile.tempfolder) raise + + def setup_profile(self, fp): + fp.set_preference("browser.download.folderList", 2) + fp.set_preference("browser.download.manager.showWhenStarting", + False) + fp.set_preference("browser.download.dir", self.TEMPDIR) + fp.set_preference("browser.helperApps.neverAsk.saveToDisk", + "application/binary,text/plain") diff --git a/openstack_dashboard/test/integration_tests/pages/identity/projectspage.py b/openstack_dashboard/test/integration_tests/pages/identity/projectspage.py index fff32bf9ea..b2821020f8 100644 --- a/openstack_dashboard/test/integration_tests/pages/identity/projectspage.py +++ b/openstack_dashboard/test/integration_tests/pages/identity/projectspage.py @@ -36,6 +36,7 @@ class ProjectsPage(basepage.BaseNavigationPage): DEFAULT_ENABLED = True PROJECTS_TABLE_NAME_COLUMN = 'name' + PROJECT_ID_TABLE_NAME_COLUMN = 'id' def __init__(self, driver, conf): super(ProjectsPage, self).__init__(driver, conf) @@ -67,3 +68,7 @@ class ProjectsPage(basepage.BaseNavigationPage): def is_project_present(self, project_name): return bool(self._get_row_with_project_name(project_name)) + + def get_project_id_from_row(self, name): + row = self._get_row_with_project_name(name) + return row.cells[self.PROJECT_ID_TABLE_NAME_COLUMN].text diff --git a/openstack_dashboard/test/integration_tests/pages/project/compute/access_and_security/apiaccesspage.py b/openstack_dashboard/test/integration_tests/pages/project/compute/access_and_security/apiaccesspage.py new file mode 100644 index 0000000000..72f2031eae --- /dev/null +++ b/openstack_dashboard/test/integration_tests/pages/project/compute/access_and_security/apiaccesspage.py @@ -0,0 +1,72 @@ +# 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 import basepage +from openstack_dashboard.test.integration_tests.regions import tables + +from os import listdir +from os.path import isfile +from os.path import join +from re import search + + +class ApiAccessTable(tables.TableRegion): + name = "endpoints" + + @tables.bind_table_action('download_openrc_v2') + def download_openstack_rc_v2(self, download_button): + download_button.click() + + @tables.bind_table_action('download_openrc') + def download_openstack_rc_v3(self, download_button): + download_button.click() + + +class ApiaccessPage(basepage.BaseNavigationPage): + + def __init__(self, driver, conf): + super(ApiaccessPage, self).__init__(driver, conf) + self._page_title = "Access & Security" + + @property + def apiaccess_table(self): + return ApiAccessTable(self.driver, self.conf) + + def download_openstack_rc_file(self, version, directory, template): + if version == 2: + self.apiaccess_table.download_openstack_rc_v2() + elif version == 3: + self.apiaccess_table.download_openstack_rc_v3() + + def list_of_files(self, directory, template): + return [f for f in listdir(directory) if isfile(join(directory, f)) + and f.endswith(template)] + + def get_credentials_from_file(self, version, directory, template): + self._wait_until( + lambda _: len(self.list_of_files(directory, template)) > 0) + file_name = self.list_of_files(directory, template)[0] + with open(join(directory, file_name)) as cred_file: + content = cred_file.read() + username_re = r'export OS_USERNAME="([^"]+)"' + if version == 2: + tenant_name_re = r'export OS_TENANT_NAME="([^"]+)"' + tenant_id_re = r'export OS_TENANT_ID=(.+)' + elif version == 3: + tenant_name_re = r'export OS_PROJECT_NAME="([^"]+)"' + tenant_id_re = r'export OS_PROJECT_ID=(.+)' + username = search(username_re, content).group(1) + tenant_name = search(tenant_name_re, content).group(1) + tenant_id = search(tenant_id_re, content).group(1) + cred_dict = {'OS_USERNAME': username, + 'OS_TENANT_NAME': tenant_name, + 'OS_TENANT_ID': tenant_id} + return cred_dict diff --git a/openstack_dashboard/test/integration_tests/tests/test_credentials.py b/openstack_dashboard/test/integration_tests/tests/test_credentials.py new file mode 100644 index 0000000000..45c7f9956f --- /dev/null +++ b/openstack_dashboard/test/integration_tests/tests/test_credentials.py @@ -0,0 +1,74 @@ +# 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 horizon.test import firefox_binary +from openstack_dashboard.test.integration_tests import helpers + +from os import listdir +from os.path import join +from os import remove + + +class TestDownloadRCFile(helpers.AdminTestCase): + + _directory = firefox_binary.WebDriver.TEMPDIR + _openrc_template = "-openrc.sh" + + def setUp(self): + super(TestDownloadRCFile, self).setUp() + username = self.TEST_USER_NAME + tenant_name = self.HOME_PROJECT + projects_page = self.home_pg.go_to_identity_projectspage() + tenant_id = projects_page.get_project_id_from_row(tenant_name) + self.actual_dict = {'OS_USERNAME': username, + 'OS_TENANT_NAME': tenant_name, + 'OS_TENANT_ID': tenant_id} + + def test_download_rc_v2_file(self): + """This is a basic scenario test: + Steps: + 1) Login to Horizon Dashboard as admin user + 2) Navigate to Project > Compute > Access & Security > API Access tab + 3) Click on "Download OpenStack RC File v2.0" button + 4) File named by template "-openrc.sh" must be downloaded + 5) Check that username, tenant name and tenant id correspond to current + username, tenant name and tenant id + """ + api_access_page = self.home_pg.\ + go_to_compute_accessandsecurity_apiaccesspage() + api_access_page.download_openstack_rc_file( + 2, self._directory, self._openrc_template) + cred_dict = api_access_page.get_credentials_from_file( + 2, self._directory, self._openrc_template) + self.assertEqual(cred_dict, self.actual_dict) + + def test_download_rc_v3_file(self): + """This is a basic scenario test: + Steps: + 1) Login to Horizon Dashboard as admin user + 2) Navigate to Project > Compute > Access & Security > API Access tab + 3) Click on "Download OpenStack RC File v3" button + 4) File named by template "-openrc.sh" must be downloaded + 5) Check that username, project name and project id correspond to + current username, tenant name and tenant id + """ + api_access_page = self.home_pg.\ + go_to_compute_accessandsecurity_apiaccesspage() + api_access_page.download_openstack_rc_file( + 3, self._directory, self._openrc_template) + cred_dict = api_access_page.get_credentials_from_file( + 3, self._directory, self._openrc_template) + self.assertEqual(cred_dict, self.actual_dict) + + def tearDown(self): + super(TestDownloadRCFile, self).tearDown() + remove(join(self._directory, listdir(self._directory)[0]))