When you invoke theĪpplication under test using self.fetch(.), it will send HTTP requests Your application to point at the service layer. Like the services that you depend on by adding endpoints and then configuring Then you add inĪ object and configure it to look The application under test is linked in by implementing the standard get_url ( '/do-stuff' ), method = 'GET' ) recorded = self. setUp () def get_app ( self ): return MyApplication () def test_that_my_service_calls_other_service ( self ): self. service = service_layer # TODO configured your application here using # _for('/add') or super ( MyServiceTests, self ). AsyncHTTPTestCase ): def setUp ( self ): service_layer = services. from tornado import testing from glinda.testing import services class MyServiceTests ( testing. ServiceLayer abstraction that glinda.testing provides. The following snippet tests the application under test using the The nasty side-effect of hiding defects around how content type or headersĪre handled – no HTTP requests means that you have untested assumptions. The AsyncHTTPClient and return fake futures and what not but that has Without having to have a copy of the service running. In this case, the application interacts with with the Here’s an example of testing a Tornado endpoint that asynchronously callsĪnother service. Section 3.1 and proactive content negotiation as described in sections Specifically, it decodes request bodies as described in The ntent package implements content handling as described in All that you have to do is installĮncoding and decoding handlers for expected content types. Method will take care of figuring out the appropriate content type based onĪny included Accept headers. Have to worry about handling malformed messages. Failures are handled by raising a HTTPError(400) so you don’t Will decode the binary body to a string according to the HTTP headers andĬall json.loads to decode the body when you reference the request_body When the client sends a post with a content type of application/json, it register_binary_type ( 'application/msgpack', msgpack. register_text_type ( 'application/json', default_charset = 'utf-8', dumper = json. RequestHandler ): def post ( self, * args, ** kwargs ): body_argument = self. Here’s what it looks like: class MyHandler ( glinda. RequestHandler with a property that is the decoded request body andĪ new method to encode a response. Glinda exposes a content handling mix-in that imbues a standard It willĭecode basic form data, application/x-www-form-urlencoded and Tornado has some internal content decoding accessible by calling the I decided to add that into this library as well. It doesn’t provide a clean way to handle representations transparently so Of handling the nitty gritty HTTP details (e.g., CTE, transfer encodings). Once you can test your application, the next step is to write a well-behavedĪpplication that fits into the WWW nicely. Offer – a way to test non-trivial services. That I tackled and it is the first thing that this library is going to That testing that is not as easy as it should be. Service that is calling other HTTP services asynchronously. I started down the path of developing HTTP endpoints in TornadoĪnd needing to test them. In fact, I want to make it downrightĮnjoyable. Glinda is a companion library for tornado.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |