I have a decorator that needs a test similar to this:
# code.py
from flask import request, current_app
def some_decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if current_app.config['ENVIRONMENT'] == 'test':
pass
if request.method == 'POST':
pass
return f(*args, **kwargs)
return decorated_function
With test:
import mock
@mock.patch('flask.request')
def test_some_decorator(mock_req):
mock_req.method = 'POST'
function = lambda x: x
decorated_function = some_decorator(function)
function(1)
Now the thing is, the mocked request.method
value does not get overridden with 'POST'
mocked value but instead ends up with 'GET'
which I think is a default one.
Is there something I'm doing wrong?