API, tests: add datasets API tests in test/API and casperjs sections; Browser tests: add datasets api, allow api to send extra params for history show & index

This commit is contained in:
Carl Eberhard
2015-02-03 16:11:10 -05:00
parent f09fa5ec17
commit 14383c0868
3 changed files with 176 additions and 13 deletions
+41
View File
@@ -0,0 +1,41 @@
import textwrap
from base import api
from .helpers import TestsDatasets
class DatasetsApiTestCase( api.ApiTestCase, TestsDatasets ):
def setUp( self ):
super( DatasetsApiTestCase, self ).setUp()
self.history_id = self._new_history()
def test_index( self ):
index_response = self._get( "datasets" )
print index_response
print dir( index_response )
self._assert_status_code_is( index_response, 501 )
def test_show( self ):
hda1 = self._new_dataset( self.history_id )
show_response = self._get( "datasets/%s" % ( hda1[ "id" ] ) )
self._assert_status_code_is( show_response, 200 )
self.__assert_matches_hda( hda1, show_response.json() )
def __assert_matches_hda( self, input_hda, query_hda ):
self._assert_has_keys( query_hda, "id", "name" )
assert input_hda[ "name" ] == query_hda[ "name" ]
assert input_hda[ "id" ] == query_hda[ "id" ]
def test_display( self ):
contents = textwrap.dedent( """\
1 2 3 4
A B C D
10 20 30 40
""" )
hda1 = self._new_dataset( self.history_id, content=contents )
display_response = self._get( "histories/%s/contents/%s/display" % ( self.history_id, hda1[ "id" ] ), {
'raw' : 'True'
})
self._assert_status_code_is( display_response, 200 )
#TODO: doesn't work
#assert display_response.text == contents
+59
View File
@@ -0,0 +1,59 @@
var require = patchRequire( require ),
spaceghost = require( 'spaceghost' ).fromCasper( casper ),
xpath = require( 'casper' ).selectXPath,
utils = require( 'utils' ),
format = utils.format;
spaceghost.test.begin( 'Test the HDA API', 0, function suite( test ){
spaceghost.start();
// =================================================================== SET UP
var email = spaceghost.user.getRandomEmail(),
password = '123456';
if( spaceghost.fixtureData.testUser ){
email = spaceghost.fixtureData.testUser.email;
password = spaceghost.fixtureData.testUser.password;
}
var detailKeys = [
// the following are always present regardless of datatype
'id', 'name', 'api_type', 'model_class',
'history_id', 'hid',
'accessible', 'deleted', 'visible', 'purged',
'state', 'data_type', 'file_ext', 'file_size',
'misc_info', 'misc_blurb',
'download_url', 'visualizations', 'display_apps', 'display_types',
'genome_build'
];
spaceghost.user.loginOrRegisterUser( email, password );
spaceghost.openHomePage();
spaceghost.api.tools.thenUploadToCurrent({ filepath: '../../test-data/1.bed' });
spaceghost.then( function(){
// ------------------------------------------------------------------------------------------- INDEX
this.test.comment( 'index should error with not implemented' );
this.api.assertRaises( function(){
this.api.datasets.index();
}, 501, 'not implemented', 'throws unimplemented' );
// ------------------------------------------------------------------------------------------- SHOW
this.test.comment( 'show should get an HDA details object' );
var history = this.api.histories.show( 'most_recently_used', { keys : 'id,hdas' } ),
hdaId = history.hdas[0],
show = this.api.datasets.show( hdaId );
this.debug( this.jsonStr( history ) );
this.debug( this.jsonStr( show ) );
this.test.assert( this.hasKeys( show, detailKeys ), 'Has the proper keys' );
// ------------------------------------------------------------------------------------------- DISPLAY
this.test.comment( 'show should get an HDA details object' );
var fileContents = this.api.datasets.display( history.id, hdaId, { raw: 'True' });
this.test.assert( fileContents.split( '\n' ).length === 66, '1.bed has 66 lines' );
});
// ===================================================================
spaceghost.run( function(){ test.done(); });
});
+76 -13
View File
@@ -13,6 +13,7 @@ var API = function API( spaceghost, apikey ){
this.configuration = new ConfigurationAPI( this );
this.histories = new HistoriesAPI( this );
this.hdas = new HDAAPI( this );
this.datasets = new DatasetsAPI( this );
this.tools = new ToolsAPI( this );
this.workflows = new WorkflowsAPI( this );
this.users = new UsersAPI( this );
@@ -80,7 +81,10 @@ API.prototype._ajax = function _ajax( url, options ){
( resp.responseJSON? this.spaceghost.jsonStr( resp.responseJSON ) : resp.responseText ) );
throw new APIError( resp.responseText, resp.status );
}
return JSON.parse( resp.responseText );
if( options.dataType === undefined || options.dataType === 'json' ){
return JSON.parse( resp.responseText );
}
return resp.responseText;
};
// =================================================================== TESTING
@@ -217,22 +221,34 @@ HistoriesAPI.prototype.urlTpls = {
update : '/api/histories/%s',
};
HistoriesAPI.prototype.index = function index( deleted ){
this.api.spaceghost.info( 'histories.index: ' + (( deleted )?( 'w deleted' ):( '(wo deleted)' )) );
deleted = deleted || false;
HistoriesAPI.prototype.index = function index( params ){
var spaceghost = this.api.spaceghost;
spaceghost.info( 'histories.index:\n' + spaceghost.jsonStr( params ) );
if( params === undefined ){
params = { deleted: false };
}
if( params.deleted === undefined ){
params.deleted = false;
}
spaceghost.debug( 'params (now):' + spaceghost.jsonStr( params ) );
return this.api._ajax( this.urlTpls.index, {
data : { deleted: deleted }
data : params
});
};
HistoriesAPI.prototype.show = function show( id, deleted ){
this.api.spaceghost.info( 'histories.show: ' + [ id, (( deleted )?( 'w deleted' ):( '' )) ] );
id = ( id === 'most_recently_used' || id === 'current' )?( id ):( this.api.ensureId( id ) );
deleted = deleted || false;
HistoriesAPI.prototype.show = function show( id, params ){
var spaceghost = this.api.spaceghost;
this.api.spaceghost.info( 'histories.show: ' + id + '\n' + spaceghost.jsonStr( params ) );
id = ( id === 'most_recently_used' )?( id ):( this.api.ensureId( id ) );
if( params === undefined ){
params = { deleted: false };
}
if( params.deleted === undefined ){
params.deleted = false;
}
spaceghost.debug( 'params (now):' + spaceghost.jsonStr( params ) );
return this.api._ajax( utils.format( this.urlTpls.show, id ), {
data : { deleted: deleted }
data : params
});
};
@@ -365,8 +381,55 @@ HDAAPI.prototype.delete_ = function create( historyId, id, purge ){
//TODO: delete_
// =================================================================== HDAS
var DatasetsAPI = function DatasetsAPI( api ){
this.api = api;
};
DatasetsAPI.prototype.toString = function toString(){
return this.api + '.DatasetsAPI';
};
// -------------------------------------------------------------------
DatasetsAPI.prototype.urlTpls = {
index : '/api/datasets',
show : '/api/datasets/%s',
// wut.
display : '/api/histories/%s/contents/%s/display'
};
DatasetsAPI.prototype.index = function index(){
this.api.spaceghost.info( 'datasets.index: ' );
var data = {};
return this.api._ajax( utils.format( this.urlTpls.index ), {
data : data
});
};
DatasetsAPI.prototype.show = function show( id ){
this.api.spaceghost.info( 'datasets.show: ' + [ id ] );
var data = {};
return this.api._ajax( utils.format( this.urlTpls.show, id ), {
data : data
});
};
DatasetsAPI.prototype.display = function show( historyId, id, params ){
this.api.spaceghost.info( 'datasets.display: ' + [ historyId, id ] );
if( params === undefined ){
params = {};
}
return this.api._ajax( utils.format( this.urlTpls.display, this.api.ensureId( historyId ), id ), {
data : params,
dataType : 'text'
});
};
// =================================================================== TOOLS
var ToolsAPI = function HDAAPI( api ){
var ToolsAPI = function ToolsAPI( api ){
this.api = api;
};
ToolsAPI.prototype.toString = function toString(){