mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
API, batch: test errored calls
This commit is contained in:
@@ -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 )
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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 );
|
||||
|
||||
/*
|
||||
*/
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user