I'm building a Python app that accesses a 3rd party SOAP API with Python-zeep. I want to implement some unit-tests using mocked responses as I don't always have a live server to run my tests against.
I'm new to unit-testing and not quite sure where to start. I've seen examples of using mock with the requests library, but not really sure how to translate this into Zeep.
On one of my Models I have a method to get all DevicePools from a SOAP API. Here's an excerpt of the relevant code (I use a helper method to provide the service object as I plan on using this in many other methods).
# Get Zeep Service Object to make AXL API calls
service = get_axl_client(self)
# Get list of all DevicePools present in the cluster
resp = service.listDevicePool(searchCriteria={'name': '%'},
returnedTags={'name': '', 'uuid': ''})
I want to mock the resp object, however this is of type zeep.objects.ListDevicePoolRes (a dynamic type based on the parsing of the WSDL) and I can't just instantiate an object with static values.
Maybe I'm on the wrong track here and would have to go a bit deeper and actually mock some internals of the zeep library and replace the requests response before zeep parses the XML?
If someone had an example of something similar it would be greatly appreciated.