Merge "Added tests for check RC files from API Access page"
This commit is contained in:
commit
a1e84a2282
@ -14,6 +14,7 @@
|
|||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
from selenium.common import exceptions as selenium_exceptions
|
from selenium.common import exceptions as selenium_exceptions
|
||||||
from selenium.webdriver.common import desired_capabilities as dc
|
from selenium.webdriver.common import desired_capabilities as dc
|
||||||
@ -59,10 +60,15 @@ class FirefoxBinary(firefox.firefox_binary.FirefoxBinary):
|
|||||||
|
|
||||||
class WebDriver(firefox.webdriver.WebDriver):
|
class WebDriver(firefox.webdriver.WebDriver):
|
||||||
"""Workarounds selenium firefox issues."""
|
"""Workarounds selenium firefox issues."""
|
||||||
|
TEMPDIR = tempfile.mkdtemp(dir="/tmp")
|
||||||
|
|
||||||
def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
|
def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
|
||||||
desired_capabilities=dc.DesiredCapabilities.FIREFOX,
|
desired_capabilities=dc.DesiredCapabilities.FIREFOX,
|
||||||
proxy=None):
|
proxy=None):
|
||||||
try:
|
try:
|
||||||
|
if firefox_profile is None:
|
||||||
|
firefox_profile = firefox.webdriver.FirefoxProfile()
|
||||||
|
self.setup_profile(firefox_profile)
|
||||||
super(WebDriver, self).__init__(
|
super(WebDriver, self).__init__(
|
||||||
firefox_profile, FirefoxBinary(), timeout,
|
firefox_profile, FirefoxBinary(), timeout,
|
||||||
desired_capabilities, proxy)
|
desired_capabilities, proxy)
|
||||||
@ -72,3 +78,11 @@ class WebDriver(firefox.webdriver.WebDriver):
|
|||||||
if self.profile.tempfolder is not None:
|
if self.profile.tempfolder is not None:
|
||||||
shutil.rmtree(self.profile.tempfolder)
|
shutil.rmtree(self.profile.tempfolder)
|
||||||
raise
|
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")
|
||||||
|
@ -36,6 +36,7 @@ class ProjectsPage(basepage.BaseNavigationPage):
|
|||||||
|
|
||||||
DEFAULT_ENABLED = True
|
DEFAULT_ENABLED = True
|
||||||
PROJECTS_TABLE_NAME_COLUMN = 'name'
|
PROJECTS_TABLE_NAME_COLUMN = 'name'
|
||||||
|
PROJECT_ID_TABLE_NAME_COLUMN = 'id'
|
||||||
|
|
||||||
def __init__(self, driver, conf):
|
def __init__(self, driver, conf):
|
||||||
super(ProjectsPage, self).__init__(driver, conf)
|
super(ProjectsPage, self).__init__(driver, conf)
|
||||||
@ -67,3 +68,7 @@ class ProjectsPage(basepage.BaseNavigationPage):
|
|||||||
|
|
||||||
def is_project_present(self, project_name):
|
def is_project_present(self, project_name):
|
||||||
return bool(self._get_row_with_project_name(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
|
||||||
|
@ -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
|
@ -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 "<tenant_name>-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 "<tenant_name>-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]))
|
Loading…
Reference in New Issue
Block a user