Example #1
0
def manage_folder(group, folder=None):
    """Context manager to use when modifying the folder contents.

    You can use manager's :py:meth:`FolderManager.bail_out` classmethod to end and discard the
    changes done inside the with block. This context manager does not give the manager as a value to
    the with block so you have to import and use the :py:class:`FolderManager` class manually.

    Args:
        group: User group.
        folder: Which folder to manage. If None, top-level will be managed.
    Returns: Context-managed :py:class:`cfme.intelligence.reports.ui_elements.FolderManager` inst.
    """
    go_to_group(group)
    if folder is None:
        reports_tree().click_path("Top Level")
    else:
        reports_tree().click_path("Top Level", folder)
    try:
        yield manager
    except FolderManager._BailOut:
        logger.info("Discarding editation modifications on %s", str(repr(manager)))
        manager.discard()
    except:
        # In case of any exception, nothing will be saved
        manager.discard()
        raise  # And reraise the exception
    else:
        # If no exception happens, save!
        manager.commit()
        form_buttons.save()
Example #2
0
def manage_subfolder(group, folder, subfolder):
    """Context manager to use when modifying the subfolder contents.

    You can use manager's :py:meth:`FolderManager.bail_out` classmethod to end and discard the
    changes done inside the with block.

    Args:
        group: User group.
        folder: Parent folder name.
        subfolder: Subfodler name to manage.
    Returns: Context-managed :py:class:`cfme.intelligence.reports.ui_elements.FolderManager` inst.
    """
    go_to_group(group)
    reports_tree().click_path("Top Level", folder, subfolder)
    try:
        yield report_select
    except FolderManager._BailOut:
        logger.info("Discarding editation modifications on %s", str(repr(manager)))
        manager.discard()
    except:
        # In case of any exception, nothing will be saved
        manager.discard()
        raise  # And reraise the exception
    else:
        # If no exception happens, save!
        manager.commit()
        form_buttons.save()
Example #3
0
def manage_folder(group, folder=None):
    """Context manager to use when modifying the folder contents.

    You can use manager's :py:meth:`FolderManager.bail_out` classmethod to end and discard the
    changes done inside the with block. This context manager does not give the manager as a value to
    the with block so you have to import and use the :py:class:`FolderManager` class manually.

    Args:
        group: User group.
        folder: Which folder to manage. If None, top-level will be managed.
    Returns: Context-managed :py:class:`cfme.intelligence.reports.ui_elements.FolderManager` inst.
    """
    sel.force_navigate("report_menus_group", context={"group": group})
    if folder is None:
        reports_tree.click_path("Top Level")
    else:
        reports_tree.click_path("Top Level", folder)
    try:
        yield manager
    except FolderManager._BailOut:
        logger.info("Discarding editation modifications on {}".format(str(repr(manager))))
        manager.discard()
    except:
        # In case of any exception, nothing will be saved
        manager.discard()
        raise  # And reraise the exception
    else:
        # If no exception happens, save!
        manager.commit()
        form_buttons.save()
Example #4
0
def manage_folder(group, folder=None):
    """Context manager to use when modifying the folder contents.

    Args:
        group: User group.
        folder: Which folder to manage. If None, top-level will be managed.
    Returns: Context-managed :py:class:`cfme.intelligence.reports.ui_elements.FolderManager` inst.
    """
    sel.force_navigate("report_menus_group", context={"group": group})
    if folder is None:
        reports_tree.click_path("Top Level")
    else:
        reports_tree.click_path("Top Level", folder)
    try:
        yield manager
    except FolderManager._BailOut:
        logger.info("Discarding editation modifications on {}".format(str(repr(manager))))
        manager.discard()
    except:
        # In case of any exception, nothing will be saved
        manager.discard()
        raise  # And reraise the exception
    else:
        # If no exception happens, save!
        manager.commit()
        form_buttons.save()
Example #5
0
def manage_subfolder(group, folder, subfolder):
    """Context manager to use when modifying the subfolder contents.

    You can use manager's :py:meth:`FolderManager.bail_out` classmethod to end and discard the
    changes done inside the with block.

    Args:
        group: User group.
        folder: Parent folder name.
        subfolder: Subfodler name to manage.
    Returns: Context-managed :py:class:`cfme.intelligence.reports.ui_elements.FolderManager` inst.
    """
    sel.force_navigate("report_menus_group", context={"group": group})
    reports_tree.click_path("Top Level", folder, subfolder)
    try:
        yield report_select
    except FolderManager._BailOut:
        logger.info("Discarding editation modifications on {}".format(str(repr(manager))))
        manager.discard()
    except:
        # In case of any exception, nothing will be saved
        manager.discard()
        raise  # And reraise the exception
    else:
        # If no exception happens, save!
        manager.commit()
        form_buttons.save()
