def test_delete_dialog_before_parent_item(appliance, catalog_item): service_dialog = appliance.collections.service_dialogs dialog = service_dialog.instantiate(label=catalog_item.dialog.label) error_message = ('Dialog \"{}\": Error during delete: Dialog cannot be' ' deleted because it is connected to other components.').format(catalog_item.dialog.label) with error.expected(error_message): dialog.delete()
def test_duplicite_provider_creation(provider): """Tests that creation of already existing provider fails.""" message = 'Name has already been taken, Host Name has already been taken' if current_version() >= '5.8': message = 'Name has already been taken' with error.expected(message): provider.create(cancel=False, validate_credentials=True)
def test_zone_add_blank_name(): zc = current_appliance.collections.zones with error.expected("Name can't be blank"): zc.create( name='', description=fauxfactory.gen_alphanumeric(8) )
def test_permission_edit(appliance, request, product_features, action): """ Ensures that changes in permissions are enforced on next login Args: appliance: cfme appliance fixture request: pytest request fixture product_features: product features to set for test role action: reference to a function to execute under the test user context """ product_features = version.pick(product_features) request.addfinalizer(appliance.server.login_admin) role_name = fauxfactory.gen_alphanumeric() role = appliance.collections.roles.create(name=role_name, vm_restriction=None, product_features=[(['Everything'], False)] + # role_features [(k, True) for k in product_features]) group_description = 'grp{}'.format(fauxfactory.gen_alphanumeric()) group = group_collection(appliance).create(description=group_description, role=role.name) user = new_user(appliance, group=group) with user: try: action() except Exception: pytest.fail('Incorrect permissions set') appliance.server.login_admin() role.update({'product_features': [(['Everything'], True)] + [(k, False) for k in product_features] }) with user: try: with error.expected(Exception): action() except error.UnexpectedSuccessException: pytest.fail('Permissions have not been updated')
def test_provider_add_with_bad_credentials(provider): """ Tests provider add with bad credentials Metadata: test_flag: crud """ default_credentials = provider.default_endpoint.credentials # default settings flash = 'Login failed due to a bad username or password.' default_credentials.principal = "bad" default_credentials.secret = 'notyourday' if provider.one_of(AzureProvider): flash = ( "Credential validation was not successful: Incorrect credentials - " "check your Azure Client ID and Client Key" ) default_credentials.principal = str(uuid.uuid4()) default_credentials.secret = 'notyourday' elif provider.one_of(GCEProvider): flash = 'Credential validation was not successful: Invalid Google JSON key' default_credentials.service_account = '{"test": "bad"}' elif provider.one_of(OpenStackProvider): for endp_name in provider.endpoints.keys(): if endp_name != 'default': del provider.endpoints[endp_name] with error.expected(flash): provider.create(validate_credentials=True)
def test_zone_add_blank_description(): zc = current_appliance.collections.zones with error.expected("Description is required"): zc.create( name=fauxfactory.gen_alphanumeric(5), description='' )
def test_catalog_duplicate_name(): cat = Catalog(name=fauxfactory.gen_alphanumeric(), description="my catalog") cat.create() with error.expected("Name has already been taken"): cat.create() cat.delete()
def test_provider_add_with_bad_hostname(provider): """ Tests provider add with bad hostname (incorrect)""" provider.endpoints['default'].hostname = 'incorrect' with error.expected( 'Credential validation was not successful: Unable to connect to incorrect:{}' .format(provider.port)): provider.create(validate_credentials=True)
def test_user_group_error_validation(appliance): with error.expected("A User must be assigned to a Group"): appliance.collections.users.create( name='user{}'.format(fauxfactory.gen_alphanumeric()), credential=new_credential(), email='*****@*****.**', group='')
def test_control_import_invalid_yaml_file(appliance, import_invalid_yaml_file): if current_version() < "5.5": error_message = ("Error during 'Policy Import': undefined method `collect' " 'for "Invalid yaml":String') else: error_message = "Error during 'Policy Import': Invalid YAML file" with error.expected(error_message): import_export.import_file(appliance, import_invalid_yaml_file)
def test_duplicate_namespace_disallowed(request, parent_namespace): ns = parent_namespace.namespaces.create( name=fauxfactory.gen_alpha(), description=fauxfactory.gen_alpha()) with error.expected("Name has already been taken"): parent_namespace.namespaces.create( name=ns.name, description=ns.description)
def test_provider_add_with_bad_hostname(provider): """ Tests provider add with bad hostname (incorrect)""" provider.endpoints['default'].hostname = 'incorrect' with error.expected( 'Credential validation was not successful: Unable to connect to incorrect:{}' .format(provider.port)): with sel.ajax_timeout(120): provider.create(validate_credentials=True)
def test_delete_vm_from_detail(vm, appliance, method): del_action = getattr(vm.action.delete, method.upper()) del_action() assert_response(appliance) vm.wait_not_exists(num_sec=300, delay=10) with error.expected('ActiveRecord::RecordNotFound'): del_action() assert_response(appliance, http_status=404)
def test_name_required_error_validation(appliance): """ Tests a System Image with no name. """ collection = appliance.collections.system_image_types with error.expected('Name is required'): collection.create(name=None, provision_type=SystemImageType.VM_OR_INSTANCE)
def test_provider_add_with_bad_credentials(provider): """ Tests provider add with bad credentials""" provider.endpoints['default'].credentials = Credential(principal='bad', secret='reallybad') with error.expected( 'Credential validation was not successful: Invalid credentials'): provider.create(validate_credentials=True) view = provider.create_view(MiddlewareProviderAddView) assert not view.add.active
def test_pxe_image_type_required_error_validation(collection): """Test to validate pxe image type in customization templates.""" with error.expected("Pxe_image_type can't be blank"): collection.create(name=fauxfactory.gen_alphanumeric(8), description=fauxfactory.gen_alphanumeric(16), image_type=None, script_type='Kickstart', script_data='Testing the script')
def test_drift_analysis(request, provider, instance, soft_assert): """ Tests drift analysis is correct Metadata: test_flag: vm_analysis """ instance.load_details() drift_num_orig = 0 drift_orig = InfoBlock("Relationships", "Drift History").text if drift_orig != 'None': drift_num_orig = int(drift_orig) instance.smartstate_scan() wait_for(lambda: is_vm_analysis_finished(instance.name), delay=15, timeout="35m", fail_func=lambda: toolbar.select('Reload')) instance.load_details() wait_for( lambda: int(InfoBlock("Relationships", "Drift History").text) == drift_num_orig + 1, delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=sel.refresh ) drift_new = int(InfoBlock("Relationships", "Drift History").text) # add a tag and a finalizer to remove it tag = ('Department', 'Accounting') instance.add_tag(tag, single_value=False) request.addfinalizer(lambda: instance.remove_tag(tag)) instance.smartstate_scan() wait_for(lambda: is_vm_analysis_finished(instance.name), delay=15, timeout="35m", fail_func=lambda: toolbar.select('Reload')) instance.load_details() wait_for( lambda: int(InfoBlock("Relationships", "Drift History").text) == drift_new + 1, delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=sel.refresh ) # check drift difference soft_assert(not instance.equal_drift_results('Department (1)', 'My Company Tags', 0, 1), "Drift analysis results are equal when they shouldn't be") # Test UI features that modify the drift grid d_grid = DriftGrid() # Accounting tag should not be displayed, because it was changed to True toolbar.select("Attributes with same values") with error.expected(sel.NoSuchElementException): d_grid.get_cell('Accounting', 0) # Accounting tag should be displayed now toolbar.select("Attributes with different values") d_grid.get_cell('Accounting', 0)
def test_type_required_error_validation(collection): """Test to validate type in customization templates.""" with error.expected('Type is required'): collection.create(name=fauxfactory.gen_alphanumeric(8), description=fauxfactory.gen_alphanumeric(16), image_type='RHEL-6', script_type=None, script_data='Testing the script')
def test_zone_add_dupe(request): zc = current_appliance.get(ZoneCollection) name = fauxfactory.gen_alphanumeric(5) description = fauxfactory.gen_alphanumeric(8) zone = zc.create(name=name, description=description) request.addfinalizer(zone.delete) with error.expected('Name has already been taken'): zc.create(name=name, description=description)
def test_user_email_error_validation(appliance, group_collection): group = group_collection.instantiate(description='EvmGroup-user') with error.expected("Email must be a valid email address"): appliance.collections.users.create( name='user{}'.format(fauxfactory.gen_alphanumeric()), credential=new_credential(), email='xyzdhat.com', group=group)
def test_delete_dialog_before_parent_item(appliance, catalog_item): service_dialog = appliance.collections.service_dialogs dialog = service_dialog.instantiate(label=catalog_item.dialog.label) error_message = ( 'Dialog \"{}\": Error during delete: Dialog cannot be' ' deleted because it is connected to other components.').format( catalog_item.dialog.label) with error.expected(error_message): dialog.delete()
def test_user_email_error_validation(appliance, group_collection): group = group_collection.instantiate(description='EvmGroup-user') with error.expected("Email must be a valid email address"): appliance.collections.users.create(name='user{}'.format( fauxfactory.gen_alphanumeric()), credential=new_credential(), email='xyzdhat.com', groups=group)
def test_name_required_error_validation(provisioning, create_template): flash_msg = \ "Error during 'Orchestration Template creation': Validation failed: Name can't be blank" template_type = provisioning['stack_provisioning']['template_type'] template = OrchestrationTemplate(template_type=template_type, template_name=None, description="my template") with error.expected(flash_msg): template.create(create_template)
def test_name_required_error_validation(): """ Tests a System Image with no name. """ sys_image_type = SystemImageType( name=None, provision_type=SystemImageType.VM_OR_INSTANCE) with error.expected('Name is required'): sys_image_type.create()
def test_name_required_error_validation(appliance): """ Tests a System Image with no name. """ collection = appliance.collections.system_image_types with error.expected('Name is required'): collection.create( name=None, provision_type=SystemImageType.VM_OR_INSTANCE)
def test_group_description_required_error_validation(group_collection): error_text = "Description can't be blank" with error.expected(error_text): group_collection.create(description=None, role='EvmRole-approver') # Navigating away from this page will create an "Abandon Changes" alert # Since group creation failed we need to reset the state of the page navigate_to(group_collection.parent.server, 'Dashboard')
def test_collection_class_invalid(appliance): """Tests that it's not possible to query using invalid collection_class. Metadata: test_flag: rest """ with error.expected('Invalid collection_class'): appliance.rest_api.collections.vms.query_string( collection_class='ManageIQ::Providers::Nonexistent::Vm')
def test_control_import_invalid_yaml_file(import_invalid_yaml_file): if current_version() < "5.5": error_message = ( "Error during 'Policy Import': undefined method `collect' " 'for "Invalid yaml":String') else: error_message = "Error during 'Policy Import': Invalid YAML file" with error.expected(error_message): import_export.import_file(import_invalid_yaml_file)
def test_username_required_error_validation(appliance, group_collection): group_name = 'EvmGroup-user' group = group_collection.instantiate(description=group_name) with error.expected("Name can't be blank"): appliance.collections.users.create(name="", credential=new_credential(), email='*****@*****.**', groups=[group])
def test_drift_analysis(request, provider, instance, soft_assert): """ Tests drift analysis is correct Metadata: test_flag: vm_analysis """ instance.load_details() drift_num_orig = 0 drift_orig = InfoBlock("Relationships", "Drift History").text if drift_orig != 'None': drift_num_orig = int(drift_orig) instance.smartstate_scan() wait_for(lambda: is_vm_analysis_finished(instance.name), delay=15, timeout="35m", fail_func=lambda: toolbar.select('Reload')) instance.load_details() wait_for( lambda: int(InfoBlock("Relationships", "Drift History").text) == drift_num_orig + 1, delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=sel.refresh ) drift_new = int(InfoBlock("Relationships", "Drift History").text) # add a tag and a finalizer to remove it instance.add_tag('Department', 'Accounting') request.addfinalizer(lambda: instance.remove_tag('Department', 'Accounting')) instance.smartstate_scan() wait_for(lambda: is_vm_analysis_finished(instance.name), delay=15, timeout="35m", fail_func=lambda: toolbar.select('Reload')) instance.load_details() wait_for( lambda: int(InfoBlock("Relationships", "Drift History").text) == drift_new + 1, delay=20, num_sec=120, message="Waiting for Drift History count to increase", fail_func=sel.refresh ) # check drift difference soft_assert(not instance.equal_drift_results('Department (1)', 'My Company Tags', 0, 1), "Drift analysis results are equal when they shouldn't be") # Test UI features that modify the drift grid d_grid = DriftGrid() # Accounting tag should not be displayed, because it was changed to True toolbar.select("Attributes with same values") with error.expected(sel.NoSuchElementException): d_grid.get_cell('Accounting', 0) # Accounting tag should be displayed now toolbar.select("Attributes with different values") d_grid.get_cell('Accounting', 0)
def test_username_required_error_validation(group_collection): group_name = 'EvmGroup-user' group = group_collection.instantiate(description=group_name) user = User(name="", credential=new_credential(), email='*****@*****.**', group=group) with error.expected("Name can't be blank"): user.create()
def test_delete_catalog_deletes_service(appliance, dialog, catalog): item_name = fauxfactory.gen_alphanumeric() catalog_item = CatalogItem(item_type="Generic", name=item_name, description="my catalog", display_in=True, catalog=catalog, dialog=dialog) catalog_item.create() catalog.delete() service_catalogs = ServiceCatalogs(appliance, catalog, catalog_item.name) with error.expected(NoSuchElementException): service_catalogs.order()
def test_schema_duplicate_field_disallowed(request, domain): ns = domain.namespaces.create(name=fauxfactory.gen_alpha(), description=fauxfactory.gen_alpha()) a_class = ns.classes.create(name=fauxfactory.gen_alphanumeric(), display_name=fauxfactory.gen_alphanumeric(), description=fauxfactory.gen_alphanumeric()) field = fauxfactory.gen_alpha() a_class.schema.add_field(name=field, type='Relationship') with error.expected('Name has already been taken'): a_class.schema.add_field(name=field, type='Relationship')
def test_provider_add_with_bad_credentials(provider): """ Tests provider add with bad credentials""" provider.endpoints['default'].credentials = Credential( principal='bad', secret='reallybad' ) with error.expected('Credential validation was not successful: Invalid credentials'): provider.create(validate_credentials=True) view = provider.create_view(MiddlewareProviderAddView) assert not view.add.active
def test_duplicate_domain_disallowed(request, appliance): domains = DomainCollection(appliance) domain = domains.create(name=fauxfactory.gen_alpha(), description=fauxfactory.gen_alpha(), enabled=True) request.addfinalizer(domain.delete_if_exists) with error.expected("Name has already been taken"): domains.create(name=domain.name, description=domain.description, enabled=domain.enabled)
def test_delete_vm_from_detail(vm_name, appliance, method): vm = appliance.rest_api.collections.vms.get(name=vm_name) del_action = getattr(vm.action.delete, method.upper()) del_action() assert_response(appliance) wait_for( lambda: not appliance.rest_api.collections.vms.find_by(name=vm_name), num_sec=300, delay=10) with error.expected('ActiveRecord::RecordNotFound'): del_action() assert_response(appliance, http_status=404)
def test_type_required_error_validation(collection): """Test to validate type in customization templates.""" with error.expected('Type is required'): collection.create( name=fauxfactory.gen_alphanumeric(8), description=fauxfactory.gen_alphanumeric(16), image_type='RHEL-6', script_type=None, script_data='Testing the script')
def test_pxe_image_type_required_error_validation(collection): """Test to validate pxe image type in customization templates.""" with error.expected("Pxe_image_type can't be blank"): collection.create( name=fauxfactory.gen_alphanumeric(8), description=fauxfactory.gen_alphanumeric(16), image_type=None, script_type='Kickstart', script_data='Testing the script')
def test_no_template_catalog_item(provider, provisioning, setup_provider, vm_name, dialog, catalog): """Tests no template catalog item Metadata: test_flag: provision """ item_name = fauxfactory.gen_alphanumeric() catalog_item = CatalogItem(item_type=provider.catalog_name, name=item_name, description="my catalog", display_in=True, catalog=catalog, dialog=dialog) with error.expected("'Catalog/Name' is required"): catalog_item.create()
def test_new_template_required_error_validation(provisioning): flash_msg = \ 'Error during Orchestration Template creation: new template content cannot be empty' template_type = provisioning['stack_provisioning']['template_type'] template = OrchestrationTemplate(template_type=template_type, template_name=fauxfactory.gen_alphanumeric(), description="my template") with error.expected(flash_msg): template.create('')
def test_provider_add_with_bad_credentials(provider): """Tests provider add with bad credentials Metadata: test_flag: crud """ provider.default_endpoint.credentials = Credential( principal='bad', secret='reallybad', verify_secret='reallybad') with error.expected(provider.bad_credentials_error_msg): provider.create(validate_credentials=True)
def test_name_max_character_validation(collection): """Test to validate name with maximum characters in customization templates.""" with error.expected('Name is required'): template_name = collection.create( name=fauxfactory.gen_alphanumeric(256), description=fauxfactory.gen_alphanumeric(16), image_type='RHEL-6', script_type='Kickstart', script_data='Testing the script') collection.delete(False, template_name)
def test_new_template_required_error_validation(provisioning): flash_msg = \ 'Error during Orchestration Template creation: new template content cannot be empty' template_type = provisioning['stack_provisioning']['template_type'] template = OrchestrationTemplate( template_type=template_type, template_name=fauxfactory.gen_alphanumeric(), description="my template") with error.expected(flash_msg): template.create('')
def test_userid_required_error_validation(): user = User(name='user' + fauxfactory.gen_alphanumeric(), credential=Credential(principal='', secret='redhat'), email='*****@*****.**', group=group_user) with error.expected("Userid can't be blank"): user.create() # Navigating away from this page will create an "Abandon Changes" alert # Since group creation failed we need to reset the state of the page navigate_to(user.appliance.server, 'Dashboard')
def test_username_required_error_validation(group_collection): group_name = 'EvmGroup-user' group = group_collection.instantiate(description=group_name) user = User( name="", credential=new_credential(), email='*****@*****.**', group=group) with error.expected("Name can't be blank"): user.create()
def test_delete_template_from_detail_delete(appliance, template): """Tests deletion of template from detail using DELETE method. Metadata: test_flag: rest """ template.action.delete.DELETE() assert_response(appliance) with error.expected("ActiveRecord::RecordNotFound"): template.action.delete.DELETE() assert_response(appliance, http_status=404)
def test_pxe_image_type_required_error_validation(): """Test to validate pxe image type in customization templates.""" template_name = pxe.CustomizationTemplate( name=fauxfactory.gen_alphanumeric(8), description=fauxfactory.gen_alphanumeric(16), image_type='<Choose>', script_type='Kickstart', script_data='Testing the script') with error.expected("Pxe_image_type can't be blank"): template_name.create()
def test_delete_template_from_detail_delete(appliance, template): """Tests deletion of template from detail using DELETE method. Metadata: test_flag: rest """ template.action.delete(force_method="delete") assert appliance.rest_api.response.status_code == 204 with error.expected("ActiveRecord::RecordNotFound"): template.action.delete(force_method="delete") assert appliance.rest_api.response.status_code == 404
def test_host_bad_creds(appliance, request, setup_provider, provider): """ Tests host credentialing with bad credentials """ test_host = random.choice(provider.data["hosts"]) host_collection = appliance.collections.hosts host_obj = host_collection.instantiate(name=test_host.name, provider=provider) with error.expected(msgs[provider.type]): with update(host_obj, validate_credentials=True): host_obj.credentials = host.get_credentials_from_config('bad_credentials')
def test_duplicate_domain_disallowed(request, appliance): domain = appliance.collections.domains.create( name=fauxfactory.gen_alpha(), description=fauxfactory.gen_alpha(), enabled=True) request.addfinalizer(domain.delete_if_exists) with error.expected("Name has already been taken"): appliance.collections.domains.create( name=domain.name, description=domain.description, enabled=domain.enabled)
def test_delete_tags_from_collection(self, appliance, tags): """Tests deleting tags from collection. Metadata: test_flag: rest """ appliance.rest_api.collections.tags.action.delete(*tags) assert_response(appliance) with error.expected("ActiveRecord::RecordNotFound"): appliance.rest_api.collections.tags.action.delete(*tags) assert_response(appliance, http_status=404)