Skip to content

Commit

Permalink
Merge pull request #4464 from renzon/2971
Browse files Browse the repository at this point in the history
Improved ui org tests
  • Loading branch information
oshtaier committed Apr 14, 2017
2 parents 0939243 + 0c465f9 commit 0ae244e
Show file tree
Hide file tree
Showing 4 changed files with 493 additions and 500 deletions.
3 changes: 2 additions & 1 deletion robottelo/ui/locators/tab.py
Expand Up @@ -102,7 +102,8 @@
"//a[@data-toggle='tab' and contains(@href,'media')]"),
"context.tab_template": (
By.XPATH,
"//a[@data-toggle='tab' and contains(@href,'template')]"),
"//a[@data-toggle='tab' and contains(@href,'provisioning_templates')]"
),
"context.tab_ptable": (
By.XPATH,
"//a[@data-toggle='tab' and contains(@href,'ptables')]"),
Expand Down
206 changes: 160 additions & 46 deletions robottelo/ui/org.py
Expand Up @@ -9,6 +9,110 @@

class Org(Base):
"""Provides the CRUD functionality for Organization."""
_entity_filter_and_locator_dct = {
'users': {
'filter_key': FILTER['org_user'],
'tab_locator': tab_locators['context.tab_users']
},
'capsules': {
'filter_key': FILTER['org_capsules'],
'tab_locator': tab_locators['context.tab_capsules']
},
'subnets': {
'filter_key': FILTER['org_subnet'],
'tab_locator': tab_locators['context.tab_subnets']
},
'resources': {
'filter_key': FILTER['org_resource'],
'tab_locator': tab_locators['context.tab_resources']
},
'medias': {
'filter_key': FILTER['org_media'],
'tab_locator': tab_locators['context.tab_media']
},
'templates': {
'filter_key': FILTER['org_template'],
'tab_locator': tab_locators['context.tab_template']
},
'ptables': {
'filter_key': FILTER['org_ptable'],
'tab_locator': tab_locators['context.tab_ptable']
},
'domains': {
'filter_key': FILTER['org_domain'],
'tab_locator': tab_locators['context.tab_domains']
},
'envs': {
'filter_key': FILTER['org_envs'],
'tab_locator': tab_locators['context.tab_env']
},
'hostgroups': {
'filter_key': FILTER['org_hostgroup'],
'tab_locator': tab_locators['context.tab_hostgrps']
},
'locations': {
'filter_key': FILTER['org_location'],
'tab_locator': tab_locators['context.tab_locations']
},
}

def add_entity(self, org_name, entity_type, entity_name):
"""Helper to add an entity to an existing organization.
Return ui entity on list so it can be used on tests. If it is not None
entity was added
:param org_name: name of Organization
:param entity_type: Entity's name param for self.update
:param entity_name: Entity's name
:return entity: ui element
"""
kwargs = {entity_type: [entity_name]}
self.update(org_name, select=True, **kwargs)
self.search_and_click(org_name)
tab_locator = self._entity_filter_and_locator_dct[entity_type][
'tab_locator']
self.click(tab_locator)
return self.wait_until_element(
common_locators['entity_deselect'] % entity_name)

def remove_entity(self, org_name, entity_type, entity_name):
"""Helper to remove an entity from an existing organization.
Return ui entity on list so it can be used on tests. If it is not None
entity was removed
:param org_name: name of Organization
:param entity_type: Entity's name param for self.update
:param entity_name: Entity's name
:return entity: ui element
"""
kwargs = {entity_type: [entity_name]}
self.update(org_name, **kwargs)
self.search_and_click(org_name)
tab_locator = self._entity_filter_and_locator_dct[entity_type][
'tab_locator']
self.click(tab_locator)
return self.wait_until_element(
common_locators['entity_select'] % entity_name)

def create_with_entity(self, org_name, entity_type, entity_name):
"""Helper function to assert Organization creation with related
entities
:param org_name: Organization's name to be created
:param entity_type: one of following entities: users
:param entity_name: Entity's name
:return entity: element on screen if present. So assertIsNotNone can
be used to test entity successful attachment
"""
self.navigate_to_entity()
kwargs = {entity_type: [entity_name]}
self.create(org_name, **kwargs)
self.search_and_click(org_name)
tab_locator = self._entity_filter_and_locator_dct[entity_type][
'tab_locator']
self.click(tab_locator)
return self.wait_until_element(
common_locators['entity_deselect'] % entity_name)

def navigate_to_entity(self):
"""Navigate to org entity page"""
Expand All @@ -27,63 +131,73 @@ def _configure_org(self, users=None, capsules=None, subnets=None,
new_envs=None, new_hostgroups=None, new_locations=None,
select=None):
"""Configures different entities of selected organization."""
loc = tab_locators

