Reputation: 40321
I'm writing a RESTful API in Python using the restish framework. I would like to write some unit tests (using the unittest package, for example), that will make different requests to my application and validate the results. The unit tests should be able to run as-is, without needing to start a separate web-server process. How do I set up a mock environment using restish to do this?
Thanks
Upvotes: 1
Views: 409
Reputation: 40321
Restish has a built in TestApp class that can be used to test restish apps. Assuming you have a "test" dir in your root restish project callte "restest" created with paster.
import os
import unittest
from paste.fixture import TestApp
class RootTest (unittest.TestCase):
def setUp(self):
self.app = TestApp('config:%s/../development.ini' % os.path.dirname(os.path.abspath(__file__)))
def tearDown(self):
self.app = None
def test_html(self):
res = self.app.get('/')
res.mustcontain('Hello from restest!')
if __name__ == '__main__':
unittest.main()
Upvotes: 1
Reputation: 123568
Since restish is a WSGI framework, you can take advantage of any one of a number of WSGI testing tools:
At least a few of those tools, such as Twill, should be able to test your application without starting a separate web server. (For example, see the "Testing WSGI Apps with Twill" link for more details.)
You might want to ask on the restish forum/list if they have a preferred tool for this type of thing.
Upvotes: 1