Exemple #1
0
def browse(entity, browser, host):
    """Opens a page in defined browser for interaction:\n
    All parameters defaults to what is in robottelo.properties file.\n
        example: $ manage ui browse activationkey\n
                 Opens a browser in ActivationKey scope and gives you
                 interactive shell to play with the page\n
    """
    settings.configure()
    if host:
        settings.server.hostname = host
    current_browser = _get_browser(browser)
    with Session(current_browser) as session:  # noqa

        ui_crud = _import_ui_crud()
        # Make all UI CRUD entities available in a dict
        # each entity initialized with current_browser instance
        ui_entities = {name.lower(): crud_class(current_browser) for name, crud_class in ui_crud.items()}
        if entity:
            # if entity name specified navigate to the page
            # example: manage ui browse user
            ui_entities[entity.lower()].navigate_to_entity()

        # gets all functions from ui.factory module which starts with 'make_'
        ui_factory_members = getmembers(ui_factory, lambda i: callable(i) and i.__name__.startswith("make"))
        # Usually we need to pass the `session` as 1st argument
        # e.g `make_user(session, username='******')`
        # using `partial` we make session the default 1st argument
        # it allows the use as: `make_user(username='******')
        # and `session` is implicit there.
        ui_factory_functions = {name: partial(function, session=session) for name, function in ui_factory_members}

        # now we "inject" the factories and entities under `session.ui`
        session.ui = Storage(ui_entities, ui_factory_functions)

        # The same for nailgun.entities.* under `session.api`
        session.api = Storage(dict(getmembers(entities)))

        def close():
            """Hook to close the session and browser atexit it also flushes
            the session history content to the specified file
            """
            session.close()
            # FIXME: if --out=/path/to/file should save session history
            # see ipython.readthedocs.io/en/stable/config/options/terminal.html

        extra_vars = {
            "session": session,
            "browser": current_browser,
            "current_browser": current_browser,
            "host": settings.server.hostname,
            "api_factory": entities,
            "ui_factory": ui_factory,
        }

        create_shell("ipython", extra_vars=extra_vars, exit_hooks=[close])
Exemple #2
0
def browse(entity, browser, host):
    """Opens a page in defined browser for interaction:\n
    All parameters defaults to what is in robottelo.properties file.\n
        example: $ manage ui browse activationkey\n
                 Opens a browser in ActivationKey scope and gives you
                 interactive shell to play with the page\n
    """
    settings.configure()
    if host:
        settings.server.hostname = host
    current_browser = _get_browser(browser)
    with Session(current_browser) as session:  # noqa

        ui_crud = _import_ui_crud()
        # Make all UI CRUD entities available in a dict
        # each entity initialized with current_browser instance
        ui_entities = {
            name.lower(): crud_class(current_browser)
            for name, crud_class in ui_crud.items()
        }
        if entity:
            # if entity name specified navigate to the page
            # example: manage ui browse user
            ui_entities[entity.lower()].navigate_to_entity()

        # gets all functions from ui.factory module which starts with 'make_'
        ui_factory_members = getmembers(
            ui_factory,
            lambda i: callable(i) and i.__name__.startswith('make'))
        # Usually we need to pass the `session` as 1st argument
        # e.g `make_user(session, username='******')`
        # using `partial` we make session the default 1st argument
        # it allows the use as: `make_user(username='******')
        # and `session` is implicit there.
        ui_factory_functions = {
            name: partial(function, session=session)
            for name, function in ui_factory_members
        }

        # now we "inject" the factories and entities under `session.ui`
        session.ui = Storage(ui_entities, ui_factory_functions)

        # The same for nailgun.entities.* under `session.api`
        session.api = Storage(dict(getmembers(entities)))

        def close():
            """Hook to close the session and browser atexit it also flushes
            the session history content to the specified file
            """
            session.close()
            # FIXME: if --out=/path/to/file should save session history
            # see ipython.readthedocs.io/en/stable/config/options/terminal.html

        extra_vars = {
            'session': session,
            'browser': current_browser,
            'current_browser': current_browser,
            'host': settings.server.hostname,
            'api_factory': entities,
            'ui_factory': ui_factory
        }

        create_shell('ipython', extra_vars=extra_vars, exit_hooks=[close])
Exemple #3
0
def shell(console):
    """Runs a Python shell with Flaskpress context"""
    context = {'app': app, 'db': db}
    return create_shell(console, extra_vars=context)
Exemple #4
0
def shell(console):
    """Runs a Python shell with Quokka context"""
    context = {'app': app, 'db': db}
    return create_shell(console, extra_vars=context)