Example #6
0
 def remove_tag(self, tag, value):
     sel.force_navigate("cfg_accesscontrol_group_ed", context={"group": self})
     pol_btn("Edit 'My Company' Tags for this Group", invokes_alert=True)
     row = tag_table.find_row_by_cells({'category': tag, 'assigned_value': value},
         partial_check=True)
     sel.click(row[0])
     form_buttons.save()
     flash.assert_success_message('Tag edits were successfully saved')
Example #7
0
 def remove_tag(self, tag, value):
     sel.force_navigate("cfg_accesscontrol_group_ed", context={"group": self})
     pol_btn("Edit 'My Company' Tags for this Group", invokes_alert=True)
     row = tag_table.find_row_by_cells({'category': tag, 'assigned_value': value},
         partial_check=True)
     sel.click(row[0])
     form_buttons.save()
     flash.assert_success_message('Tag edits were successfully saved')
Example #8
0
 def remove_tag(self, tag, value):
     navigate_to(self, 'Details')
     pol_btn("Edit 'My Company' Tags for this Group", invokes_alert=True)
     row = tag_table.find_row_by_cells({'category': tag, 'assigned_value': value},
                                       partial_check=True)
     sel.click(row[0])
     form_buttons.save()
     flash.assert_success_message('Tag edits were successfully saved')
 def remove_tag(self, tag, value):
     navigate_to(self, 'Details')
     pol_btn("Edit 'My Company' Tags for this Group", invokes_alert=True)
     row = tag_table.find_row_by_cells({'category': tag, 'assigned_value': value},
                                       partial_check=True)
     sel.click(row[0])
     form_buttons.save()
     flash.assert_success_message('Tag edits were successfully saved')
 def update(self, updates):
     sel.force_navigate('service_dialog_edit', context={'dialog': self})
     fill(
         label_form, {
             'name_text': updates.get('name', None),
             'description_text': updates.get('description', None)
         })
     form_buttons.save()
     flash.assert_no_errors()
Example #11
0
def remove_tag(tag):
    toolbar.select('Policy', 'Edit Tags')
    display_name = tag.category.display_name
    row = tag_table.find_row_by_cells({'category': display_name,
                                       'assigned_value': tag.display_name},
                                      partial_check=True)
    sel.click(row[0])
    form_buttons.save()
    flash.assert_success_message('Tag edits were successfully saved')
Example #12
0
def add_tag(tag):
    toolbar.select('Policy', 'Edit Tags')
    if tag.category.single_value:
        display_name = "{} *".format(tag.category.display_name)
    else:
        display_name = tag.category.display_name
    fill(tag_form, {'category': display_name,
                    'tag': tag.display_name})
    form_buttons.save()
    flash.assert_success_message('Tag edits were successfully saved')
Example #13
0
def add_tag(tag, single_value=False):
    toolbar.select('Policy', 'Edit Tags')
    if isinstance(tag, (list, tuple)):
        fill_d = {
            "category": tag[0] if not single_value else "{} *".format(tag[0]),
            "tag": tag[1]
        }
    else:
        fill_d = {"tag": tag.display_name}
        if tag.category.single_value:
            fill_d["category"] = "{} *".format(tag.category.display_name)
        else:
            fill_d["category"] = tag.category.display_name
    fill(tag_form, fill_d)
    form_buttons.save()
    flash.assert_success_message('Tag edits were successfully saved')
Example #14
0
    def _assign_unassign_policy_profiles(self, assign, *policy_profile_names):
        """ Assign or unassign Policy Profiles to this Provider. DRY method

        Args:
            assign: Whether this method assigns or unassigns policy profiles.
            policy_profile_names: :py:class:`str` with Policy Profile's name. After Control/Explorer
                coverage goes in, PolicyProfile object will be also passable.
        """
        sel.force_navigate('clouds_provider_policy_assignment', context={'provider': self})
        for policy_profile in policy_profile_names:
            if assign:
                manage_policies_tree.check_node(policy_profile)
            else:
                manage_policies_tree.uncheck_node(policy_profile)
        sel.move_to_element('#tP')
        form_buttons.save()
