Skip to content

Commit

Permalink
API, batch: test errored calls
Browse files Browse the repository at this point in the history
  • Loading branch information
carlfeberhard committed Apr 22, 2015
1 parent 09bcb74 commit 8fb10a5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/web/framework/middleware/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _proccess_batch_request( self, request, environ, start_response ):

# 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 )
Expand Down
20 changes: 18 additions & 2 deletions test/api/test_api_batch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import simplejson
from requests import post
import pprint

from base import api
# from .helpers import DatasetPopulator
Expand All @@ -20,6 +21,9 @@ def _post_batch( self, batch ):
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' ) ),
Expand All @@ -29,7 +33,7 @@ def test_simple_array( self ):
]
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 )

Expand All @@ -39,6 +43,18 @@ def test_bad_route( self ):
]
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 )
16 changes: 14 additions & 2 deletions test/casperjs/api-batch-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

/*
*/
});
Expand Down

0 comments on commit 8fb10a5

Please sign in to comment.