Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
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.
def reset(self):
"""
Resets and flushes engine state and mocks to defaults.
"""
# Reset engine
Engine.__init__(self, network=self.networking)