Add test_sahara_create_delete_job_binary test method

Adding test method that checks creating/removal of job binary under
Project/Data Processing/Job Binaries.
The core testing function can be easily extended with other job binary
templates; the initial versions allows to test for jobs stored on the
Internal DB.

As part of this test several items have been created
* new pageobject class JobbinariesPage
* new form field FileInputFormFieldRegion

Co-Authored-By: Luigi Toscano <ltoscano@redhat.com>
Partially implements blueprint: selenium-integration-testing

Change-Id: I48c992bbfd0b2428be220a4462d5ef76aca5fa45
This commit is contained in:
Tomas Novacik 2015-03-02 19:36:10 +01:00 committed by Luigi Toscano
parent 7b16bbf920
commit 8386221adf
3 changed files with 222 additions and 1 deletions

View File

@ -0,0 +1,109 @@
# 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.
import copy
from selenium.webdriver.common import by
from openstack_dashboard.test.integration_tests.pages import basepage
from openstack_dashboard.test.integration_tests.regions import forms
from openstack_dashboard.test.integration_tests.regions import tables
class JobbinariesPage(basepage.BaseNavigationPage):
_job_binaries_table_locator = (by.By.CSS_SELECTOR, 'table#job_binaries')
_create_job_binary_form_locator = (by.By.CSS_SELECTOR, 'div.modal-dialog')
_confirm_job_binary_deletion_form =\
(by.By.CSS_SELECTOR, 'div.modal-dialog')
JOB_BINARIES_TABLE_ACTIONS = ("create_job_binary", "delete_job_binaries")
JOB_BINARIES_ROW_ACTIONS = {
tables.ComplexActionRowRegion.PRIMARY_ACTION: "delete_job_binary",
tables.ComplexActionRowRegion.SECONDARY_ACTIONS:
("download_job_binary",)
}
BINARY_NAME = "name"
BINARY_STORAGE_TYPE = "storage_type"
BINARY_URL = "url"
INTERNAL_BINARY = "internal_binary"
BINARY_PATH = "upload_file"
SCRIPT_NAME = "script_name"
SCRIPT_TEXT = "script_text"
USERNAME = "username"
PASSWORD = "password"
DESCRIPTION = "description"
CREATE_BINARY_FORM_FIELDS = (
BINARY_NAME,
BINARY_STORAGE_TYPE,
BINARY_URL,
INTERNAL_BINARY,
BINARY_PATH,
SCRIPT_NAME,
SCRIPT_TEXT,
USERNAME,
PASSWORD,
DESCRIPTION
)
# index of name column in binary jobs table
JOB_BINARIES_TABLE_NAME_COLUMN = 0
# fields that are set via text setter
_TEXT_FIELDS = (BINARY_NAME, BINARY_STORAGE_TYPE, INTERNAL_BINARY)
def __init__(self, driver, conf):
super(JobbinariesPage, self).__init__(driver, conf)
self._page_title = "Data Processing"
def _get_row_with_job_binary_name(self, name):
return self.job_binaries_table.get_row(
self.JOB_BINARIES_TABLE_NAME_COLUMN, name)
@property
def job_binaries_table(self):
src_elem = self._get_element(*self._job_binaries_table_locator)
return tables.ComplexActionTableRegion(self.driver,
self.conf, src_elem,
self.JOB_BINARIES_TABLE_ACTIONS,
self.JOB_BINARIES_ROW_ACTIONS
)
@property
def create_job_binary_form(self):
src_elem = self._get_element(*self._create_job_binary_form_locator)
return forms.FormRegion(self.driver, self.conf, src_elem,
self.CREATE_BINARY_FORM_FIELDS)
@property
def confirm_delete_job_binaries_form(self):
src_elem = self._get_element(*self._confirm_job_binary_deletion_form)
return forms.BaseFormRegion(self.driver, self.conf, src_elem)
def delete_job_binary(self, name):
row = self._get_row_with_job_binary_name(name)
row.mark()
self.job_binaries_table.delete_job_binaries.click()
self.confirm_delete_job_binaries_form.submit.click()
def create_job_binary(self, name, storage_type, url, internal_binary,
upload_file, script_name, script_text, username,
password, description):
self.job_binaries_table.create_job_binary.click()
job_data = copy.copy(locals())
del job_data["self"]
self.create_job_binary_form.set_field_values(job_data)
self.create_job_binary_form.submit.click()
def is_job_binary_present(self, name):
return bool(self._get_row_with_job_binary_name(name))