Example #15
0
    def _assign_unassign_policy_profiles(self, assign, *policy_profile_names):
        """DRY function for managing policy profiles.

        See :py:func:`assign_policy_profiles` and :py:func:`assign_policy_profiles`

        Args:
            assign: Wheter to assign or unassign.
            policy_profile_names: :py:class:`str` with Policy Profile names.
        """
        sel.force_navigate('infrastructure_provider_policy_assignment', context={'provider': self})
        for policy_profile in policy_profile_names:
            if assign:
                manage_policies_tree.check_node(policy_profile)
            else:
                manage_policies_tree.uncheck_node(policy_profile)
        form_buttons.save()
Example #16
0
def add_tag(tag, single_value=False, navigate=True):
    if navigate:
        toolbar.select('Policy', 'Edit Tags')
    if isinstance(tag, (list, tuple)):
        fill_d = {
            "category": tag[0] if not single_value else "{} *".format(tag[0]),
            "tag": tag[1]
        }
    else:
        fill_d = {"tag": tag.display_name}
        if tag.category.single_value:
            fill_d["category"] = "{} *".format(tag.category.display_name)
        else:
            fill_d["category"] = tag.category.display_name
    fill(tag_form, fill_d)
    form_buttons.save()
    flash.assert_success_message('Tag edits were successfully saved')
Example #17
0
    def _assign_unassign_policy_profiles(self, assign, *policy_profile_names):
        """DRY function for managing policy profiles.

        See :py:func:`assign_policy_profiles` and :py:func:`assign_policy_profiles`

        Args:
            assign: Wheter to assign or unassign.
            policy_profile_names: :py:class:`str` with Policy Profile names.
        """
        sel.force_navigate('infrastructure_provider_policy_assignment',
                           context={'provider': self})
        for policy_profile in policy_profile_names:
            if assign:
                manage_policies_tree.check_node(policy_profile)
            else:
                manage_policies_tree.uncheck_node(policy_profile)
        form_buttons.save()
Example #18
0
    def _assign_unassign_policy_profiles(self, assign, *policy_profile_names):
        """DRY function for managing policy profiles.

        See :py:func:`assign_policy_profiles` and :py:func:`assign_policy_profiles`

        Args:
            assign: Wheter to assign or unassign.
            policy_profile_names: :py:class:`str` with Policy Profile names.
        """
        self.load_details(refresh=True)
        pol_btn("Manage Policies")
        for policy_profile in policy_profile_names:
            if assign:
                self.manage_policies_tree.check_node(policy_profile)
            else:
                self.manage_policies_tree.uncheck_node(policy_profile)
        form_buttons.save()
        flash.assert_no_errors()
Example #19
0
    def _assign_unassign_policy_profiles(self, assign, *policy_profile_names):
        """DRY function for managing policy profiles.

        See :py:func:`assign_policy_profiles` and :py:func:`assign_policy_profiles`

        Args:
            assign: Wheter to assign or unassign.
            policy_profile_names: :py:class:`str` with Policy Profile names.
        """
        self.load_details(refresh=True)
        pol_btn("Manage Policies")
        for policy_profile in policy_profile_names:
            if assign:
                self.manage_policies_tree.check_node(policy_profile)
            else:
                self.manage_policies_tree.uncheck_node(policy_profile)
        form_buttons.save()
        flash.assert_no_errors()
def set_random_tag(instance):
    navigate_to(instance, 'Details')
    toolbar.select('Policy', 'Edit Tags')

    # select random tag category
    cat_selector = AngularSelect("tag_cat")
    random_cat = random.choice(cat_selector.all_options)
    cat_selector.select_by_value(random_cat.value)

    # select random tag tag
    tag_selector = AngularSelect("tag_add")
    random_tag = random.choice([op for op in tag_selector.all_options if op.value != "select"])
    tag_selector.select_by_value(random_tag.value)

    # Save tag conig
    form_buttons.save()

    return Tag(display_name=random_tag.text, category=random_cat.text)
