Group Testing Client-Server Interaction in Twisted
In my last Python project using Twisted I tried to use the unittest module. At a high level, I am creating two RESTful APIs designed specifically to communicate with each other. For most requests, I can just use DummyRequest and test the displayed values with the expected constant and work fine.
However, I have a few cases where a design requires a request on one server, which (among other things) sends a request to another server, but doesn't really care about the response. What matters is what the request happens.
As I said, I can perfectly test this functionality from the other side, but I cannot figure out how to check that the data is sent. My ideas so far are
- Set up a dummy test server that simply checks to see if the request was made and validates the input. It seems to be bad and too much effort.
- Set up a decorator to wrap certain tests and modify urllib.urlopen to tell when it was called what we were trying to fetch and let me just return a known result there.
I lean towards the second option as it seems more pythonic, but also a little hacky.
source to share
I don't know much about Twisted or how you set up your system for testing, but can you run two servers on the same thread? One of them will be the one you are testing and the other will be just a dummy that can accept any request. In addition to this, the dummy will store the information that he received a call. After starting an operation on the first server that calls the second, you can argue that the second received the request.
source to share