mocking - Mock flask.request in python nosetests -
i'm writing test cases code called via route under flask. don't want test code setting test app , calling url hits route, want call function directly. make work need mock flask.request , can't seem manage it. google / stackoverflow searches lead lot of answers show how set test application again not want do.
the code list this.
somefile.py ----------- flask import request def method_called_from_route(): data = request.values # data here test_somefile.py ---------------- import unittest import somefile class somefiletestcase(unittest.testcase): @patch('somefile.request') def test_method_called_from_route(self, mock_request): # want mock request.values here
i'm having 2 issues.
(1) patching request i've sketched out above not work. error similar "attributeerror: 'blueprint' object has no attribute 'somefile'"
(2) don't know how mock request object if patch it. doesn't have return_value since isn't function.
again can't find examples on how felt new question acceptable.
what you're trying counterproductive. following rfc 2616 request is:
a request message client server includes, within first line of message, method applied resource, identifier of resource, , protocol version in use.
mocking flask request need rebuild structure, certainly, not want do!
the best approach should use flask-testing or use recipes this, , then, test method.
Comments
Post a Comment