I am building a rest api and I was making the routes for the api and stumbled upon a problem. I am using flask restplus to build the api and marshmallow to validate the json sent by the client.
My design: I use a decorator that is used to wrap every api route. this decorator validates the json sent by the client against a marshmallow schema and if the json validates, then the decorator lets the api route run. Otherwise, if the json invalidates when it's checked against the schema, it returns the errors that it got when it invalidated the json back to the client without running the route.
I really like this design as it significantly reduces code repetition and it can automatically validate and invalidate the data posted by the client without me doing pretty much the same thing in each api route -- checking the json sent by the client and then running the route.
My only issue is that I have no clue how to unit test this. I have written tests for the specific marshmallow json schemas to check if they raise the correct validation errors when invalid data is passed to them. However, now I need to test the api routes to check if they return the validation errors raised by the schemas. This seems like a lot of repetition of unit tests because I'm checking for the same errors when testing the schemas and again when I'm testing the api routes/decorator.
Therefore, do you guys have any recommendation of how I should unit test this. Should I test the api routes specifically, the decorator separately, and the schemas separately? Or should I test just the api routes to check they return the correct errors that the schemas raise?
Thanks in advance.