mercredi 14 novembre 2018

Test of calling webservice from Flask application

What's the best practice for writing tests for a Flask (Restful) application which calls a second web service when posting data to a given URI? Imagine that I have the following method in my Flask app:

class PredictStuff(Resource):
    @use_args(post_args) # Using webargs to validate the posted arguments.
    def post(self, arg):
        my_data = my_func(arg)

        prediction = requests.post('URI_to_other_webservice', json=my_data)

        return prediction.json()

Should my test just worry about testing that my_func is behaving properly? Otherwise, what is the best way to test calling another webservice? I have heard the library Mock, but not sure if that applies to this case.

I am using pytest for my testing.

Aucun commentaire:

Enregistrer un commentaire