Example #21
0
def set_random_tag(instance):
    navigate_to(instance, 'Details')
    toolbar.select('Policy', 'Edit Tags')

    # select random tag category
    cat_selector = AngularSelect("tag_cat")
    random_cat = random.choice(cat_selector.all_options)
    cat_selector.select_by_value(random_cat.value)

    # select random tag tag
    tag_selector = AngularSelect("tag_add")
    random_tag = random.choice([op for op in tag_selector.all_options if op.value != "select"])
    tag_selector.select_by_value(random_tag.value)

    # Save tag conig
    form_buttons.save()

    return Tag(display_name=random_tag.text, category=random_cat.text)
Example #22
0
    def update(self, updates, cancel=False, samba_validate=False):
        """ Modify an existing schedule with informations from this instance.

        Args:
            updates: Dict with fields to be updated
            cancel: Whether to click on the cancel button to interrupt the editation.
            samba_validate: Samba-only option to click the `Validate` button to check
                            if entered samba credentials are valid or not
        """
        navigate_to(self, 'Edit')

        self.details.update(updates)
        fill(self.form, self.details)
        if samba_validate:
            sel.click(form_buttons.validate)
        if cancel:
            form_buttons.cancel()
        else:
            form_buttons.save()
Example #23
0
    def _assign_unassign_policy_profiles(self, assign, *policy_profile_names):
        """ Assign or unassign Policy Profiles to this Provider. DRY method

        See :py:func:`assign_policy_profiles` and :py:func:`assign_policy_profiles`

        Args:
            assign: Whether this method assigns or unassigns policy profiles.
            policy_profile_names: :py:class:`str` with Policy Profile's name. After Control/Explorer
                coverage goes in, PolicyProfile object will be also passable.
        """
        sel.force_navigate('{}_provider_policy_assignment'.format(
            self.page_name),
                           context={'provider': self})
        for policy_profile in policy_profile_names:
            if assign:
                manage_policies_tree.check_node(policy_profile)
            else:
                manage_policies_tree.uncheck_node(policy_profile)
        sel.move_to_element('#tP')
        form_buttons.save()
Example #24
0
def set_random_tag(instance):
    logger.debug("Setting random tag")
    navigate_to(instance, 'Details')
    toolbar.select('Policy', 'Edit Tags')

    # select random tag category
    cat_selector = AngularSelect("tag_cat")
    random_cat = random.choice(cat_selector.all_options)
    logger.debug("Selected category {cat}".format(cat=random_cat))
    cat_selector.select_by_value(random_cat.value)

    # select random tag tag
    tag_selector = AngularSelect("tag_add")
    random_tag = random.choice([op for op in tag_selector.all_options if op.value != "select"])
    logger.debug("Selected value {tag}".format(tag=random_tag))
    tag_selector.select_by_value(random_tag.value)

    # Save tag conig
    form_buttons.save()
    logger.debug("Tag configuration was saved")
    return Tag(display_name=random_tag.text, category=random_cat.text)
