python - Mocking Django's RequestContext class -
i trying mock django's requestcontext class return key piece of data tests:
here implementation:
from django.template import requestcontext
def oauth(request, provider): response = httpresponse() print(requestcontext(request)) --->>> prints out magic mock site_name = requestcontext(request)['site_name']
here test:
@patch('core.views.authomatic') @patch('core.views.requestcontext') def test_new_user_redirects_to_sign_up_page( # noqa self, mockauthomatic, mockrequestcontext): mockrequestcontext.return_value = {'site_name': 'jacaranda'} print(mockrequestcontext()) --->>>> prints out dict
my view prints out magicmock instance, doing wrong.
go for
@patch('core.views.requestcontext') @patch('core.views.authomatic') def test_new_user_redirects_to_sign_up_page( # noqa self, mockauthomatic, mockrequestcontext):
the order of patches should reversed
Comments
Post a Comment