Archive for category Python
Integration testing with the help of CherryPy
The time for integration testing for a system I wrote arrived (let’s call it system A). In essence, It is a backend system which performs a series of operations (steps) and if all went well, the last two steps are deployment of files to a server and then notifying a system (system B) on the server to refresh its state by reading the new files.
The notification is performed by an HTTP call. Btw, the HTTP interface for system B is the one from here.
In order to test the system A end to end I needed it to perform all the steps, including the notification to system B. To achieve that, a running system B should be present, however, it is quite an over-kill to run system B just for testing and then checking that the call was received.
The simple solution for that is just to run a mockup of system B that has the same HTTP interface.
Naturally I thought about putting an ASP.NET mockup as I am a .net guy. This however requires configuring IIS, playing with the web.config file and of course there is the problem of the url which I can’t simply control…
In order to avoid this whole overhead I went and wrote a simple mock up using CherryPy and Python (Ruby’s Sinatra would be an even better fit however I am little more familiar with Python).
It took only 8 line of code (not including blank lines) to implement this:
import cherrypy
cherrypy.config.update({'server.socket_host': '0.0.0.0','server.socket_port': 50002,})
class Root:
def ReferencesUpdate(self):
cherrypy.response.headers['Content-Type']='text/xml'
return "<ServerResponse><Success>True</Success></ServerResponse>"
ReferencesUpdate.exposed = True
cherrypy.quickstart(Root())
And that’s it! I have a web server up and running!