Example #25
0
def update_registration(service,
                        url,
                        username,
                        password,
                        password_verify=None,
                        repo_name=None,
                        organization=None,
                        use_proxy=False,
                        proxy_url=None,
                        proxy_username=None,
                        proxy_password=None,
                        proxy_password_verify=None,
                        validate=True,
                        cancel=False,
                        set_default_rhsm_address=False,
                        set_default_repository=False):
    """ Fill in the registration form, validate and save/cancel

    Args:
        service: Service type (registration method).
        url: Service server URL address.
        username: Username to use for registration.
        password: Password to use for registration.
        password_verify: 2nd entry of password for verification.
                         Same as 'password' if None.
        repo_or_channel: Repository/channel to enable.
        organization: Organization (sat5/sat6 only).
        use_proxy: `True` if proxy should be used, `False` otherwise
                   (default `False`).
        proxy_url: Address of the proxy server.
        proxy_username: Username for the proxy server.
        proxy_password: Password for the proxy server.
        proxy_password_verify: 2nd entry of proxy server password for verification.
                               Same as 'proxy_password' if None.
        validate: Click the Validate button and check the
                  flash message for errors if `True` (default `True`)
        cancel: Click the Cancel button if `True` or the Save button
                if `False` (default `False`)
        set_default_rhsm_address: Click the Default button connected to
                                  the RHSM (only) address if `True`
        set_default_repository: Click the Default button connected to
                                the repo/channel if `True`

    Warning:
        'password_verify' and 'proxy_password_verify' are available in 5.4+ only.

    Note:
        With satellite 6, it is necessary to validate credentials to obtain
        available organizations from the server.
        With satellite 5, 'validate' parameter is ignored because there is
        no validation button available.
    """
    assert service in service_types, "Unknown service type '{}'".format(service)
    service_value = service_types[service]

    # In 5.4+, we have verification inputs as well
    if version.current_version() >= '5.4':
        password_verify = password_verify or password
        proxy_password_verify = proxy_password_verify or proxy_password
    # Otherwise, verification inputs are ignored df even if specified
    else:
        password_verify = None
        proxy_password_verify = None

    # Sat6 organization can be selected only after successful validation
    # while Sat5 organization is selected normally
    if service == 'sat6':
        organization_sat5 = None
        organization_sat6 = organization
    else:
        organization_sat5 = organization
        organization_sat6 = None

    sel.force_navigate("cfg_settings_region_red_hat_updates")
    sel.click(update_buttons.edit_registration)
    details = dict(
        service=sel.ByValue(service_value),
        url=url,
        username=username,
        password=password,
        password_verify=password_verify,
        repo_name=repo_name,
        organization_sat5=organization_sat5,
        use_proxy=use_proxy,
        proxy_url=proxy_url,
        proxy_username=proxy_username,
        proxy_password=proxy_password,
        proxy_password_verify=proxy_password_verify
    )

    fill(registration_form, details)

    if set_default_rhsm_address:
        sel.click(registration_buttons.url_default)

    if set_default_repository:
        sel.click(registration_buttons.repo_default)

    if validate and service != 'sat5':
        sel.click(form_buttons.validate_short)
        flash.assert_no_errors()
        flash.dismiss()

    if organization_sat6:
        sel.select(registration_form.locators['organization_sat6'], organization_sat6)

    if cancel:
        form_buttons.cancel()
    else:
        form_buttons.save()
        flash.assert_message_match("Customer Information successfully saved")
        flash.dismiss()
Example #26
0
def update_registration(service,
                        url,
                        username,
                        password,
                        password_verify=None,
                        repo_name=None,
                        organization=None,
                        use_proxy=False,
                        proxy_url=None,
                        proxy_username=None,
                        proxy_password=None,
                        proxy_password_verify=None,
                        validate=True,
                        cancel=False,
                        set_default_rhsm_address=False,
                        set_default_repository=False):
    """ Fill in the registration form, validate and save/cancel

    Args:
        service: Service type (registration method).
        url: Service server URL address.
        username: Username to use for registration.
        password: Password to use for registration.
        password_verify: 2nd entry of password for verification.
                         Same as 'password' if None.
        repo_or_channel: Repository/channel to enable.
        organization: Organization (sat5/sat6 only).
        use_proxy: `True` if proxy should be used, `False` otherwise
                   (default `False`).
        proxy_url: Address of the proxy server.
        proxy_username: Username for the proxy server.
        proxy_password: Password for the proxy server.
        proxy_password_verify: 2nd entry of proxy server password for verification.
                               Same as 'proxy_password' if None.
        validate: Click the Validate button and check the
                  flash message for errors if `True` (default `True`)
        cancel: Click the Cancel button if `True` or the Save button
                if `False` (default `False`)
        set_default_rhsm_address: Click the Default button connected to
                                  the RHSM (only) address if `True`
        set_default_repository: Click the Default button connected to
                                the repo/channel if `True`

    Warning:
        'password_verify' and 'proxy_password_verify' are available in 5.4+ only.

    Note:
        With satellite 6, it is necessary to validate credentials to obtain
        available organizations from the server.
        With satellite 5, 'validate' parameter is ignored because there is
        no validation button available.
    """
    assert service in service_types, "Unknown service type '{}'".format(
        service)
    service_value = service_types[service]

    # In 5.4+, we have verification inputs as well
    if version.current_version() >= '5.4':
        password_verify = password_verify or password
        proxy_password_verify = proxy_password_verify or proxy_password
    # Otherwise, verification inputs are ignored df even if specified
    else:
        password_verify = None
        proxy_password_verify = None

    # Sat6 organization can be selected only after successful validation
    # while Sat5 organization is selected normally
    if service == 'sat6':
        organization_sat5 = None
        organization_sat6 = organization
    else:
        organization_sat5 = organization
        organization_sat6 = None

    sel.force_navigate("cfg_settings_region_red_hat_updates")
    sel.click(update_buttons.edit_registration)
    details = dict(service=sel.ByValue(service_value),
                   url=url,
                   username=username,
                   password=password,
                   password_verify=password_verify,
                   repo_name=repo_name,
                   organization_sat5=organization_sat5,
                   use_proxy=use_proxy,
                   proxy_url=proxy_url,
                   proxy_username=proxy_username,
                   proxy_password=proxy_password,
                   proxy_password_verify=proxy_password_verify)

    fill(registration_form, details)

    if set_default_rhsm_address:
        sel.click(registration_buttons.url_default)

    if set_default_repository:
        sel.click(registration_buttons.repo_default)

    if validate and service != 'sat5':
        sel.click(form_buttons.validate_short)
        flash.assert_no_errors()
        flash.dismiss()

    if organization_sat6:
        sel.select(registration_form.locators['organization_sat6'],
                   organization_sat6)

    if cancel:
        form_buttons.cancel()
    else:
        form_buttons.save()
        flash.assert_message_match("Customer Information successfully saved")
        flash.dismiss()
