I am writting unit tests for a flask app. This app expose REST endpoints and uses the flask_restful lib.
Basically, one of my endpoints will do requests to other endpoints and do some processing.
While executing the tests through pytest, it returns this error (NOTE: this works when basically testing with curl) :
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1',
port=5000): Max retries exceeded with url:
/ctrlm/H_INFOEXPLH:05u3v/output/
(Caused by NewConnectionError('<urllib3.connection.HTTPConnection object
at
0x0486D090>: Failed to establish a new connection: [WinError 10061]
Here is the test code :
class RestTests(unittest.TestCase):
""" Test the rest module. """
############################
#### setup and teardown ####
############################
def setUp(self):
""" Executed prior to each test """
app.config['TESTING'] = True
app.config['WTF_CSRF_ENABLED'] = False
app.config['DEBUG'] = False
app.config['THREADED'] = True
self.client = app.test_client()
# incident id:
self.incident = "INC1863137"
# ctrl-m job id :
self.jobid_no_output = "server:0ceit"
self.jobid_no_job = "server:0ceity" # job format that will surely fail!
def tearDown(self):
""" executed after each testexecuted after each test """
pass
###############
#### tests ####
###############
def test_ctrl_output(self):
""" UAT 3 : ctrl-M job output is found. """
response = self.client.post('/servnow/incident/{}'.format(self.incident),
data=json.dumps({'data': "This is just a json test"}),
headers={'Content-Type': 'application/json'}
)
#print("DEBUGGGG!!!!!!!!!!!!!!!!!!! ===============> {}".format(response))
self.assertIsNotNone(response)
Well, maybe the flask instance initiated with setUp() is not able to be threaded...
On the app code, this is this code which create the issue :
url = "http://127.0.0.1:5000{}".format(
flask.url_for('joboutput', jobid=jobid))
resp = requests.get(url).json()
Well, I just would like to execute a query to an url from flask... Probably, I'm doing it the wrong way....
Could you help me, please?
Redirecting...
\nYou should be redirected automatically to target URL: /ctrlm/H_INFOEXPLH:05u3v/output/. If not click the link.'
– stockersky Oct 17 '17 at 16:00