How to use the pook.engine.Engine function in pook

To help you get started, we’ve selected a few pook examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github h2non / pook / pook / api.py View on Github external
with pook.use() as engine:
            pook.mock('server.com/foo').reply(404)

            res = requests.get('server.com/foo')
            assert res.status_code == 404
    """
    global _engine

    # Create temporal engine
    __engine = _engine
    activated = __engine.active
    if activated:
        __engine.disable()

    _engine = Engine(network=network)
    _engine.activate()

    # Yield enfine to be used by the context manager
    yield _engine

    # Restore engine state
    _engine.disable()
    if network:
        _engine.disable_network()

    # Restore previous engine
    _engine = __engine
    if activated:
        _engine.activate()
github h2non / pook / pook / api.py View on Github external
activate_async = None

# Public API symbols to export
__all__ = (
    'activate', 'on', 'disable', 'off', 'reset', 'engine',
    'use_network', 'enable_network', 'disable_network',
    'get', 'post', 'put', 'patch', 'head', 'use',
    'set_mock_engine', 'delete', 'options', 'pending',
    'ispending', 'mock', 'pending_mocks', 'unmatched_requests',
    'isunmatched', 'unmatched', 'isactive', 'isdone', 'regex',
    'Engine', 'Mock', 'Request', 'Response',
    'MatcherEngine', 'MockEngine', 'use_network_filter'
)

# Default singleton mock engine to be used
_engine = Engine()


def debug(enable=True):
    """
    Enables or disables debug mode in the current mock engine.

    Arguments:
        enable (bool): ``True`` to enable debug mode. Otherwise ``False``.
    """
    _engine.debug = enable


def engine():
    """
    Returns the current running mock engine.
github h2non / pook / pook / engine.py View on Github external
def reset(self):
        """
        Resets and flushes engine state and mocks to defaults.
        """
        # Reset engine
        Engine.__init__(self, network=self.networking)