I have noticed during integration testing that I actually work on recurring use cases with restful APIs (or in general HTTP interfaces) I check here and there with bash+cURL.
It starts looking quite messy and gets harder to maintain. Why deliver mess?
Typical use cases are:
- Check that an URL returns http response code e.g. 200
- Check that content type matches some MIME you need in that case
- Check that returned content matches some pattern, or passes an abstract validation procedure
What I have found so far and consider a workable option without reinventing the wheel, is:
- have a go with PyCurl - in a hope it fully implements all cURL options esp. proxying but also other switches I might need
- use Python's built in unit testng
Then I could have, for example, one unit test per service I'd like to check:
import unittest, pycurl class TestService (unittest.TestCase): def test_1(self): self.assertEqual(pycurl.returncode("some_url"), 200) def test_2(self): self.assertTrue(pycurl.response("some_url").matches ("xxx") ) def test_3(self): self.assertTrue (pycurl.ContentType("some_url").equal("xxx")) if __name__ == '__main__': unittest.main()
Does this make sense or is there a more high-level (but not too complex to pick up and integrate) tooling?