Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
[1LP][RFR] CB: refactor infra objects (#8223)
Browse files Browse the repository at this point in the history
* move objects to common page

* refactor infra object setup fixture
  • Loading branch information
digitronik authored and mshriver committed Dec 6, 2018
1 parent b3753dc commit 7dc1ba0
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 100 deletions.
6 changes: 3 additions & 3 deletions cfme/automate/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,18 @@ class ButtonGroupCollection(BaseCollection):
CLOUD_SUBNET = "Cloud Subnet"
CLOUD_TENANT = "Cloud Tenant"
CLOUD_VOLUME = "Cloud Volume"
CLUSTER = "Cluster / Deployment Role"
CLUSTERS = "Cluster / Deployment Role"
CONTAINER_IMAGES = "Container Image"
CONTAINER_NODES = "Container Node"
CONTAINER_PODS = "Container Pod"
CONTAINER_PROJECTS = "Container Project"
CONTAINER_TEMPLATES = "Container Template"
CONTAINER_VOLUMES = "Container Volume"
DATASTORE = "Datastore"
DATASTORES = "Datastore"
GROUP = "Group"
USER = "User"
GENERIC = "Generic Object"
HOST = "Host / Node"
HOSTS = "Host / Node"
LOAD_BALANCER = "Load Balancer"
ROUTER = "Network Router"
ORCHESTRATION_STACK = "Orchestration Stack"
Expand Down
47 changes: 47 additions & 0 deletions cfme/tests/automate/custom_button/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,53 @@
from widgetastic_patternfly import Button


OBJ_TYPE_59 = [
"CLOUD_TENANT",
"CLOUD_VOLUME",
"CLUSTERS",
"CONTAINER_NODES",
"CONTAINER_PROJECTS",
"DATASTORES",
"GENERIC",
"HOSTS",
"PROVIDER",
"SERVICE",
"TEMPLATE_IMAGE",
"VM_INSTANCE",
]

OBJ_TYPE = [
"AZONE",
"CLOUD_NETWORK",
"CLOUD_OBJECT_STORE_CONTAINER",
"CLOUD_SUBNET",
"CLOUD_TENANT",
"CLOUD_VOLUME",
"CLUSTERS",
"CONTAINER_IMAGES",
"CONTAINER_NODES",
"CONTAINER_PODS",
"CONTAINER_PROJECTS",
"CONTAINER_TEMPLATES",
"CONTAINER_VOLUMES",
"DATASTORES",
"GROUP",
"USER",
"GENERIC",
"HOSTS",
"LOAD_BALANCER",
"ROUTER",
"ORCHESTRATION_STACK",
"PROVIDER",
"SECURITY_GROUP",
"SERVICE",
"SWITCH",
"TENANT",
"TEMPLATE_IMAGE",
"VM_INSTANCE",
]


def check_log_requests_count(appliance, parse_str=None):
""" Method for checking number of requests count in automation log
Expand Down
74 changes: 15 additions & 59 deletions cfme/tests/automate/custom_button/test_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,12 @@
import pytest

from cfme import test_requirements
from cfme.tests.automate.custom_button import OBJ_TYPE, OBJ_TYPE_59
from cfme.utils.appliance.implementations.ui import navigate_to
from cfme.utils.blockers import BZ
from cfme.utils.update import update

pytestmark = [
test_requirements.automate,
pytest.mark.usefixtures('uses_infra_providers'),
]


OBJ_TYPE_59 = [
"CLOUD_TENANT",
"CLOUD_VOLUME",
"CLUSTER",
"CONTAINER_NODES",
"CONTAINER_PROJECTS",
"DATASTORE",
"GENERIC",
"HOST",
"PROVIDER",
"SERVICE",
"TEMPLATE_IMAGE",
"VM_INSTANCE",
]

OBJ_TYPE = [
"AZONE",
"CLOUD_NETWORK",
"CLOUD_OBJECT_STORE_CONTAINER",
"CLOUD_SUBNET",
"CLOUD_TENANT",
"CLOUD_VOLUME",
"CLUSTER",
"CONTAINER_IMAGES",
"CONTAINER_NODES",
"CONTAINER_PODS",
"CONTAINER_PROJECTS",
"CONTAINER_TEMPLATES",
"CONTAINER_VOLUMES",
"DATASTORE",
"GROUP",
"USER",
"GENERIC",
"HOST",
"LOAD_BALANCER",
"ROUTER",
"ORCHESTRATION_STACK",
"PROVIDER",
"SECURITY_GROUP",
"SERVICE",
"SWITCH",
"TENANT",
"TEMPLATE_IMAGE",
"VM_INSTANCE",
]
pytestmark = [test_requirements.automate, pytest.mark.usefixtures("uses_infra_providers")]


@pytest.fixture(scope="module")
Expand All @@ -67,9 +18,10 @@ def _buttongroup(object_type):
button_gp = collection.create(
text=fauxfactory.gen_alphanumeric(),
hover=fauxfactory.gen_alphanumeric(),
type=getattr(collection, object_type)
type=getattr(collection, object_type),
)
return button_gp

return _buttongroup


Expand Down Expand Up @@ -112,7 +64,7 @@ def test_button_group_crud(request, appliance, obj_type):
# 2) Verify it exists
assert buttongroup.exists
# 3) Now the new part, go to the details page
view = navigate_to(buttongroup, 'Details')
view = navigate_to(buttongroup, "Details")
# 4) and verify that the values in there indeed correspond to the values specified
assert view.text.text == buttongroup.text
assert view.hover.text == buttongroup.hover
Expand All @@ -124,7 +76,7 @@ def test_button_group_crud(request, appliance, obj_type):
# 7) Assert it still exists
assert buttongroup.exists
# 8) Go to the details page again
view = navigate_to(buttongroup, 'Details')
view = navigate_to(buttongroup, "Details")
# 9) Verify it indeed equals to what it was set to before
assert view.hover.text == updated_hover
# 10) Delete it - first cancel and then real
Expand Down Expand Up @@ -167,17 +119,20 @@ def test_button_crud(appliance, dialog, request, buttongroup, obj_type):
button = button_gp.buttons.create(
text=fauxfactory.gen_alphanumeric(),
hover=fauxfactory.gen_alphanumeric(),
dialog=dialog, system="Request", request="InspectMe")
dialog=dialog,
system="Request",
request="InspectMe",
)
request.addfinalizer(button.delete_if_exists)
assert button.exists
view = navigate_to(button, 'Details')
view = navigate_to(button, "Details")
assert view.text.text == button.text
assert view.hover.text == button.hover
edited_hover = "edited {}".format(fauxfactory.gen_alphanumeric())
with update(button):
button.hover = edited_hover
assert button.exists
view = navigate_to(button, 'Details')
view = navigate_to(button, "Details")
assert view.hover.text == edited_hover
button.delete(cancel=True)
assert button.exists
Expand All @@ -203,11 +158,12 @@ def test_button_avp_displayed(appliance, dialog, request):
buttongroup = appliance.collections.button_groups.create(
text=fauxfactory.gen_alphanumeric(),
hover="btn_desc_{}".format(fauxfactory.gen_alphanumeric()),
type=appliance.collections.button_groups.VM_INSTANCE)
type=appliance.collections.button_groups.VM_INSTANCE,
)
request.addfinalizer(buttongroup.delete_if_exists)
buttons_collection = appliance.collections.buttons
buttons_collection.group = buttongroup
view = navigate_to(buttons_collection, 'Add')
view = navigate_to(buttons_collection, "Add")
for n in range(1, 6):
assert view.advanced.attribute(n).key.is_displayed
assert view.advanced.attribute(n).value.is_displayed
Expand Down
17 changes: 1 addition & 16 deletions cfme/tests/automate/custom_button/test_cloud_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from cfme.cloud.provider.openstack import OpenStackProvider
from cfme.markers.env_markers.provider import ONE_PER_TYPE
from cfme.tests.automate.custom_button import log_request_check, TextInputDialogView
from cfme.tests.automate.custom_button import log_request_check, OBJ_TYPE_59, TextInputDialogView
from cfme.utils.appliance.implementations.ui import navigate_to
from cfme.utils.log import logger
from cfme.utils.wait import TimedOutError, wait_for
Expand Down Expand Up @@ -37,21 +37,6 @@

SUBMIT = ["Submit all", "One by one"]

OBJ_TYPE_59 = [
"CLOUD_TENANT",
"CLOUD_VOLUME",
"CLUSTER",
"CONTAINER_NODE",
"CONTAINER_PROJECT",
"DATASTORE",
"GENERIC",
"HOST",
"PROVIDER",
"SERVICE",
"TEMPLATE_IMAGE",
"VM_INSTANCE",
]


@pytest.fixture(
params=CLOUD_OBJECTS, ids=[obj.capitalize() for obj in CLOUD_OBJECTS], scope="module"
Expand Down
4 changes: 1 addition & 3 deletions cfme/tests/automate/custom_button/test_container_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from cfme.containers.provider import ContainersProvider
from cfme.markers.env_markers.provider import ONE_PER_TYPE
from cfme.tests.automate.custom_button import log_request_check, TextInputDialogView
from cfme.tests.automate.custom_button import log_request_check, OBJ_TYPE_59, TextInputDialogView
from cfme.utils.appliance.implementations.ui import navigate_to
from cfme.utils.blockers import BZ
from cfme.utils.wait import TimedOutError, wait_for
Expand All @@ -28,8 +28,6 @@
"CONTAINER_VOLUMES",
]

OBJ_TYPE_59 = ["PROVIDER", "CONTAINER_NODES", "CONTAINER_PROJECTS"]

DISPLAY_NAV = {
"Single entity": ["Details"],
"List": ["All"],
Expand Down
33 changes: 14 additions & 19 deletions cfme/tests/automate/custom_button/test_infra_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from cfme.tests.automate.custom_button import log_request_check, TextInputDialogView
from cfme.utils.appliance.implementations.ui import navigate_to
from cfme.utils.blockers import BZ
from cfme.utils.log import logger
from cfme.utils.wait import TimedOutError, wait_for


Expand All @@ -18,7 +17,7 @@
pytest.mark.provider([VMwareProvider], selector=ONE_PER_TYPE),
]

INFRA_OBJECTS = ["PROVIDER", "HOST", "VM_INSTANCE", "TEMPLATE_IMAGE", "DATASTORE", "CLUSTER"]
INFRA_OBJECTS = ["PROVIDER", "HOSTS", "VM_INSTANCE", "TEMPLATE_IMAGE", "DATASTORES", "CLUSTERS"]

DISPLAY_NAV = {
"Single entity": ["Details"],
Expand Down Expand Up @@ -48,20 +47,18 @@ def setup_obj(button_group, provider):
""" Setup object for specific custom button object type."""
obj_type = button_group[1]

if obj_type == "PROVIDER":
obj = provider
elif obj_type == "HOST":
obj = provider.appliance.collections.hosts.all()[0]
elif obj_type == "VM_INSTANCE":
obj = provider.appliance.provider_based_collection(provider).all()[0]
elif obj_type == "TEMPLATE_IMAGE":
obj = provider.appliance.collections.infra_templates.all()[0]
elif obj_type == "DATASTORE":
obj = provider.appliance.collections.datastores.filter({"provider": provider}).all()[0]
elif obj_type == "CLUSTER":
obj = provider.appliance.collections.clusters.all()[0]
else:
logger.error("No object collected for custom button object type '{}'".format(obj_type))
try:
if obj_type == "PROVIDER":
obj = provider
elif obj_type == "VM_INSTANCE":
obj = provider.appliance.provider_based_collection(provider).all()[0]
elif obj_type == "TEMPLATE_IMAGE":
obj = provider.appliance.collections.infra_templates.all()[0]
else:
obj = getattr(provider.appliance.collections, obj_type.lower()).all()[0]
except IndexError:
pytest.skip("Object not found for {obj} type".format(obj=obj_type))

return obj


Expand Down Expand Up @@ -255,9 +252,7 @@ def test_custom_button_dialog(appliance, dialog, request, setup_obj, button_grou
assert dialog_view.service_name.fill("Custom Button Execute")

# Clear the automation log
assert appliance.ssh_client.run_command(
'echo -n "" > /var/www/miq/vmdb/log/automation.log'
)
assert appliance.ssh_client.run_command('echo -n "" > /var/www/miq/vmdb/log/automation.log')

# Submit order
dialog_view.submit.click()
Expand Down

0 comments on commit 7dc1ba0

Please sign in to comment.