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"}
?
Figured it out. I had to add .data
to get the value:
self.assertEqual("a",search(new_URL).data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With