View File

@ -115,7 +115,24 @@ class BaseTextFormFieldRegion(BaseFormFieldRegion):
class TextInputFormFieldRegion(BaseTextFormFieldRegion):
"""Text input box."""
_element_locator = (by.By.CSS_SELECTOR, 'div > input[type=text]')
_element_locator = (by.By.CSS_SELECTOR, 'div > input[type=text],'
'div > input[type=None]')
class FileInputFormFieldRegion(BaseFormFieldRegion):
"""Text input box."""
_element_locator = (by.By.CSS_SELECTOR, 'div > input[type=file]')
@property
def path(self):
return self.element.text
@path.setter
def path(self, path):
# clear does not work on this kind of element
# because it is not user editable
self.element.send_keys(path)
class PasswordInputFormFieldRegion(BaseTextFormFieldRegion):
@ -243,6 +260,29 @@ class FormRegion(BaseFormRegion):
self._turn_on_implicit_wait()
return form_fields
def set_field_values(self, data):
"""Set fields values
data - {field_name: field_value, field_name: field_value ...}
"""
for field_name in data:
field = getattr(self, field_name, None)
# Field form does not exist
if field is None:
raise AttributeError("Unknown form field name.")
value = data[field_name]
# if None - default value is left in field
if value is not None:
# all text fields
if hasattr(field, "text"):
field.text = value
# file upload field
elif hasattr(field, "path"):
field.path = value
# integers fields
elif hasattr(field, "value"):
field.value = value
# properties
@property
def header(self):

View File

@ -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 import helpers
from openstack_dashboard.test.integration_tests.pages.project.data_processing\
import jobbinariespage
from openstack_dashboard.test.integration_tests.tests import decorators
JOB_BINARY_INTERNAL = {
# Size of binary name is limited to 50 characters
jobbinariespage.JobbinariesPage.BINARY_NAME:
helpers.gen_random_resource_name(resource='jobbinary',
timestamp=False)[0:50],
jobbinariespage.JobbinariesPage.BINARY_STORAGE_TYPE:
"Internal database",
jobbinariespage.JobbinariesPage.BINARY_URL: None,
jobbinariespage.JobbinariesPage.INTERNAL_BINARY:
"*Create a script",
jobbinariespage.JobbinariesPage.BINARY_PATH: None,
jobbinariespage.JobbinariesPage.SCRIPT_NAME:
helpers.gen_random_resource_name(resource='scriptname',
timestamp=False),
jobbinariespage.JobbinariesPage.SCRIPT_TEXT: "test_script_text",
jobbinariespage.JobbinariesPage.USERNAME: None,
jobbinariespage.JobbinariesPage.PASSWORD: None,
jobbinariespage.JobbinariesPage.DESCRIPTION: "test description"
}
@decorators.services_required("sahara")
class TestSaharaJobBinary(helpers.TestCase):
def _sahara_create_delete_job_binary(self, job_binary_template):
job_name = \
job_binary_template[jobbinariespage.JobbinariesPage.BINARY_NAME]
# create job binary
job_binary_pg = self.home_pg.go_to_dataprocessing_jobbinariespage()
self.assertFalse(job_binary_pg.is_job_binary_present(job_name),
"Job binary was present in the binaries table"
" before its creation.")
job_binary_pg.create_job_binary(**job_binary_template)
# verify that job is created without problems
self.assertFalse(job_binary_pg.is_error_message_present(),
"Error message occurred during binary job creation.")
self.assertTrue(job_binary_pg.is_job_binary_present(job_name),
"Job binary is not in the binaries job table after"
" its creation.")
# delete binary job
job_binary_pg.delete_job_binary(job_name)
# verify that job was successfully deleted
self.assertFalse(job_binary_pg.is_error_message_present(),
"Error message occurred during binary job deletion.")
self.assertFalse(job_binary_pg.is_job_binary_present(job_name),
"Job binary was not removed from binaries job table.")
def test_sahara_create_delete_job_binary_internaldb(self):
"""Test the creation of a Job Binary in the Internal DB."""
self._sahara_create_delete_job_binary(JOB_BINARY_INTERNAL)