Example #27
0
def update_registration(service,
                        url,
                        username,
                        password,
                        repo_name=None,
                        organization=None,
                        use_proxy=False,
                        proxy_url=None,
                        proxy_username=None,
                        proxy_password=None,
                        validate=False,
                        cancel=False,
                        set_default_rhsm_address=False,
                        set_default_repository=False):
    """ Fill in the registration form, validate and save/cancel

    Args:
        service: Service type (registration method).
        url: Service server URL address.
        username: Username to use for registration.
        password: Password to use for registration.
        repo_or_channel: Repository/channel to enable.
        organization: Organization (sat5/sat6 only).
        use_proxy: `True` if proxy should be used, `False` otherwise
                   (default `False`).
        proxy_url: Address of the proxy server.
        proxy_username: Username for the proxy server.
        proxy_password: Password for the proxy server.
        validate: Click the Validate button and check the
                  flash message for errors if `True` (default `False`)
        cancel: Click the Cancel button if `True` or the Save button
                if `False` (default `False`)
        set_default_rhsm_address: Click the Default button connected to
                                  the RHSM (only) address if `True`
        set_default_repository: Click the Default button connected to
                                the repo/channel if `True`
    """
    assert service in service_types, "Unknown service type '{}'".format(service)
    service_value = service_types[service]

    sel.force_navigate("cfg_settings_region_red_hat_updates")
    sel.click(update_buttons.edit_registration)
    details = dict(
        service=sel.ByValue(service_value),
        url=url,
        username=username,
        password=password,
        repo_name=repo_name,
        organization=organization,
        use_proxy=use_proxy,
        proxy_url=proxy_url,
        proxy_username=proxy_username,
        proxy_password=proxy_password
    )

    fill(registration_form, details)

    if set_default_rhsm_address:
        sel.click(registration_buttons.url_default)

    if set_default_repository:
        sel.click(registration_buttons.repo_default)

    if validate:
        sel.click(registration_buttons.validate)
        flash.assert_no_errors()
        flash.dismiss()

    if cancel:
        form_buttons.cancel()
    else:
        form_buttons.save()
        flash.assert_message_match("Customer Information successfully saved")
        flash.dismiss()
Example #28
0
 def update(self, updates):
     sel.force_navigate("service_dialog_edit", context={"dialog": self})
     fill(label_form, {"name_text": updates.get("name", None), "description_text": updates.get("description", None)})
     form_buttons.save()
     flash.assert_no_errors()