if users or new_users:
self.configure_entity(users, FILTER['org_user'],
tab_locator=loc['context.tab_users'],
new_entity_list=new_users,
entity_select=select)
self.configure_entity(
users,
new_entity_list=new_users,
entity_select=select,
**self._entity_filter_and_locator_dct['users']
)
if capsules or new_capsules:
self.configure_entity(capsules, FILTER['org_capsules'],
tab_locator=loc['context.tab_capsules'],
new_entity_list=new_capsules,
entity_select=select)
self.configure_entity(
capsules,
new_entity_list=new_capsules,
entity_select=select,
**self._entity_filter_and_locator_dct['capsules'])
if subnets or new_subnets:
self.configure_entity(subnets, FILTER['org_subnet'],
tab_locator=loc['context.tab_subnets'],
new_entity_list=new_subnets,
entity_select=select)
self.configure_entity(
subnets,
new_entity_list=new_subnets,
entity_select=select,
**self._entity_filter_and_locator_dct['subnets'])
if resources or new_resources:
self.configure_entity(resources, FILTER['org_resource'],
tab_locator=loc['context.tab_resources'],
new_entity_list=new_resources,
entity_select=select)
self.configure_entity(
resources,
new_entity_list=new_resources,
entity_select=select,
**self._entity_filter_and_locator_dct['resources'])
if medias or new_medias:
self.configure_entity(medias, FILTER['org_media'],
tab_locator=loc['context.tab_media'],
new_entity_list=new_medias,
entity_select=select)
self.configure_entity(
medias,
new_entity_list=new_medias,
entity_select=select,
**self._entity_filter_and_locator_dct['medias'])
if templates or new_templates:
self.configure_entity(templates, FILTER['org_template'],
tab_locator=loc['context.tab_template'],
new_entity_list=new_templates,
entity_select=select)
self.configure_entity(
templates,
new_entity_list=new_templates,
entity_select=select,
**self._entity_filter_and_locator_dct['templates'])
if ptables or new_ptables:
self.configure_entity(ptables, FILTER['org_ptable'],
tab_locator=loc['context.tab_ptable'],
new_entity_list=new_ptables,
entity_select=select)
self.configure_entity(
ptables,
new_entity_list=new_ptables,
entity_select=select,
**self._entity_filter_and_locator_dct['ptables'])
if domains or new_domains:
self.configure_entity(domains, FILTER['org_domain'],
tab_locator=loc['context.tab_domains'],
new_entity_list=new_domains,
entity_select=select)
self.configure_entity(
domains,
new_entity_list=new_domains,
entity_select=select,
**self._entity_filter_and_locator_dct['domains'])
if envs or new_envs:
self.configure_entity(envs, FILTER['org_envs'],
tab_locator=loc['context.tab_env'],
new_entity_list=new_envs,
entity_select=select)
self.configure_entity(
envs,
new_entity_list=new_envs,
entity_select=select,
**self._entity_filter_and_locator_dct['envs'])
if hostgroups or new_hostgroups:
self.configure_entity(hostgroups, FILTER['org_hostgroup'],
tab_locator=loc['context.tab_hostgrps'],
new_entity_list=new_hostgroups,
entity_select=select)
self.configure_entity(
hostgroups,
new_entity_list=new_hostgroups,
entity_select=select,
**self._entity_filter_and_locator_dct['hostgroups'])
if locations or new_locations:
self.configure_entity(hostgroups, FILTER['org_location'],
tab_locator=loc['context.tab_locations'],
new_entity_list=new_locations,
entity_select=select)
self.configure_entity(
locations,
new_entity_list=new_locations,
entity_select=select,
**self._entity_filter_and_locator_dct['locations'])

def create(self, org_name=None, label=None, desc=None, users=None,
capsules=None, subnets=None, resources=None, medias=None,
Expand Down
23 changes: 23 additions & 0 deletions robottelo/ui/session.py
@@ -1,9 +1,13 @@
# -*- encoding: utf-8 -*-
from fauxfactory import gen_string

from robottelo.config import settings
from robottelo.ui.factory import make_org
from robottelo.ui.login import Login
from robottelo.ui.navigator import Navigator

_org_cache = {}


class Session(object):
"""A session context manager that manages login and logout"""
Expand Down Expand Up @@ -46,3 +50,22 @@ def logout(self):
def close(self):
"""Exits session and also closes the browser (used in shell)"""
self.browser.close()

def get_org_name(self):
"""
Make a Organization and cache its name to be returned through session,
avoiding overhead of its recreation on each test.
Organization Must be at same state (not mutate) at the end of the test
Create your own organization if mutation is needed. Otherwise other
tests can break with your tests side effects
:return: str: Organization name
"""
if 'org_name' in _org_cache:
return _org_cache['org_name']
org_name = gen_string('alpha')
make_org(self, org_name=org_name)
_org_cache['org_name'] = org_name
return org_name

0 comments on commit 0ae244e

Please sign in to comment.