def test_custom_dashboards(request, soft_assert, number_dashboards): """Create some custom dashboards and check their presence. Then check their contents.""" # Very useful construct. List is mutable, so we can prepare the generic delete finalizer. # Then we add everything that succeeded with creation. Simple as that :) dashboards = [] request.addfinalizer(lambda: map(lambda item: item.delete(), dashboards)) def _create_dashboard(widgets): return Dashboard( generate_random_string(), "EvmGroup-super_administrator", generate_random_string(), locked=False, widgets=widgets ) for i in range(number_dashboards): d = _create_dashboard(pick(AVAILABLE_WIDGETS, 3)) d.create() dashboards.append(d) dash_dict = {d.title: d for d in dashboards} try: for dash_name in dashboard.dashboards(): soft_assert(dash_name in dash_dict, "Dashboard {} not found!".format(dash_name)) if dash_name in dash_dict: for widget in Widget.all(): soft_assert(widget.name in dash_dict[dash_name].widgets, "Widget {} not found in {}!".format(widget.name, dash_name)) del dash_dict[dash_name] soft_assert(not dash_dict, "Some of the dashboards were not found! ({})".format( ", ".join(dash_dict.keys()))) except IndexError: pytest.fail("No dashboard selection tabs present on dashboard!")
def report_vms(setup_first_provider): report = CustomReport( menu_name=generate_random_string(), title=generate_random_string(), base_report_on="Virtual Machines", report_fields=[ version.pick({ version.LOWEST: "Provider : Name", "5.3": "Cloud/Infrastructure Provider : Name", }), "Cluster : Name", "Datastore : Name", "Hardware : Number of CPUs", "Hardware : RAM", "Host : Name", "Name", ] ) report.create() report.queue(wait_for_finish=True) yield pick( filter( lambda i: len(i[ version.pick({ version.LOWEST: "Provider : Name", "5.3": "Cloud/Infrastructure Provider Name", }) ].strip()) > 0, list(report.get_saved_reports()[0].data.rows)), 2) report.delete()
def test_filter_with_user_input_and_cancellation(vms, subset_of_vms, expression_for_vms_subset): sel.force_navigate("infra_vms") vm = pick(subset_of_vms, 1)[0] # Set up the filter search.fill_and_apply_filter("fill_field(Virtual Machine : Name, =)", {"Virtual Machine": vm}, cancel_on_user_filling=True) assert_no_cfme_exception()
def test_filter_with_user_input(vms, subset_of_vms, expression_for_vms_subset): sel.force_navigate("infra_vms") vm = pick(subset_of_vms, 1)[0] # Set up the filter search.fill_and_apply_filter("fill_field(Virtual Machine : Name, =)", {"Virtual Machine": vm}) assert_no_cfme_exception() vms_present = virtual_machines.get_all_vms(do_not_navigate=True) if vm not in vms_present: pytest.fail("Could not find VM {} after filtering!".format(vm))
def test_filter_with_user_input_and_cancellation(vms, subset_of_vms, expression_for_vms_subset): sel.force_navigate("infra_vms") vm = pick(subset_of_vms, 1)[0] # Set up the filter search.fill_and_apply_filter( "fill_field(Virtual Machine : Name, =)", {"Virtual Machine": vm}, cancel_on_user_filling=True ) assert_no_cfme_exception()
def test_quick_search_without_filter(vms, subset_of_vms): sel.force_navigate("infra_vms") search.ensure_no_filter_applied() assert_no_cfme_exception() vm = pick(subset_of_vms, 1)[0] # Filter this host only search.normal_search(vm) assert_no_cfme_exception() # Check it is there all_vms_visible = virtual_machines.get_all_vms(do_not_navigate=True) assert len(all_vms_visible) == 1 and vm in all_vms_visible
def test_quick_search_with_filter(vms, subset_of_vms, expression_for_vms_subset): sel.force_navigate("infra_vms") search.fill_and_apply_filter(expression_for_vms_subset) assert_no_cfme_exception() # Filter this host only chosen_vm = pick(subset_of_vms, 1)[0] search.normal_search(chosen_vm) assert_no_cfme_exception() # Check it is there all_vms_visible = virtual_machines.get_all_vms(do_not_navigate=True) assert len(all_vms_visible) == 1 and chosen_vm in all_vms_visible
def test_filter_with_user_input(vms, subset_of_vms, expression_for_vms_subset): sel.force_navigate("infra_vms") vm = pick(subset_of_vms, 1)[0] # Set up the filter search.fill_and_apply_filter( "fill_field(Virtual Machine : Name, =)", {"Virtual Machine": vm} ) assert_no_cfme_exception() vms_present = virtual_machines.get_all_vms(do_not_navigate=True) if vm not in vms_present: pytest.fail("Could not find VM {} after filtering!".format(vm))
def test_quick_search_with_filter(request, vms, subset_of_vms, expression_for_vms_subset): sel.force_navigate("infra_vms") search.fill_and_apply_filter(expression_for_vms_subset) assert_no_cfme_exception() # Make sure that we empty the regular search field after the test request.addfinalizer(search.ensure_normal_search_empty) # Filter this host only chosen_vm = pick(subset_of_vms, 1)[0] search.normal_search(chosen_vm) assert_no_cfme_exception() # Check it is there all_vms_visible = virtual_machines.get_all_vms(do_not_navigate=True) assert len(all_vms_visible) == 1 and chosen_vm in all_vms_visible
def test_filter_save_and_load(request, vms, subset_of_vms, expression_for_vms_subset): sel.force_navigate("infra_vms") filter_name = generate_random_string() vm = pick(subset_of_vms, 1)[0] # Set up the filter search.save_filter("fill_field(Virtual Machine : Name, =)", filter_name) assert_no_cfme_exception() search.reset_filter() search.load_and_apply_filter(filter_name, fill_callback={"Virtual Machine": vm}) assert_no_cfme_exception() request.addfinalizer(search.delete_filter) assert vm in virtual_machines.get_all_vms(do_not_navigate=True)
def test_quick_search_without_filter(request, vms, subset_of_vms): sel.force_navigate("infra_vms") search.ensure_no_filter_applied() assert_no_cfme_exception() vm = pick(subset_of_vms, 1)[0] # Make sure that we empty the regular search field after the test request.addfinalizer(search.ensure_normal_search_empty) # Filter this host only search.normal_search(vm) assert_no_cfme_exception() # Check it is there all_vms_visible = virtual_machines.get_all_vms(do_not_navigate=True) assert len(all_vms_visible) == 1 and vm in all_vms_visible
def test_filter_save_and_load_cancel(request, vms, subset_of_vms): sel.force_navigate("infra_vms") filter_name = generate_random_string() vm = pick(subset_of_vms, 1)[0] # Set up the filter search.save_filter("fill_field(Virtual Machine : Name, =)", filter_name) def cleanup(): search.load_filter(filter_name) search.delete_filter() request.addfinalizer(cleanup) assert_no_cfme_exception() search.reset_filter() search.load_and_apply_filter(filter_name, fill_callback={"Virtual Machine": vm}, cancel_on_user_filling=True) assert_no_cfme_exception()
def test_filter_save_and_load_cancel(request, vms, subset_of_vms): sel.force_navigate("infra_vms") filter_name = generate_random_string() vm = pick(subset_of_vms, 1)[0] # Set up the filter search.save_filter("fill_field(Virtual Machine : Name, =)", filter_name) def cleanup(): search.load_filter(filter_name) search.delete_filter() request.addfinalizer(cleanup) assert_no_cfme_exception() search.reset_filter() search.load_and_apply_filter( filter_name, fill_callback={"Virtual Machine": vm}, cancel_on_user_filling=True ) assert_no_cfme_exception()
def test_custom_dashboards(request, soft_assert, number_dashboards): """Create some custom dashboards and check their presence. Then check their contents.""" # Very useful construct. List is mutable, so we can prepare the generic delete finalizer. # Then we add everything that succeeded with creation. Simple as that :) dashboards = [] request.addfinalizer(lambda: map(lambda item: item.delete(), dashboards)) def _create_dashboard(widgets): return Dashboard(generate_random_string(), "EvmGroup-super_administrator", generate_random_string(), locked=False, widgets=widgets) for i in range(number_dashboards): d = _create_dashboard(pick(AVAILABLE_WIDGETS, 3)) d.create() dashboards.append(d) dash_dict = {d.title: d for d in dashboards} try: for dash_name in dashboard.dashboards(): soft_assert(dash_name in dash_dict, "Dashboard {} not found!".format(dash_name)) if dash_name in dash_dict: for widget in Widget.all(): soft_assert( widget.name in dash_dict[dash_name].widgets, "Widget {} not found in {}!".format( widget.name, dash_name)) del dash_dict[dash_name] soft_assert( not dash_dict, "Some of the dashboards were not found! ({})".format(", ".join( dash_dict.keys()))) except IndexError: pytest.fail("No dashboard selection tabs present on dashboard!")
def subset_of_vms(vms): """We'll pick a host with median number of vms""" return pick(vms, 4)