def update_registration(service,
                        url,
                        username,
                        password,
                        repo_name=None,
                        organization=None,
                        use_proxy=False,
                        proxy_url=None,
                        proxy_username=None,
                        proxy_password=None,
                        validate=False,
                        cancel=False,
                        set_default_rhsm_address=False,
                        set_default_repository=False):
    """ Fill in the registration form, validate and save/cancel

    Args:
        service: Service type (registration method).
        url: Service server URL address.
        username: Username to use for registration.
        password: Password to use for registration.
        repo_or_channel: Repository/channel to enable.
        organization: Organization (sat5/sat6 only).
        use_proxy: `True` if proxy should be used, `False` otherwise
                   (default `False`).
        proxy_url: Address of the proxy server.
        proxy_username: Username for the proxy server.
        proxy_password: Password for the proxy server.
        validate: Click the Validate button and check the
                  flash message for errors if `True` (default `False`)
        cancel: Click the Cancel button if `True` or the Save button
                if `False` (default `False`)
        set_default_rhsm_address: Click the Default button connected to
                                  the RHSM (only) address if `True`
        set_default_repository: Click the Default button connected to
                                the repo/channel if `True`
    """
    assert service in service_types, "Unknown service type '{}'".format(
        service)
    service_value = service_types[service]

    sel.force_navigate("cfg_settings_region_red_hat_updates")
    sel.click(update_buttons.edit_registration)
    details = dict(service=sel.ByValue(service_value),
                   url=url,
                   username=username,
                   password=password,
                   repo_name=repo_name,
                   organization=organization,
                   use_proxy=use_proxy,
                   proxy_url=proxy_url,
                   proxy_username=proxy_username,
                   proxy_password=proxy_password)

    fill(registration_form, details)

    if set_default_rhsm_address:
        sel.click(registration_buttons.url_default)

    if set_default_repository:
        sel.click(registration_buttons.repo_default)

    if validate:
        sel.click(registration_buttons.validate)
        flash.assert_no_errors()
        flash.dismiss()

    if cancel:
        form_buttons.cancel()
    else:
        form_buttons.save()
        flash.assert_message_match("Customer Information successfully saved")
        flash.dismiss()
def update_registration(service,
                        url,
                        username,
                        password,
                        password_verify=None,
                        repo_name=None,
                        organization=None,
                        use_proxy=False,
                        proxy_url=None,
                        proxy_username=None,
                        proxy_password=None,
                        proxy_password_verify=None,
                        validate=True,
                        cancel=False,
                        set_default_rhsm_address=False,
                        set_default_repository=False):
    """ Fill in the registration form, validate and save/cancel

    Args:
        service: Service type (registration method).
        url: Service server URL address.
        username: Username to use for registration.
        password: Password to use for registration.
        password_verify: 2nd entry of password for verification.
                         Same as 'password' if None.
        repo_or_channel: Repository/channel to enable.
        organization: Organization (sat6 only).
        use_proxy: `True` if proxy should be used, `False` otherwise
                   (default `False`).
        proxy_url: Address of the proxy server.
        proxy_username: Username for the proxy server.
        proxy_password: Password for the proxy server.
        proxy_password_verify: 2nd entry of proxy server password for verification.
                               Same as 'proxy_password' if None.
        validate: Click the Validate button and check the
                  flash message for errors if `True` (default `True`)
        cancel: Click the Cancel button if `True` or the Save button
                if `False` (default `False`)
        set_default_rhsm_address: Click the Default button connected to
                                  the RHSM (only) address if `True`
        set_default_repository: Click the Default button connected to
                                the repo/channel if `True`

    Warning:
        'password_verify' and 'proxy_password_verify' are available in 5.4+ only.

    Note:
        With satellite 6, it is necessary to validate credentials to obtain
        available organizations from the server.
        With satellite 5, 'validate' parameter is ignored because there is
        no validation button available.
    """
    assert service in service_types, "Unknown service type '{}'".format(service)
    service_value = service_types[service]

    # In 5.4+, we have verification inputs as well
    if version.current_version() >= '5.4':
        password_verify = password_verify or password
        proxy_password_verify = proxy_password_verify or proxy_password
    # Otherwise, verification inputs are ignored df even if specified
    else:
        password_verify = None
        proxy_password_verify = None

    view = navigate_to(current_appliance.server.zone.region, 'RedHatUpdatesEdit')

    details = dict(
        register_to=service_value,
        url=url,
        username=username,
        password=password,
        password_verify=password_verify,
        repo_name=repo_name,
        use_proxy=use_proxy,
        proxy_url=proxy_url,
        proxy_username=proxy_username,
        proxy_password=proxy_password,
        proxy_password_verify=proxy_password_verify
    )

    view.fill(details)

    if set_default_rhsm_address:
        view.rhn_default_url.click()

    if set_default_repository:
        view.repo_default_name.click()

    view.validate.click()

    if cancel:
        form_buttons.cancel()
    else:
        form_buttons.save()
        main_view = current_appliance.server.create_view(RedHatUpdatesView)
        success_text = 'Customer Information successfully saved'
        main_view.flash.assert_message(success_text)