From 8fb10a5c9a5316552ed3f8f83ecc58592f44b052 Mon Sep 17 00:00:00 2001 From: Carl Eberhard Date: Wed, 22 Apr 2015 17:45:36 -0400 Subject: [PATCH] API, batch: test errored calls --- lib/galaxy/web/framework/middleware/batch.py | 2 +- test/api/test_api_batch.py | 20 ++++++++++++++++++-- test/casperjs/api-batch-tests.js | 16 ++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/web/framework/middleware/batch.py b/lib/galaxy/web/framework/middleware/batch.py index bee0aba0805..2811719671e 100644 --- a/lib/galaxy/web/framework/middleware/batch.py +++ b/lib/galaxy/web/framework/middleware/batch.py @@ -103,7 +103,7 @@ class BatchMiddleware(object): # We have to re-create the handle request method here in order to bypass reusing the 'api/batch' request # because reuse will cause the paste error: - # File "/Users/carleberhard/galaxy/api-v2/eggs/Paste-1.7.5.1-py2.7.egg/paste/httpserver.py", line 166, in wsgi_start_response + # File "./eggs/Paste-1.7.5.1-py2.7.egg/paste/httpserver.py", line 166, in wsgi_start_response # assert 0, "Attempt to set headers a second time w/o an exc_info" try: response = self.galaxy.handle_request( environ, start_response, body_renderer=self.body_renderer ) diff --git a/test/api/test_api_batch.py b/test/api/test_api_batch.py index 5f277dc6ca6..4251880f187 100644 --- a/test/api/test_api_batch.py +++ b/test/api/test_api_batch.py @@ -1,5 +1,6 @@ import simplejson from requests import post +import pprint from base import api # from .helpers import DatasetPopulator @@ -20,6 +21,9 @@ class ApiBatchTestCase( api.ApiTestCase ): data = simplejson.dumps({ "batch" : batch }) return post( "%s/batch" % ( self.galaxy_interactor.api_url ), data=data ) + def log_reponse( self, response ): + log.debug( 'RESPONSE %s\n%s', ( '-' * 40 ), pprint.pformat( response ) ) + def test_simple_array( self ): batch = [ dict( url=self._with_key( '/api/histories' ) ), @@ -29,7 +33,7 @@ class ApiBatchTestCase( api.ApiTestCase ): ] response = self._post_batch( batch ) response = response.json() - # log.debug( 'RESPONSE %s\n%s', ( '-' * 40 ), pprint.pformat( response ) ) + # self.log_reponse( response ) self.assertIsInstance( response, list ) self.assertEquals( len( response ), 3 ) @@ -39,6 +43,18 @@ class ApiBatchTestCase( api.ApiTestCase ): ] response = self._post_batch( batch ) response = response.json() - # log.debug( 'RESPONSE %s\n%s', ( '-' * 40 ), pprint.pformat( response ) ) + # self.log_reponse( response ) self.assertIsInstance( response, list ) self.assertEquals( response[0][ 'status' ], 404 ) + + def test_errors( self ): + batch = [ + dict( url=self._with_key( '/api/histories/abc123' ) ), + dict( url=self._with_key( '/api/users/123' ), method='PUT' ), + ] + response = self._post_batch( batch ) + response = response.json() + # self.log_reponse( response ) + self.assertIsInstance( response, list ) + self.assertEquals( response[0][ 'status' ], 400 ) + self.assertEquals( response[1][ 'status' ], 501 ) diff --git a/test/casperjs/api-batch-tests.js b/test/casperjs/api-batch-tests.js index 5bf77d39bbf..30d861108de 100644 --- a/test/casperjs/api-batch-tests.js +++ b/test/casperjs/api-batch-tests.js @@ -51,15 +51,27 @@ spaceghost.test.begin( 'Test the API batch system', 0, function suite( test ){ this.test.comment( 'API batching should handle bad routes well' ); responses = apiBatch([ - { url : '/api/bler' } + { url : '/api/bler' }, ]); // this.debug( 'responses:' + this.jsonStr( responses ) ); - this.test.assert( responses.length === 1, 'Has one response' ); + this.test.assert( responses.length === 1 ); var badRouteResponse = responses[0]; this.test.assert( badRouteResponse.status === 404 ); this.test.assert( utils.isObject( badRouteResponse.body ) && this.countKeys( badRouteResponse.body ) === 0 ); + this.test.comment( 'API batching should handle errors well' ); + responses = apiBatch([ + { url : '/api/histories/abc123' }, + { url : '/api/users/123', method: 'PUT' } + ]); + // this.debug( 'responses:' + this.jsonStr( responses ) ); + this.test.assert( responses.length === 2 ); + var badIdResponse = responses[0], + notImplemented = responses[1]; + this.test.assert( badIdResponse.status === 400 ); + this.test.assert( notImplemented.status === 501 ); + /* */ });