Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python :unit test throws <Response streamed [200 OK]> instead of actual output

from flask import jsonify

@app.route('/urlinfo/1/<path:URL>', methods=['GET']) 
def search(URL): 
  if something:
     a=dict(message="everything is good"
     resp=jsonify(a)
     return resp
  else:
     a=dict(error="problem")
     return jsonify(a)

I am curling it using

 curl  http://127.0.0.1:5000/urlinfo/1/'https://www.youtube.com/'

and it is returning desired output in json format.

I wrote a Unittest for it

 import unittest

 def test_search_non_malicious_url(self):
    #pass safe URL and test web service does not block it
    new_URL= "183.434.44.44:90"
    expected= {
                  "message": "Everything is good"
             }    
    self.assertEqual("a",search(new_URL))

Unittest fails because instead of returning string ("message": "Everything is good"), search(new_URL) returns Response streamed [200 OK]

How to return output as a dictionary {"message": "Everything is good"}?

like image 354
guri Avatar asked Nov 19 '16 02:11

guri


1 Answers

Figured it out. I had to add .data to get the value:

self.assertEqual("a",search(new_URL).data)
like image 80
guri Avatar answered Sep 18 '22 20:09

guri