1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/3131a76ddd93/ Changeset: 3131a76ddd93 User: carlfeberhard Date: 2014-12-22 19:58:44+00:00 Summary: merge Affected #: 29 files diff -r 1aa8a57c599455b2a9faeeadb980b62b8abecc1f -r 3131a76ddd932911a80838d83aaf71baf26a3d6f lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -254,6 +254,11 @@ """ Get a History from the database by id, verifying ownership. """ + if trans.user is None and trans.history: + if id == trans.security.encode_id( trans.history.id ): + return trans.history + raise ItemOwnershipException( "Must be logged in to manage Galaxy items", type='error' ) + history = self.get_object( trans, id, 'History', check_ownership=check_ownership, check_accessible=check_accessible, deleted=deleted ) history = self.security_check( trans, history, check_ownership, check_accessible ) diff -r 1aa8a57c599455b2a9faeeadb980b62b8abecc1f -r 3131a76ddd932911a80838d83aaf71baf26a3d6f test/casperjs/anon-history-tests.js --- a/test/casperjs/anon-history-tests.js +++ b/test/casperjs/anon-history-tests.js @@ -7,127 +7,110 @@ spaceghost.test.begin( 'Testing histories for anonymous users', 0, function suite( test ){ spaceghost.start(); -// =================================================================== + // =================================================================== + var email = spaceghost.user.getRandomEmail(), + password = '123456'; + if( spaceghost.fixtureData.testUser ){ + email = spaceghost.fixtureData.testUser.email; + password = spaceghost.fixtureData.testUser.password; + spaceghost.info( 'Will use fixtureData.testUser: ' + email ); + } -var email = spaceghost.user.getRandomEmail(), - password = '123456'; -if( spaceghost.fixtureData.testUser ){ - email = spaceghost.fixtureData.testUser.email; - password = spaceghost.fixtureData.testUser.password; - spaceghost.info( 'Will use fixtureData.testUser: ' + email ); -} + var editableTextClass = spaceghost.data.selectors.editableText, + editableTextInput = spaceghost.data.selectors.editableTextInput, -var tooltipSelector = spaceghost.data.selectors.tooltipBalloon, - editableTextClass = spaceghost.data.selectors.editableText, - editableTextInput = spaceghost.data.selectors.editableTextInput, + unnamedName = spaceghost.historypanel.data.text.history.newName, + nameSelector = spaceghost.historypanel.data.selectors.history.name, + sizeSelector = spaceghost.historypanel.data.selectors.history.size, + initialSizeStr = spaceghost.historypanel.data.text.history.newSize, + tagIconSelector = spaceghost.historypanel.data.selectors.history.tagIcon, + annoIconSelector = spaceghost.historypanel.data.selectors.history.annoIcon, + emptyMsgSelector = spaceghost.historypanel.data.selectors.history.emptyMsg, + emptyMsgStr = spaceghost.historypanel.data.text.history.emptyMsg; - unnamedName = spaceghost.historypanel.data.text.history.newName, - nameSelector = spaceghost.historypanel.data.selectors.history.name, - sizeSelector = spaceghost.historypanel.data.selectors.history.size, - initialSizeStr = spaceghost.historypanel.data.text.history.newSize, - tagIconSelector = spaceghost.historypanel.data.selectors.history.tagIcon, - annoIconSelector = spaceghost.historypanel.data.selectors.history.annoIcon, - emptyMsgSelector = spaceghost.historypanel.data.selectors.history.emptyMsg, - emptyMsgStr = spaceghost.historypanel.data.text.history.emptyMsg, - anonNameTooltip = spaceghost.historypanel.data.text.anonymous.tooltips.name; + var filenameToUpload = '1.txt', + filepathToUpload = '../../test-data/' + filenameToUpload; -var historyFrameInfo = {}, - filenameToUpload = '1.txt', - filepathToUpload = '../../test-data/' + filenameToUpload, - testUploadedId = null, - testUploadInfo = {}; + // ------------------------------------------------------------------- check the anonymous new, history for form + spaceghost.openHomePage().historypanel.waitForHdas( function testPanelStructure(){ + this.test.comment( 'history panel for anonymous user, new history' ); + this.test.comment( "history name should exist, be visible, and have text " + unnamedName ); + this.test.assertExists( nameSelector, nameSelector + ' exists' ); + this.test.assertVisible( nameSelector, 'History name is visible' ); + this.test.assertSelectorHasText( nameSelector, unnamedName, 'History name is ' + unnamedName ); -// =================================================================== TESTS -// ------------------------------------------------------------------- check the anonymous new, history for form -spaceghost.openHomePage().historypanel.waitForHdas( function testPanelStructure(){ - this.test.comment( 'history panel for anonymous user, new history' ); + this.test.comment( "history should display size and size should be 0 bytes" ); + this.test.assertExists( sizeSelector, 'Found ' + sizeSelector ); + this.test.assertVisible( sizeSelector, 'History size is visible' ); + this.test.assertSelectorHasText( sizeSelector, initialSizeStr, + 'History size has "' + initialSizeStr + '"' ); - this.test.comment( "history name should exist, be visible, and have text " + unnamedName ); - this.test.assertExists( nameSelector, nameSelector + ' exists' ); - this.test.assertVisible( nameSelector, 'History name is visible' ); - this.test.assertSelectorHasText( nameSelector, unnamedName, 'History name is ' + unnamedName ); + this.test.comment( "NO tags or annotations icons should be available for an anonymous user" ); + this.test.assertDoesntExist( tagIconSelector, 'Tag icon button not found' ); + this.test.assertDoesntExist( annoIconSelector, 'Annotation icon button not found' ); - this.test.comment( "history should display size and size should be 0 bytes" ); - this.test.assertExists( sizeSelector, 'Found ' + sizeSelector ); - this.test.assertVisible( sizeSelector, 'History size is visible' ); - this.test.assertSelectorHasText( sizeSelector, initialSizeStr, - 'History size has "' + initialSizeStr + '"' ); - - this.test.comment( "NO tags or annotations icons should be available for an anonymous user" ); - this.test.assertDoesntExist( tagIconSelector, 'Tag icon button not found' ); - this.test.assertDoesntExist( annoIconSelector, 'Annotation icon button not found' ); - - this.test.assertExists( emptyMsgSelector, emptyMsgSelector + ' exists' ); - this.test.comment( "A message about the current history being empty should be displayed" ); - this.test.assertVisible( emptyMsgSelector, 'Empty history message is visible' ); - this.test.assertSelectorHasText( emptyMsgSelector, emptyMsgStr, - 'Message contains "' + emptyMsgStr + '"' ); - - this.test.comment( 'name should NOT be editable when clicked by anon-user' ); - this.assertDoesntHaveClass( nameSelector, editableTextClass, "Name field is not classed as editable text" ); - this.click( nameSelector ); - this.test.assertDoesntExist( editableTextInput, "Clicking on name does not create an input" ); -}); - -// ------------------------------------------------------------------- anon user can upload file -spaceghost.then( function testAnonUpload(){ - this.test.comment( 'anon-user should be able to upload files' ); - - var currHistory = spaceghost.api.histories.index()[0]; - spaceghost.api.tools.thenUpload( currHistory.id, { - filepath: filepathToUpload - }, function uploadCallback( uploadedId ){ - testUploadedId = uploadedId; - }); -}); -spaceghost.openHomePage().historypanel.waitForHdas( function testAnonUpload(){ - this.test.comment( 'uploaded files should be well formed in the panel' ); - - var hdaElement = spaceghost.getElementInfo( '#dataset-' + testUploadedId ); - this.debug( 'uploaded HDA info: ' + this.jsonStr( this.quickInfo( hdaElement ) ) ); - - var hasHda = hdaElement, - hasClass = hdaElement.attributes[ 'class' ], - hasOkClass = hdaElement.attributes[ 'class' ].indexOf( 'state-ok' ) !== -1; - this.test.assert( ( hasHda && hasClass && hasOkClass ), "Uploaded file: " + hdaElement.text ); - testUploadInfo = hdaElement; -}); -spaceghost.then( function testAnonUpload(){ - this.test.comment( "empty should be NO LONGER be displayed" ); - this.test.assertNotVisible( emptyMsgSelector, 'Empty history message is not visible' ); -}); - -// ------------------------------------------------------------------- anon user can run tool on file - -// ------------------------------------------------------------------- anon user registers/logs in -> same history -spaceghost.user.loginOrRegisterUser( email, password ).openHomePage( function(){ - this.test.comment( 'anon-user should login and be associated with previous history' ); - - var loggedInAs = spaceghost.user.loggedInAs(); - this.test.assert( loggedInAs === email, 'loggedInAs() matches email: "' + loggedInAs + '"' ); - - this.historypanel.waitForHdas( function(){ - var hdaInfo = this.historypanel.hdaElementInfoByTitle( filenameToUpload ); - this.test.assert( hdaInfo !== null, "After logging in - found a matching hda by name and hid" ); - if( hdaInfo ){ - this.test.assert( testUploadInfo.attributes.id === hdaInfo.attributes.id, - "After logging in - found a matching hda by hda view id: " + hdaInfo.attributes.id ); - } - }); -}); - -// ------------------------------------------------------------------- logs out -> new history -spaceghost.user.logout().openHomePage( function(){ - this.test.comment( 'logging out should create a new, anonymous history' ); - - this.historypanel.waitForHdas( function(){ - this.test.assertSelectorHasText( nameSelector, unnamedName, 'History name is ' + unnamedName ); + this.test.assertExists( emptyMsgSelector, emptyMsgSelector + ' exists' ); + this.test.comment( "A message about the current history being empty should be displayed" ); + this.test.assertVisible( emptyMsgSelector, 'Empty history message is visible' ); this.test.assertSelectorHasText( emptyMsgSelector, emptyMsgStr, 'Message contains "' + emptyMsgStr + '"' ); + + this.test.comment( 'name should NOT be editable when clicked by anon-user' ); + this.assertDoesntHaveClass( nameSelector, editableTextClass, "Name field is not classed as editable text" ); + this.click( nameSelector ); + this.test.assertDoesntExist( editableTextInput, "Clicking on name does not create an input" ); }); -}); -// =================================================================== + // ------------------------------------------------------------------- anon user can upload file + var uploadedId = null; + spaceghost.api.tools.thenUploadToCurrent({ filepath: filepathToUpload }, function( id, json ){ + uploadedId = id; + }); + spaceghost.openHomePage().historypanel.waitForHdas( function testAnonUpload(){ + this.test.comment( 'anon-user should be able to upload files' ); + this.test.assertExists( '#dataset-' + uploadedId, "found hda" ); + var hdaElement = this.elementInfoOrNull( '#dataset-' + uploadedId ); + this.debug( 'hdaElement: ' + hdaElement ); + if( hdaElement ){ + this.test.assert( hdaElement.attributes[ 'class' ].indexOf( 'state-ok' ) !== -1, + "Uploaded file: " + hdaElement.text ); + } + + this.test.comment( "empty should be NO LONGER be displayed" ); + this.test.assertNotVisible( emptyMsgSelector, 'Empty history message is not visible' ); + }); + + // ------------------------------------------------------------------- anon user can run tool on file + + // ------------------------------------------------------------------- anon user registers/logs in -> same history + spaceghost.user.loginOrRegisterUser( email, password ).openHomePage( function(){ + this.test.comment( 'anon-user should login and be associated with previous history' ); + + var loggedInAs = spaceghost.user.loggedInAs(); + this.test.assert( loggedInAs === email, 'loggedInAs() matches email: "' + loggedInAs + '"' ); + + this.historypanel.waitForHdas( function(){ + var hdaInfo = this.historypanel.hdaElementInfoByTitle( filenameToUpload ); + this.test.assert( hdaInfo !== null, "After logging in - found a matching hda by name and hid" ); + if( hdaInfo ){ + this.test.assert( 'dataset-' + uploadedId === hdaInfo.attributes.id, + "After logging in - found a matching hda by hda view id: " + hdaInfo.attributes.id ); + } + }); + }); + + // ------------------------------------------------------------------- logs out -> new history + spaceghost.user.logout().openHomePage( function(){ + this.test.comment( 'logging out should create a new, anonymous history' ); + + this.historypanel.waitForHdas( function(){ + this.test.assertSelectorHasText( nameSelector, unnamedName, 'History name is ' + unnamedName ); + this.test.assertSelectorHasText( emptyMsgSelector, emptyMsgStr, + 'Message contains "' + emptyMsgStr + '"' ); + }); + }); + + // =================================================================== spaceghost.run( function(){ test.done(); }); }); diff -r 1aa8a57c599455b2a9faeeadb980b62b8abecc1f -r 3131a76ddd932911a80838d83aaf71baf26a3d6f test/casperjs/api-anon-history-permission-tests.js --- a/test/casperjs/api-anon-history-permission-tests.js +++ b/test/casperjs/api-anon-history-permission-tests.js @@ -8,195 +8,194 @@ + 'with anonymous users over the 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 inaccessibleHistory, accessibleHistory, publishedHistory, - inaccessibleHdas, accessibleHdas, publishedHdas, - accessibleLink; + // =================================================================== SET UP + var email = spaceghost.user.getRandomEmail(), + password = '123456'; + if( spaceghost.fixtureData.testUser ){ + email = spaceghost.fixtureData.testUser.email; + password = spaceghost.fixtureData.testUser.password; + } + var inaccessibleHistory, accessibleHistory, publishedHistory, + inaccessibleHdas, accessibleHdas, publishedHdas; -//// ------------------------------------------------------------------------------------------- create 3 histories -spaceghost.user.loginOrRegisterUser( email, password ); -spaceghost.thenOpen( spaceghost.baseUrl ).then( function(){ - // create three histories: make the 2nd importable (via the API), and the third published + //// ------------------------------------------------------------------------------------------- create 3 histories + spaceghost.user.loginOrRegisterUser( email, password ); + spaceghost.openHomePage().then( function(){ + // create three histories: make the 2nd importable (via the API), and the third published - // make the current the inaccessible one - inaccessibleHistory = this.api.histories.index()[0]; - this.api.histories.update( inaccessibleHistory.id, { name: 'inaccessible' }); - inaccessibleHistory = this.api.histories.index()[0]; + // make the current the inaccessible one + inaccessibleHistory = this.api.histories.index()[0]; + this.api.histories.update( inaccessibleHistory.id, { name: 'inaccessible' }); + inaccessibleHistory = this.api.histories.index()[0]; - accessibleHistory = this.api.histories.create({ name: 'accessible' }); - var returned = this.api.histories.update( accessibleHistory.id, { - importable : true + accessibleHistory = this.api.histories.create({ name: 'accessible' }); + var returned = this.api.histories.update( accessibleHistory.id, { + importable : true + }); + //this.debug( this.jsonStr( returned ) ); + accessibleHistory = this.api.histories.show( accessibleHistory.id ); + + publishedHistory = this.api.histories.create({ name: 'published' }); + returned = this.api.histories.update( publishedHistory.id, { + published : true + }); + //this.debug( this.jsonStr( returned ) ); + publishedHistory = this.api.histories.show( publishedHistory.id ); + }); - //this.debug( this.jsonStr( returned ) ); - accessibleHistory = this.api.histories.show( accessibleHistory.id ); - publishedHistory = this.api.histories.create({ name: 'published' }); - returned = this.api.histories.update( publishedHistory.id, { - published : true + //// ------------------------------------------------------------------------------------------- upload some files + spaceghost.then( function(){ + this.api.tools.thenUpload( inaccessibleHistory.id, { filepath: '../../test-data/1.bed' }); + this.api.tools.thenUpload( accessibleHistory.id, { filepath: '../../test-data/1.bed' }); + this.api.tools.thenUpload( publishedHistory.id, { filepath: '../../test-data/1.bed' }); }); - //this.debug( this.jsonStr( returned ) ); - publishedHistory = this.api.histories.show( publishedHistory.id ); + spaceghost.then( function(){ + // check that they're there + inaccessibleHdas = this.api.hdas.index( inaccessibleHistory.id ), + accessibleHdas = this.api.hdas.index( accessibleHistory.id ), + publishedHdas = this.api.hdas.index( publishedHistory.id ); + }); + spaceghost.user.logout(); -}); + // =================================================================== TESTS + //// ------------------------------------------------------------------------------------------- anon user + function testAnonReadFunctionsOnAccessible( history, hdas ){ + this.test.comment( '---- testing read/accessibility functions for ACCESSIBLE history: ' + history.name ); -//// ------------------------------------------------------------------------------------------- upload some files -spaceghost.then( function(){ - this.api.tools.thenUpload( inaccessibleHistory.id, { filepath: '../../test-data/1.bed' }); - this.api.tools.thenUpload( accessibleHistory.id, { filepath: '../../test-data/1.bed' }); - this.api.tools.thenUpload( publishedHistory.id, { filepath: '../../test-data/1.bed' }); -}); -spaceghost.then( function(){ - // check that they're there - inaccessibleHdas = this.api.hdas.index( inaccessibleHistory.id ), - accessibleHdas = this.api.hdas.index( accessibleHistory.id ), - publishedHdas = this.api.hdas.index( publishedHistory.id ); -}); -spaceghost.user.logout(); + // read functions for history + this.test.comment( 'show should work for history: ' + history.name ); + this.test.assert( this.api.histories.show( history.id ).id === history.id, + 'show worked' ); + this.test.comment( 'copying should fail for history (multiple histories not allowed): ' + history.name ); + this.api.assertRaises( function(){ + this.api.histories.create({ history_id : history.id }); + }, 403, 'API authentication required for this request', 'update authentication required' ); -// =================================================================== TESTS -//// ------------------------------------------------------------------------------------------- anon user -function testAnonReadFunctionsOnAccessible( history, hdas ){ - this.test.comment( '---- testing read/accessibility functions for ACCESSIBLE history: ' + history.name ); + // read functions for history contents + this.test.comment( 'index of history contents should work for history: ' + history.name ); + this.test.assert( this.api.hdas.index( history.id ).length === 1, + 'hda index worked' ); + this.test.comment( 'showing of history contents should work for history: ' + history.name ); + this.test.assert( this.api.hdas.show( history.id, hdas[0].id ).id === hdas[0].id, + 'hda show worked' ); - // read functions for history - this.test.comment( 'show should work for history: ' + history.name ); - this.test.assert( this.api.histories.show( history.id ).id === history.id, - 'show worked' ); - this.test.comment( 'copying should fail for history (multiple histories not allowed): ' + history.name ); - this.api.assertRaises( function(){ - this.api.histories.create({ history_id : history.id }); - }, 403, 'API authentication required for this request', 'update authentication required' ); - - // read functions for history contents - this.test.comment( 'index of history contents should work for history: ' + history.name ); - this.test.assert( this.api.hdas.index( history.id ).length === 1, - 'hda index worked' ); - this.test.comment( 'showing of history contents should work for history: ' + history.name ); - this.test.assert( this.api.hdas.show( history.id, hdas[0].id ).id === hdas[0].id, - 'hda show worked' ); - - this.test.comment( 'Attempting to copy an accessible hda (default is accessible)' - + ' should work from accessible history: ' + history.name ); - this.api.hdas.create( this.api.histories.index()[0].id, { - source : 'hda', - content : hdas[0].id - }); -} - -function testAnonReadFunctionsOnInaccessible( history, hdas ){ - this.test.comment( '---- testing read/accessibility functions for INACCESSIBLE history: ' + history.name ); - - // read functions for history - this.test.comment( 'show should fail for history: ' + history.name ); - this.api.assertRaises( function(){ - this.api.histories.show( history.id ); - }, 403, 'History is not accessible to the current user', 'show failed with error' ); - this.test.comment( 'copying should fail for history (implicit multiple histories): ' + history.name ); - this.api.assertRaises( function(){ - this.api.histories.create({ history_id : history.id }); - }, 403, 'API authentication required for this request', 'copy failed with error' ); - - // read functions for history contents - this.test.comment( 'index and show of history contents should fail for history: ' + history.name ); - this.api.assertRaises( function(){ - this.api.hdas.index( history.id ); - }, 403, 'History is not accessible to the current user', 'hda index failed with error' ); - this.api.assertRaises( function(){ - this.api.hdas.show( history.id, hdas[0].id ); - }, 403, 'History is not accessible to the current user', 'hda show failed with error' ); - - this.test.comment( 'Attempting to copy an accessible hda (default is accessible)' - + ' from an inaccessible history should fail for: ' + history.name ); - this.api.assertRaises( function(){ - var returned = this.api.hdas.create( this.api.histories.index()[0].id, { + this.test.comment( 'Attempting to copy an accessible hda (default is accessible)' + + ' should work from accessible history: ' + history.name ); + this.api.hdas.create( this.api.histories.index()[0].id, { source : 'hda', content : hdas[0].id }); - this.debug( this.jsonStr( returned ) ); - }, 403, 'History is not accessible to the current user', 'hda copy from failed with error' ); + } -} + function testAnonReadFunctionsOnInaccessible( history, hdas ){ + this.test.comment( '---- testing read/accessibility functions for INACCESSIBLE history: ' + history.name ); -function testAnonWriteFunctions( history, hdas ){ - this.test.comment( '---- testing write/ownership functions for history: ' + history.name ); + // read functions for history + this.test.comment( 'show should fail for history: ' + history.name ); + this.api.assertRaises( function(){ + this.api.histories.show( history.id ); + }, 403, 'History is not accessible to the current user', 'show failed with error' ); + this.test.comment( 'copying should fail for history (implicit multiple histories): ' + history.name ); + this.api.assertRaises( function(){ + this.api.histories.create({ history_id : history.id }); + }, 403, 'API authentication required for this request', 'copy failed with error' ); - this.test.comment( 'update should fail for history: ' + history.name ); - this.api.assertRaises( function(){ - this.api.histories.update( history.id, { deleted: true }); - }, 403, 'API authentication required for this request', 'update authentication required' ); - this.test.comment( 'delete should fail for history: ' + history.name ); - this.api.assertRaises( function(){ - this.api.histories.delete_( history.id ); - }, 403, 'API authentication required for this request', 'delete authentication required' ); + // read functions for history contents + this.test.comment( 'index and show of history contents should fail for history: ' + history.name ); + this.api.assertRaises( function(){ + this.api.hdas.index( history.id ); + }, 403, 'History is not accessible to the current user', 'hda index failed with error' ); + this.api.assertRaises( function(){ + this.api.hdas.show( history.id, hdas[0].id ); + }, 403, 'History is not accessible to the current user', 'hda show failed with error' ); - this.test.comment( 'hda updating should fail for history: ' + history.name ); - this.api.assertRaises( function(){ - this.api.hdas.update( history.id, hdas[0].id, { deleted: true }); - // anon hda update fails w/ this msg if trying to update non-current history hda - }, 403, 'You must be logged in to update this history', 'hda update failed with error' ); - this.test.comment( 'hda deletion should fail for history: ' + history.name ); - this.api.assertRaises( function(){ - this.api.hdas.delete_( history.id, hdas[0].id ); - }, 403, 'API authentication required for this request', 'hda delete failed with error' ); + this.test.comment( 'Attempting to copy an accessible hda (default is accessible)' + + ' from an inaccessible history should fail for: ' + history.name ); + this.api.assertRaises( function(){ + var returned = this.api.hdas.create( this.api.histories.index()[0].id, { + source : 'hda', + content : hdas[0].id + }); + this.debug( this.jsonStr( returned ) ); + }, 403, 'History is not accessible to the current user', 'hda copy from failed with error' ); - this.test.comment( 'copying hda into history should fail for history: ' + history.name ); - this.api.assertRaises( function(){ - this.api.hdas.create( history.id, { - source : 'hda', - // should error before it checks the id - content : 'bler' + } + + function testAnonWriteFunctions( history, hdas ){ + this.test.comment( '---- testing write/ownership functions for history: ' + history.name ); + + this.test.comment( 'update should fail for history: ' + history.name ); + this.api.assertRaises( function(){ + this.api.histories.update( history.id, { deleted: true }); + }, 403, 'API authentication required for this request', 'update authentication required' ); + this.test.comment( 'delete should fail for history: ' + history.name ); + this.api.assertRaises( function(){ + this.api.histories.delete_( history.id ); + }, 403, 'API authentication required for this request', 'delete authentication required' ); + + this.test.comment( 'hda updating should fail for history: ' + history.name ); + this.api.assertRaises( function(){ + this.api.hdas.update( history.id, hdas[0].id, { deleted: true }); + // anon hda update fails w/ this msg if trying to update non-current history hda + }, 403, 'You must be logged in to update this history', 'hda update failed with error' ); + this.test.comment( 'hda deletion should fail for history: ' + history.name ); + this.api.assertRaises( function(){ + this.api.hdas.delete_( history.id, hdas[0].id ); + }, 403, 'API authentication required for this request', 'hda delete failed with error' ); + + this.test.comment( 'copying hda into history should fail for history: ' + history.name ); + this.api.assertRaises( function(){ + this.api.hdas.create( history.id, { + source : 'hda', + // should error before it checks the id + content : 'bler' + }); + }, 403, 'Must be logged in to manage Galaxy histories', 'hda copy to failed' ); + } + + function testAnonInaccessible( history, hdas ){ + testAnonReadFunctionsOnInaccessible.call( this, history, hdas ); + testAnonWriteFunctions.call( this, history, hdas ); + } + + function testAnonAccessible( history, hdas ){ + testAnonReadFunctionsOnAccessible.call( this, history, hdas ); + testAnonWriteFunctions.call( this, history, hdas ); + } + + spaceghost.thenOpen( spaceghost.baseUrl ).then( function(){ + testAnonInaccessible.call( spaceghost, inaccessibleHistory, inaccessibleHdas ); + testAnonAccessible.call( spaceghost, accessibleHistory, accessibleHdas ); + testAnonAccessible.call( spaceghost, publishedHistory, publishedHdas ); + }); + + + // ------------------------------------------------------------------------------------------- user1 revoke perms + spaceghost.user.loginOrRegisterUser( email, password ); + spaceghost.openHomePage().then( function(){ + this.test.comment( 'revoking perms should prevent access' ); + this.api.histories.update( accessibleHistory.id, { + importable : false }); - }, 403, 'Must be logged in to manage Galaxy histories', 'hda copy to failed' ); -} + var returned = this.api.histories.show( accessibleHistory.id ); -function testAnonInaccessible( history, hdas ){ - testAnonReadFunctionsOnInaccessible.call( this, history, hdas ); - testAnonWriteFunctions.call( this, history, hdas ); -} + this.api.histories.update( publishedHistory.id, { + importable : false, + published : false + }); + returned = this.api.histories.show( publishedHistory.id ); + }); + spaceghost.user.logout(); -function testAnonAccessible( history, hdas ){ - testAnonReadFunctionsOnAccessible.call( this, history, hdas ); - testAnonWriteFunctions.call( this, history, hdas ); -} -spaceghost.thenOpen( spaceghost.baseUrl ).then( function(){ - testAnonInaccessible.call( spaceghost, inaccessibleHistory, inaccessibleHdas ); - testAnonAccessible.call( spaceghost, accessibleHistory, accessibleHdas ); - testAnonAccessible.call( spaceghost, publishedHistory, publishedHdas ); -}); + // ------------------------------------------------------------------------------------------- anon retry perms + spaceghost.openHomePage().then( function(){ + testAnonInaccessible.call( spaceghost, accessibleHistory, accessibleHdas ); + testAnonInaccessible.call( spaceghost, publishedHistory, publishedHdas ); + }); -// ------------------------------------------------------------------------------------------- user1 revoke perms -spaceghost.user.loginOrRegisterUser( email, password ); -spaceghost.thenOpen( spaceghost.baseUrl ).then( function(){ - this.test.comment( 'revoking perms should prevent access' ); - this.api.histories.update( accessibleHistory.id, { - importable : false - }); - var returned = this.api.histories.show( accessibleHistory.id ); - - this.api.histories.update( publishedHistory.id, { - importable : false, - published : false - }); - returned = this.api.histories.show( publishedHistory.id ); -}); -spaceghost.user.logout(); - - -// ------------------------------------------------------------------------------------------- anon retry perms -spaceghost.thenOpen( spaceghost.baseUrl ).then( function(){ - testAnonInaccessible.call( spaceghost, accessibleHistory, accessibleHdas ); - testAnonInaccessible.call( spaceghost, publishedHistory, publishedHdas ); -}); - - -// =================================================================== + // =================================================================== spaceghost.run( function(){ test.done(); }); }); diff -r 1aa8a57c599455b2a9faeeadb980b62b8abecc1f -r 3131a76ddd932911a80838d83aaf71baf26a3d6f test/casperjs/api-anon-history-tests.js --- a/test/casperjs/api-anon-history-tests.js +++ b/test/casperjs/api-anon-history-tests.js @@ -7,125 +7,116 @@ spaceghost.test.begin( 'Test API functions for histories with an anonymous user', 0, function suite( test ){ spaceghost.start(); -// =================================================================== TESTS -spaceghost.thenOpen( spaceghost.baseUrl ).waitForSelector( spaceghost.historypanel.data.selectors.history.name ); -spaceghost.then( function(){ + // =================================================================== TESTS + spaceghost.thenOpen( spaceghost.baseUrl ).waitForSelector( spaceghost.historypanel.data.selectors.history.name ); + spaceghost.then( function(){ - // ------------------------------------------------------------------------------------------- anon allowed - this.test.comment( 'index should get a list of histories' ); - var index = this.api.histories.index(); - this.test.assert( utils.isArray( index ), "index returned an array: length " + index.length ); - this.test.assert( index.length === 1, 'Has at least one history' ); + // ------------------------------------------------------------------------------------------- anon allowed + this.test.comment( 'index should get a list of histories' ); + var index = this.api.histories.index(); + this.test.assert( utils.isArray( index ), "index returned an array: length " + index.length ); + this.test.assert( index.length === 1, 'Has at least one history' ); - this.test.comment( 'show should get a history details object' ); - var historyShow = this.api.histories.show( index[0].id ); - //this.debug( this.jsonStr( historyShow ) ); - this.test.assert( historyShow.id === index[0].id, 'Is the first history' ); - this.test.assert( this.hasKeys( historyShow, [ 'id', 'name', 'user_id' ] ) ); + this.test.comment( 'show should get a history details object' ); + var historyShow = this.api.histories.show( index[0].id ); + //this.debug( this.jsonStr( historyShow ) ); + this.test.assert( historyShow.id === index[0].id, 'Is the first history' ); + this.test.assert( this.hasKeys( historyShow, [ 'id', 'name', 'user_id' ] ) ); - // ------------------------------------------------------------------------------------------- anon forbidden - //TODO: why not return the current history? - this.test.comment( 'calling show with "most_recently_used" should return None for an anon user' ); - var recent = this.api.histories.show( 'most_recently_used' ); - this.test.assert( recent === null, 'most_recently_used returned None' ); + // ------------------------------------------------------------------------------------------- anon forbidden + //TODO: why not return the current history? + this.test.comment( 'calling show with "most_recently_used" should return None for an anon user' ); + var recent = this.api.histories.show( 'most_recently_used' ); + this.test.assert( recent === null, 'most_recently_used returned None' ); - this.test.comment( 'Calling create should fail for an anonymous user' ); - this.api.assertRaises( function(){ - this.api.histories.create({ name: 'new' }); - }, 403, 'API authentication required for this request', 'create failed with error' ); + this.test.comment( 'Calling create should fail for an anonymous user' ); + this.api.assertRaises( function(){ + this.api.histories.create({ name: 'new' }); + }, 403, 'API authentication required for this request', 'create failed with error' ); - this.test.comment( 'Calling delete should fail for an anonymous user' ); - this.api.assertRaises( function(){ - this.api.histories.delete_( historyShow.id ); - }, 403, 'API authentication required for this request', 'create failed with error' ); + this.test.comment( 'Calling delete should fail for an anonymous user' ); + this.api.assertRaises( function(){ + this.api.histories.delete_( historyShow.id ); + }, 403, 'API authentication required for this request', 'create failed with error' ); - this.test.comment( 'Calling update should fail for an anonymous user' ); - this.api.assertRaises( function(){ - this.api.histories.update( historyShow.id, {} ); - }, 403, 'API authentication required for this request', 'update failed with error' ); + this.test.comment( 'Calling update should fail for an anonymous user' ); + this.api.assertRaises( function(){ + this.api.histories.update( historyShow.id, {} ); + }, 403, 'API authentication required for this request', 'update failed with error' ); - //TODO: need these two in api.js - //this.test.comment( 'Calling archive_import should fail for an anonymous user' ); - //this.api.assertRaises( function(){ - // this.api.histories.archive_import( historyShow.id, {} ); - //}, 403, 'API authentication required for this request', 'archive_import failed with error' ); + //TODO: need these two in api.js + //this.test.comment( 'Calling archive_import should fail for an anonymous user' ); + //this.api.assertRaises( function(){ + // this.api.histories.archive_import( historyShow.id, {} ); + //}, 403, 'API authentication required for this request', 'archive_import failed with error' ); - //this.test.comment( 'Calling archive_download should fail for an anonymous user' ); - //this.api.assertRaises( function(){ - // this.api.histories.archive_download( historyShow.id, {} ); - //}, 403, 'API authentication required for this request', 'archive_download failed with error' ); + //this.test.comment( 'Calling archive_download should fail for an anonymous user' ); + //this.api.assertRaises( function(){ + // this.api.histories.archive_download( historyShow.id, {} ); + //}, 403, 'API authentication required for this request', 'archive_download failed with error' ); - // test server bad id protection - spaceghost.test.comment( 'A bad id should throw an error' ); - this.api.assertRaises( function(){ - this.api.histories.show( '1234123412341234' ); - }, 400, 'unable to decode', 'Bad Request with invalid id: show' ); + // test server bad id protection + spaceghost.test.comment( 'A bad id should throw an error' ); + this.api.assertRaises( function(){ + this.api.histories.show( '1234123412341234' ); + }, 400, 'unable to decode', 'Bad Request with invalid id: show' ); -}); + }); -// ------------------------------------------------------------------------------------------- hdas -spaceghost.thenOpen( spaceghost.baseUrl ).waitForSelector( spaceghost.historypanel.data.selectors.history.name ); -spaceghost.then( function(){ - var currHistory = spaceghost.api.histories.index()[0]; - spaceghost.api.tools.thenUpload( currHistory.id, { - filepath: '../../test-data/1.sam' - }, function( uploadedId ){ - var hda = spaceghost.api.hdas.show( currHistory.id, uploadedId ); - this.test.assert( hda.state === 'ok', "Convenience function produced hda in ok state" ); - }); -}); + // ------------------------------------------------------------------------------------------- hdas + spaceghost.thenOpen( spaceghost.baseUrl ).waitForSelector( spaceghost.historypanel.data.selectors.history.name ); + spaceghost.api.tools.thenUploadToCurrent({ filepath: '../../test-data/1.sam' }); + spaceghost.then( function(){ + var current = this.api.histories.index()[0]; -spaceghost.then( function(){ - var current = this.api.histories.index()[0]; + // ------------------------------------------------------------------------------------------- anon allowed + this.test.comment( 'anonymous users can index hdas in their current history' ); + var hdaIndex = this.api.hdas.index( current.id ); + this.test.assert( hdaIndex.length === 1, 'indexed hdas' ); - // ------------------------------------------------------------------------------------------- anon allowed - this.test.comment( 'anonymous users can index hdas in their current history' ); - var hdaIndex = this.api.hdas.index( current.id ); - this.test.assert( hdaIndex.length === 1, 'indexed hdas' ); + this.test.comment( 'anonymous users can show hdas in their current history' ); + var hda = this.api.hdas.show( current.id, hdaIndex[0].id ); + this.test.assert( this.hasKeys( hda, [ 'id', 'name' ] ), 'showed hda: ' + hda.name ); - this.test.comment( 'anonymous users can show hdas in their current history' ); - var hda = this.api.hdas.show( current.id, hdaIndex[0].id ); - this.test.assert( this.hasKeys( hda, [ 'id', 'name' ] ), 'showed hda: ' + hda.name ); + this.test.comment( 'anonymous users can hide hdas in their current history' ); + var changed = this.api.hdas.update( current.id, hda.id, { visible: false }); + hda = this.api.hdas.show( current.id, hda.id ); + this.test.assert( hda.visible === false, 'successfully hidden' ); - this.test.comment( 'anonymous users can hide hdas in their current history' ); - var changed = this.api.hdas.update( current.id, hda.id, { visible: false }); - hda = this.api.hdas.show( current.id, hda.id ); - this.test.assert( hda.visible === false, 'successfully hidden' ); + this.test.comment( 'anonymous users can mark their hdas as deleted in their current history' ); + changed = this.api.hdas.update( current.id, hda.id, { deleted: true }); + hda = this.api.hdas.show( current.id, hda.id ); + this.test.assert( hda.deleted, 'successfully deleted' ); - this.test.comment( 'anonymous users can mark their hdas as deleted in their current history' ); - changed = this.api.hdas.update( current.id, hda.id, { deleted: true }); - hda = this.api.hdas.show( current.id, hda.id ); - this.test.assert( hda.deleted, 'successfully deleted' ); + // ------------------------------------------------------------------------------------------- anon forbidden + this.test.comment( 'Creating an hda should work for an anonymous user' ); + var returned = this.api.hdas.create( current.id, { source: 'hda', content: hda.id }); + //this.debug( this.jsonStr( returned ) ); + this.test.assert( returned.name === hda.name, 'name matches: ' + returned.name ); + this.test.assert( returned.id !== hda.id, 'new id: ' + returned.id ); - // ------------------------------------------------------------------------------------------- anon forbidden - this.test.comment( 'Creating an hda should work for an anonymous user' ); - var returned = this.api.hdas.create( current.id, { source: 'hda', content: hda.id }); - //this.debug( this.jsonStr( returned ) ); - this.test.assert( returned.name === hda.name, 'name matches: ' + returned.name ); - this.test.assert( returned.id !== hda.id, 'new id: ' + returned.id ); + //TODO: should be allowed + this.test.comment( 'Calling hda delete should fail for an anonymous user' ); + this.api.assertRaises( function(){ + this.api.hdas.delete_( current.id, hda.id ); + }, 403, 'API authentication required for this request', 'delete failed with error' ); - //TODO: should be allowed - this.test.comment( 'Calling hda delete should fail for an anonymous user' ); - this.api.assertRaises( function(){ - this.api.hdas.delete_( current.id, hda.id ); - }, 403, 'API authentication required for this request', 'delete failed with error' ); + //TODO: only sharing, tags, annotations should be blocked/prevented + this.test.comment( 'Calling update with keys other than "visible" or "deleted" should fail silently' ); + this.test.comment( 'Calling update on tags should fail silently' ); + changed = this.api.hdas.update( current.id, hda.id, { tags: [ 'one' ] }); + hda = this.api.hdas.show( current.id, hda.id ); + this.test.assert( hda.tags.length === 0, 'tags were not set: ' + this.jsonStr( hda.tags ) ); - //TODO: only sharing, tags, annotations should be blocked/prevented - this.test.comment( 'Calling update with keys other than "visible" or "deleted" should fail silently' ); - this.test.comment( 'Calling update on tags should fail silently' ); - changed = this.api.hdas.update( current.id, hda.id, { tags: [ 'one' ] }); - hda = this.api.hdas.show( current.id, hda.id ); - this.test.assert( hda.tags.length === 0, 'tags were not set: ' + this.jsonStr( hda.tags ) ); + this.test.comment( 'Calling update on annotation should fail silently' ); + changed = this.api.hdas.update( current.id, hda.id, { annotation: 'yup yup yup' }); + hda = this.api.hdas.show( current.id, hda.id ); + this.test.assert( !hda.annotation, 'annotation was not set: ' + hda.annotation ); - this.test.comment( 'Calling update on annotation should fail silently' ); - changed = this.api.hdas.update( current.id, hda.id, { annotation: 'yup yup yup' }); - hda = this.api.hdas.show( current.id, hda.id ); - this.test.assert( !hda.annotation, 'annotation was not set: ' + hda.annotation ); + }); -}); - -// =================================================================== + // =================================================================== spaceghost.run( function(){ test.done(); }); }); diff -r 1aa8a57c599455b2a9faeeadb980b62b8abecc1f -r 3131a76ddd932911a80838d83aaf71baf26a3d6f test/casperjs/api-configuration-tests.js --- a/test/casperjs/api-configuration-tests.js +++ b/test/casperjs/api-configuration-tests.js @@ -7,57 +7,55 @@ spaceghost.test.begin( 'Test the Galaxy configuration 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; -} -spaceghost.user.loginOrRegisterUser( email, password ); + // =================================================================== SET UP + var email = spaceghost.user.getRandomEmail(), + password = '123456'; + if( spaceghost.fixtureData.testUser ){ + email = spaceghost.fixtureData.testUser.email; + password = spaceghost.fixtureData.testUser.password; + } + spaceghost.user.loginOrRegisterUser( email, password ); -// =================================================================== TESTS -var normKeys = [ - 'enable_unique_workflow_defaults', - 'ftp_upload_site', - 'ftp_upload_dir', - 'wiki_url', - 'support_url', - 'logo_url', - 'terms_url', - 'allow_user_dataset_purge' - ], - adminKeys = normKeys.concat([ - 'library_import_dir', - 'user_library_import_dir', - 'allow_library_path_paste', - 'allow_user_creation', - 'allow_user_deletion' - ]); + // =================================================================== TESTS + var normKeys = [ + 'enable_unique_workflow_defaults', + 'ftp_upload_site', + 'ftp_upload_dir', + 'wiki_url', + 'support_url', + 'logo_url', + 'terms_url', + 'allow_user_dataset_purge' + ], + adminKeys = normKeys.concat([ + 'library_import_dir', + 'user_library_import_dir', + 'allow_library_path_paste', + 'allow_user_creation', + 'allow_user_deletion' + ]); + // ------------------------------------------------------------------------------------------- INDEX + spaceghost.openHomePage().then( function(){ + this.test.comment( 'index should get a (shortened) list of configuration settings ' + + 'when requested by a normal user' ); -// ------------------------------------------------------------------------------------------- INDEX -spaceghost.thenOpen( spaceghost.baseUrl ).then( function(){ + var configIndex = this.api.configuration.index(); + this.debug( this.jsonStr( configIndex ) ); + this.test.assert( utils.isObject( configIndex ), "index returned an object" ); + this.test.assert( this.hasKeys( configIndex, normKeys ), 'Has the proper keys' ); - this.test.comment( 'index should get a (shortened) list of configuration settings ' - + 'when requested by a normal user' ); - var configIndex = this.api.configuration.index(); - this.debug( this.jsonStr( configIndex ) ); - this.test.assert( utils.isObject( configIndex ), "index returned an object" ); - this.test.assert( this.hasKeys( configIndex, normKeys ), 'Has the proper keys' ); + }); + spaceghost.user.logout(); -}); -spaceghost.user.logout(); + // ------------------------------------------------------------------------------------------- INDEX (admin) + spaceghost.tryStepsCatch( function tryAdminLogin(){ + spaceghost.user.loginAdmin(); + }, function(){} ); -// ------------------------------------------------------------------------------------------- INDEX (admin) -spaceghost.tryStepsCatch( function tryAdminLogin(){ - spaceghost.user.loginAdmin(); -}, function(){} ); - -//}, function failedLoginRegister(){ -// this.info( 'Admin level configuration API tests not run: no admin account available' ); -spaceghost.thenOpen( spaceghost.baseUrl ).then( function(){ - spaceghost.waitForMasthead( function() { + //}, function failedLoginRegister(){ + // this.info( 'Admin level configuration API tests not run: no admin account available' ); + spaceghost.openHomePage().waitForMasthead( function(){ if( spaceghost.user.userIsAdmin() ){ this.test.comment( 'index should get a (full) list of configuration settings ' + 'when requested by an admin user' ); @@ -70,9 +68,8 @@ this.info( 'Admin level configuration API tests not run: no admin account available' ); } }); -}); -// =================================================================== + // =================================================================== spaceghost.run( function(){ test.done(); }); }); diff -r 1aa8a57c599455b2a9faeeadb980b62b8abecc1f -r 3131a76ddd932911a80838d83aaf71baf26a3d6f test/casperjs/api-hda-tests.js --- a/test/casperjs/api-hda-tests.js +++ b/test/casperjs/api-hda-tests.js @@ -7,363 +7,359 @@ 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; -} -spaceghost.user.loginOrRegisterUser( email, password ); + // =================================================================== SET UP + var email = spaceghost.user.getRandomEmail(), + password = '123456'; + if( spaceghost.fixtureData.testUser ){ + email = spaceghost.fixtureData.testUser.email; + password = spaceghost.fixtureData.testUser.password; + } + spaceghost.user.loginOrRegisterUser( email, password ); -spaceghost.thenOpen( spaceghost.baseUrl, function(){ - this.test.comment( '(logged in as ' + this.user.loggedInAs() + ')' ); - this.api.tools.thenUpload( spaceghost.api.histories.index()[0].id, { + spaceghost.openHomePage().api.tools.thenUploadToCurrent({ filepath: '../../test-data/1.sam' }); -}); -// =================================================================== TESTS -var summaryKeys = [ 'id', 'name', 'history_id', 'state', 'deleted', 'purged', 'visible', 'url', 'type' ], - 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', - // the following are NOT always present DEPENDING ON datatype - 'metadata_dbkey', - 'metadata_column_names', 'metadata_column_types', 'metadata_columns', - 'metadata_comment_lines', 'metadata_data_lines' - ]; + // =================================================================== TESTS + var summaryKeys = [ 'id', 'name', 'history_id', 'state', 'deleted', 'purged', 'visible', 'url', 'type' ], + 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', + // the following are NOT always present DEPENDING ON datatype + 'metadata_dbkey', + 'metadata_column_names', 'metadata_column_types', 'metadata_columns', + 'metadata_comment_lines', 'metadata_data_lines' + ]; -// ------------------------------------------------------------------------------------------- logged in user -spaceghost.then( function(){ - - // ------------------------------------------------------------------------------------------- INDEX - this.test.comment( 'index should return a list of summary data for each hda' ); - var histories = this.api.histories.index(), - lastHistory = histories[0], - hdaIndex = this.api.hdas.index( lastHistory.id ); - //this.debug( 'hdaIndex:' + this.jsonStr( hdaIndex ) ); + // ------------------------------------------------------------------------------------------- logged in user + spaceghost.then( function(){ + // ------------------------------------------------------------------------------------------- INDEX + this.test.comment( 'index should return a list of summary data for each hda' ); + var histories = this.api.histories.index(), + lastHistory = histories[0], + hdaIndex = this.api.hdas.index( lastHistory.id ); + //this.debug( 'hdaIndex:' + this.jsonStr( hdaIndex ) ); - this.test.assert( utils.isArray( hdaIndex ), "index returned an array: length " + hdaIndex.length ); - this.test.assert( hdaIndex.length >= 1, 'Has at least one hda' ); + this.test.assert( utils.isArray( hdaIndex ), "index returned an array: length " + hdaIndex.length ); + this.test.assert( hdaIndex.length >= 1, 'Has at least one hda' ); - var firstHda = hdaIndex[0]; - this.test.assert( this.hasKeys( firstHda, summaryKeys ), 'Has the proper keys' ); + var firstHda = hdaIndex[0]; + this.test.assert( this.hasKeys( firstHda, summaryKeys ), 'Has the proper keys' ); - this.test.assert( this.api.isEncodedId( firstHda.id ), 'Id appears well-formed: ' + firstHda.id ); - this.test.assert( firstHda.name === '1.sam', 'Title matches: ' + firstHda.name ); + this.test.assert( this.api.isEncodedId( firstHda.id ), 'Id appears well-formed: ' + firstHda.id ); + this.test.assert( firstHda.name === '1.sam', 'Title matches: ' + firstHda.name ); - // ------------------------------------------------------------------------------------------- SHOW - this.test.comment( 'show should get an HDA details object' ); - var hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - //this.debug( this.jsonStr( hdaShow ) ); - this.test.assert( this.hasKeys( hdaShow, detailKeys ), 'Has the proper keys' ); + // ------------------------------------------------------------------------------------------- SHOW + this.test.comment( 'show should get an HDA details object' ); + var hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + //this.debug( this.jsonStr( hdaShow ) ); + this.test.assert( this.hasKeys( hdaShow, detailKeys ), 'Has the proper keys' ); - //TODO: validate data in each hdaShow attribute... + //TODO: validate data in each hdaShow attribute... - // ------------------------------------------------------------------------------------------- INDEX (detailed) - this.test.comment( 'index should return a list of detailed data for each hda in "ids" when passed' ); - hdaIndex = this.api.hdas.index( lastHistory.id, [ firstHda.id ] ); - this.debug( 'hdaIndex:' + this.jsonStr( hdaIndex ) ); + // ------------------------------------------------------------------------------------------- INDEX (detailed) + this.test.comment( 'index should return a list of detailed data for each hda in "ids" when passed' ); + hdaIndex = this.api.hdas.index( lastHistory.id, [ firstHda.id ] ); + this.debug( 'hdaIndex:' + this.jsonStr( hdaIndex ) ); - this.test.assert( utils.isArray( hdaIndex ), "index returned an array: length " + hdaIndex.length ); - this.test.assert( hdaIndex.length >= 1, 'Has at least one hda' ); + this.test.assert( utils.isArray( hdaIndex ), "index returned an array: length " + hdaIndex.length ); + this.test.assert( hdaIndex.length >= 1, 'Has at least one hda' ); - firstHda = hdaIndex[0]; - this.test.assert( this.hasKeys( firstHda, detailKeys ), 'Has the proper keys' ); + firstHda = hdaIndex[0]; + this.test.assert( this.hasKeys( firstHda, detailKeys ), 'Has the proper keys' ); - //TODO??: validate data in firstHda attribute? we ASSUME it's from a common method as show... + //TODO??: validate data in firstHda attribute? we ASSUME it's from a common method as show... - // ------------------------------------------------------------------------------------------- CREATE - //TODO: create from_ld_id - this.test.comment( 'create should allow copying an accessible hda' ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - var returned = this.api.hdas.create( lastHistory.id, { - source : 'hda', - content : hdaShow.id + // ------------------------------------------------------------------------------------------- CREATE + //TODO: create from_ld_id + this.test.comment( 'create should allow copying an accessible hda' ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + var returned = this.api.hdas.create( lastHistory.id, { + source : 'hda', + content : hdaShow.id + }); + //this.debug( 'returned:' + this.jsonStr( returned ) ); + this.test.assert( this.hasKeys( returned, detailKeys ), 'Has the proper keys' ); + this.test.assert( typeof returned.id !== 'number' && isNaN( Number( returned.id ) ), + 'id seems to be encoded: ' + returned.id ); + this.test.assert( typeof returned.history_id !== 'number' && isNaN( Number( returned.history_id ) ), + 'history_id seems to be encoded: ' + returned.history_id ); + + + // ------------------------------------------------------------------------------------------- UPDATE + // ........................................................................................... idiot proofing + this.test.comment( 'updating to the current value should return no value (no change)' ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + var returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + name : hdaShow.name + }); + this.test.assert( this.countKeys( returned ) === 0, "No changed returned: " + this.jsonStr( returned ) ); + + this.test.comment( 'updating using a nonsense key should NOT fail with an error' ); + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + konamiCode : 'uuddlrlrba' + }); + this.test.assert( this.countKeys( returned ) === 0, "No changed returned: " + this.jsonStr( returned ) ); + + this.test.comment( 'updating by attempting to change type should cause an error' ); + this.api.assertRaises( function(){ + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + //name : false + deleted : 'sure why not' + }); + }, 400, 'deleted must be a boolean', 'changing deleted type failed' ); + + // ........................................................................................... name + this.test.comment( 'update should allow changing the name' ); + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + name : 'New name' + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.name === 'New name', "Name successfully set via update: " + hdaShow.name ); + + this.test.comment( 'update should sanitize any new name' ); + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + name : 'New name<script type="text/javascript" src="bler">alert("blah");</script>' + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.name === 'New name', "Update sanitized name: " + hdaShow.name ); + + this.test.comment( 'update should allow unicode in names' ); + var unicodeName = 'Ржевский сапоги'; + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + name : unicodeName + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.name === unicodeName, "Update accepted unicode name: " + hdaShow.name ); + + this.test.comment( 'update should allow escaped quotations in names' ); + var quotedName = '"Bler"'; + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + name : quotedName + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.name === quotedName, + "Update accepted escaped quotations in name: " + hdaShow.name ); + + + // ........................................................................................... deleted + this.test.comment( 'update should allow changing the deleted flag' ); + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + deleted: true + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id, true ); + this.test.assert( hdaShow.deleted === true, "Update set the deleted flag: " + hdaShow.deleted ); + + this.test.comment( 'update should allow changing the deleted flag back' ); + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + deleted: false + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.deleted === false, "Update set the deleted flag: " + hdaShow.deleted ); + + + // ........................................................................................... visible/hidden + this.test.comment( 'update should allow changing the visible flag' ); + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + visible: false + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.visible === false, "Update set the visible flag: " + hdaShow.visible ); + + + // ........................................................................................... genome/dbkey + this.test.comment( 'update should allow changing the genome_build' ); + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + genome_build : 'hg18' + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + //this.debug( 'hdaShow:\n' + this.jsonStr( hdaShow ) ); + this.test.assert( hdaShow.genome_build === 'hg18', + "genome_build successfully set via update: " + hdaShow.genome_build ); + this.test.assert( hdaShow.metadata_dbkey === 'hg18', + "metadata_dbkey successfully set via the same update: " + hdaShow.metadata_dbkey ); + this.test.comment( 'update should sanitize any genome_build' ); + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + genome_build : 'hg18<script type="text/javascript" src="bler">alert("blah");</script>' + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.genome_build === 'hg18', + "Update sanitized genome_build: " + hdaShow.genome_build ); + this.test.assert( hdaShow.metadata_dbkey === 'hg18', + "metadata_dbkey successfully set via the same update: " + hdaShow.metadata_dbkey ); + + this.test.comment( 'update should allow unicode in genome builds' ); + var unicodeBuild = 'Ржевский18'; + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + genome_build : unicodeBuild + }); + this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.debug( 'hdaShow:\n' + this.jsonStr( hdaShow ) ); + this.test.assert( hdaShow.genome_build === unicodeBuild, + "Update accepted unicode genome_build: " + hdaShow.genome_build ); + + // ........................................................................................... misc_info/info + this.test.comment( 'update should allow changing the misc_info' ); + var newInfo = 'I\'ve made a huge mistake.'; + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + misc_info : newInfo + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.misc_info === newInfo, + "misc_info successfully set via update: " + hdaShow.misc_info ); + + this.test.comment( 'update should sanitize any misc_info' ); + var newInfo = 'You\'re going to get hop-ons.'; + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + misc_info : newInfo + '<script type="text/javascript" src="bler">alert("blah");</script>' + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.misc_info === newInfo, + "Update sanitized misc_info: " + hdaShow.misc_info ); + + this.test.comment( 'update should allow unicode in misc_info' ); + var unicodeInfo = '여보!'; + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + misc_info : unicodeInfo + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.misc_info === unicodeInfo, + "Update accepted unicode misc_info: " + hdaShow.misc_info ); + + // ........................................................................................... annotation + // currently fails because no annotation is returned in details + this.test.comment( 'update should allow changing the annotation' ); + var newAnnotation = 'Found this sample on a movie theatre floor'; + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + annotation : newAnnotation + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.annotation === newAnnotation, + "Annotation successfully set via update: " + hdaShow.annotation ); + + this.test.comment( 'update should sanitize any new annotation' ); + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + annotation : 'New annotation<script type="text/javascript" src="bler">alert("blah");</script>' + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.annotation === 'New annotation', + "Update sanitized annotation: " + hdaShow.annotation ); + + this.test.comment( 'update should allow unicode in annotations' ); + var unicodeAnnotation = 'お願いは、それが落下させない'; + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + annotation : unicodeAnnotation + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.annotation === unicodeAnnotation, + "Update accepted unicode annotation: " + hdaShow.annotation ); + + this.test.comment( 'update should allow escaped quotations in annotations' ); + var quotedAnnotation = '"Bler"'; + returned = this.api.hdas.update( lastHistory.id, firstHda.id, { + annotation : quotedAnnotation + }); + //this.debug( 'returned:\n' + this.jsonStr( returned ) ); + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.annotation === quotedAnnotation, + "Update accepted escaped quotations in annotation: " + hdaShow.annotation ); + + // ------------------------------------------------------------------------------------------- ERRORS + this.test.comment( 'create should error with "Please define the source" when the param "from_ld_id" is not used' ); + this.api.assertRaises( function(){ + this.api.hdas.create( lastHistory.id, { bler: 'bler' } ); + }, 400, "must be either 'library' or 'hda'", 'create with no source failed' ); + + this.test.comment( 'updating using a nonsense key should fail silently' ); + returned = this.api.hdas.update( lastHistory.id, hdaShow.id, { + konamiCode : 'uuddlrlrba' + }); + this.test.assert( returned.konamiCode === undefined, 'key was not set: ' + returned.konamiCode ); + + spaceghost.test.comment( 'A bad id should throw an error when using show' ); + this.api.assertRaises( function(){ + this.api.hdas.show( lastHistory.id, '1234123412341234' ); + }, 400, 'unable to decode', 'Bad Request with invalid id: show' ); + spaceghost.test.comment( 'A bad id should throw an error when using update' ); + this.api.assertRaises( function(){ + this.api.hdas.update( lastHistory.id, '1234123412341234', {} ); + }, 400, 'unable to decode', 'Bad Request with invalid id: update' ); + spaceghost.test.comment( 'A bad id should throw an error when using delete' ); + this.api.assertRaises( function(){ + this.api.hdas.delete_( lastHistory.id, '1234123412341234' ); + }, 400, 'unable to decode', 'Bad Request with invalid id: delete' ); + spaceghost.test.comment( 'A bad id should throw an error when using undelete' ); + + this.test.comment( 'updating by attempting to change type should cause an error' ); + [ 'name', 'annotation', 'genome_build', 'misc_info' ].forEach( function( key ){ + var updatedAttrs = {}; + updatedAttrs[ key ] = false; + spaceghost.api.assertRaises( function(){ + returned = spaceghost.api.hdas.update( hdaShow.history_id, hdaShow.id, updatedAttrs ); + }, 400, key + ' must be a string or unicode', 'type validation error' ); + }); + [ 'deleted', 'visible' ].forEach( function( key ){ + var updatedAttrs = {}; + updatedAttrs[ key ] = 'straaang'; + spaceghost.api.assertRaises( function(){ + returned = spaceghost.api.hdas.update( hdaShow.history_id, hdaShow.id, updatedAttrs ); + }, 400, key + ' must be a boolean', 'type validation error' ); + }); + [ 'you\'re it', [ true ] ].forEach( function( badVal ){ + spaceghost.api.assertRaises( function(){ + returned = spaceghost.api.hdas.update( hdaShow.history_id, hdaShow.id, { tags: badVal }); + }, 400, 'tags must be a list', 'type validation error' ); + }); + + // ------------------------------------------------------------------------------------------- DELETE + this.test.comment( 'calling delete on an hda should mark it as deleted but not change the history size' ); + lastHistory = this.api.histories.show( lastHistory.id ); + var sizeBeforeDelete = lastHistory.nice_size; + + returned = this.api.hdas.delete_( lastHistory.id, firstHda.id ); + //this.debug( this.jsonStr( returned ) ); + + hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); + this.test.assert( hdaShow.deleted, 'hda is marked deleted' ); + lastHistory = this.api.histories.show( lastHistory.id ); + this.test.assert( lastHistory.nice_size === sizeBeforeDelete, 'history size has not changed' ); + + // by default, purging fails bc uni.ini:allow_user_dataset_purge=False + this.api.assertRaises( function(){ + returned = this.api.hdas.delete_( lastHistory.id, firstHda.id, { purge : true }); + }, 403, 'This instance does not allow user dataset purging', 'Purge failed' ); + /* + */ }); - //this.debug( 'returned:' + this.jsonStr( returned ) ); - this.test.assert( this.hasKeys( returned, detailKeys ), 'Has the proper keys' ); - this.test.assert( typeof returned.id !== 'number' && isNaN( Number( returned.id ) ), - 'id seems to be encoded: ' + returned.id ); - this.test.assert( typeof returned.history_id !== 'number' && isNaN( Number( returned.history_id ) ), - 'history_id seems to be encoded: ' + returned.history_id ); + //spaceghost.user.logout(); - // ------------------------------------------------------------------------------------------- UPDATE - // ........................................................................................... idiot proofing - this.test.comment( 'updating to the current value should return no value (no change)' ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - var returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - name : hdaShow.name - }); - this.test.assert( this.countKeys( returned ) === 0, "No changed returned: " + this.jsonStr( returned ) ); - - this.test.comment( 'updating using a nonsense key should NOT fail with an error' ); - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - konamiCode : 'uuddlrlrba' - }); - this.test.assert( this.countKeys( returned ) === 0, "No changed returned: " + this.jsonStr( returned ) ); - - this.test.comment( 'updating by attempting to change type should cause an error' ); - this.api.assertRaises( function(){ - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - //name : false - deleted : 'sure why not' - }); - }, 400, 'deleted must be a boolean', 'changing deleted type failed' ); - - // ........................................................................................... name - this.test.comment( 'update should allow changing the name' ); - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - name : 'New name' - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.name === 'New name', "Name successfully set via update: " + hdaShow.name ); - - this.test.comment( 'update should sanitize any new name' ); - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - name : 'New name<script type="text/javascript" src="bler">alert("blah");</script>' - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.name === 'New name', "Update sanitized name: " + hdaShow.name ); - - this.test.comment( 'update should allow unicode in names' ); - var unicodeName = 'Ржевский сапоги'; - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - name : unicodeName - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.name === unicodeName, "Update accepted unicode name: " + hdaShow.name ); - - this.test.comment( 'update should allow escaped quotations in names' ); - var quotedName = '"Bler"'; - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - name : quotedName - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.name === quotedName, - "Update accepted escaped quotations in name: " + hdaShow.name ); - - - // ........................................................................................... deleted - this.test.comment( 'update should allow changing the deleted flag' ); - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - deleted: true - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id, true ); - this.test.assert( hdaShow.deleted === true, "Update set the deleted flag: " + hdaShow.deleted ); - - this.test.comment( 'update should allow changing the deleted flag back' ); - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - deleted: false - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.deleted === false, "Update set the deleted flag: " + hdaShow.deleted ); - - - // ........................................................................................... visible/hidden - this.test.comment( 'update should allow changing the visible flag' ); - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - visible: false - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.visible === false, "Update set the visible flag: " + hdaShow.visible ); - - - // ........................................................................................... genome_build/dbkey - this.test.comment( 'update should allow changing the genome_build' ); - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - genome_build : 'hg18' - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - //this.debug( 'hdaShow:\n' + this.jsonStr( hdaShow ) ); - this.test.assert( hdaShow.genome_build === 'hg18', - "genome_build successfully set via update: " + hdaShow.genome_build ); - this.test.assert( hdaShow.metadata_dbkey === 'hg18', - "metadata_dbkey successfully set via the same update: " + hdaShow.metadata_dbkey ); - this.test.comment( 'update should sanitize any genome_build' ); - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - genome_build : 'hg18<script type="text/javascript" src="bler">alert("blah");</script>' - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.genome_build === 'hg18', - "Update sanitized genome_build: " + hdaShow.genome_build ); - this.test.assert( hdaShow.metadata_dbkey === 'hg18', - "metadata_dbkey successfully set via the same update: " + hdaShow.metadata_dbkey ); - - this.test.comment( 'update should allow unicode in genome builds' ); - var unicodeBuild = 'Ржевский18'; - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - genome_build : unicodeBuild - }); - this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.debug( 'hdaShow:\n' + this.jsonStr( hdaShow ) ); - this.test.assert( hdaShow.genome_build === unicodeBuild, - "Update accepted unicode genome_build: " + hdaShow.genome_build ); - - // ........................................................................................... misc_info/info - this.test.comment( 'update should allow changing the misc_info' ); - var newInfo = 'I\'ve made a huge mistake.'; - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - misc_info : newInfo - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.misc_info === newInfo, - "misc_info successfully set via update: " + hdaShow.misc_info ); - - this.test.comment( 'update should sanitize any misc_info' ); - var newInfo = 'You\'re going to get hop-ons.'; - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - misc_info : newInfo + '<script type="text/javascript" src="bler">alert("blah");</script>' - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.misc_info === newInfo, - "Update sanitized misc_info: " + hdaShow.misc_info ); - - this.test.comment( 'update should allow unicode in misc_info' ); - var unicodeInfo = '여보!'; - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - misc_info : unicodeInfo - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.misc_info === unicodeInfo, - "Update accepted unicode misc_info: " + hdaShow.misc_info ); - - // ........................................................................................... annotation - // currently fails because no annotation is returned in details - this.test.comment( 'update should allow changing the annotation' ); - var newAnnotation = 'Found this sample on a movie theatre floor'; - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - annotation : newAnnotation - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.annotation === newAnnotation, - "Annotation successfully set via update: " + hdaShow.annotation ); - - this.test.comment( 'update should sanitize any new annotation' ); - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - annotation : 'New annotation<script type="text/javascript" src="bler">alert("blah");</script>' - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.annotation === 'New annotation', - "Update sanitized annotation: " + hdaShow.annotation ); - - this.test.comment( 'update should allow unicode in annotations' ); - var unicodeAnnotation = 'お願いは、それが落下させない'; - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - annotation : unicodeAnnotation - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.annotation === unicodeAnnotation, - "Update accepted unicode annotation: " + hdaShow.annotation ); - - this.test.comment( 'update should allow escaped quotations in annotations' ); - var quotedAnnotation = '"Bler"'; - returned = this.api.hdas.update( lastHistory.id, firstHda.id, { - annotation : quotedAnnotation - }); - //this.debug( 'returned:\n' + this.jsonStr( returned ) ); - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.annotation === quotedAnnotation, - "Update accepted escaped quotations in annotation: " + hdaShow.annotation ); - - // ------------------------------------------------------------------------------------------- ERRORS - this.test.comment( 'create should error with "Please define the source" when the param "from_ld_id" is not used' ); - this.api.assertRaises( function(){ - this.api.hdas.create( lastHistory.id, { bler: 'bler' } ); - }, 400, "must be either 'library' or 'hda'", 'create with no source failed' ); - - this.test.comment( 'updating using a nonsense key should fail silently' ); - returned = this.api.hdas.update( lastHistory.id, hdaShow.id, { - konamiCode : 'uuddlrlrba' - }); - this.test.assert( returned.konamiCode === undefined, 'key was not set: ' + returned.konamiCode ); - - spaceghost.test.comment( 'A bad id should throw an error when using show' ); - this.api.assertRaises( function(){ - this.api.hdas.show( lastHistory.id, '1234123412341234' ); - }, 400, 'unable to decode', 'Bad Request with invalid id: show' ); - spaceghost.test.comment( 'A bad id should throw an error when using update' ); - this.api.assertRaises( function(){ - this.api.hdas.update( lastHistory.id, '1234123412341234', {} ); - }, 400, 'unable to decode', 'Bad Request with invalid id: update' ); - spaceghost.test.comment( 'A bad id should throw an error when using delete' ); - this.api.assertRaises( function(){ - this.api.hdas.delete_( lastHistory.id, '1234123412341234' ); - }, 400, 'unable to decode', 'Bad Request with invalid id: delete' ); - spaceghost.test.comment( 'A bad id should throw an error when using undelete' ); - - this.test.comment( 'updating by attempting to change type should cause an error' ); - [ 'name', 'annotation', 'genome_build', 'misc_info' ].forEach( function( key ){ - var updatedAttrs = {}; - updatedAttrs[ key ] = false; - spaceghost.api.assertRaises( function(){ - returned = spaceghost.api.hdas.update( hdaShow.history_id, hdaShow.id, updatedAttrs ); - }, 400, key + ' must be a string or unicode', 'type validation error' ); - }); - [ 'deleted', 'visible' ].forEach( function( key ){ - var updatedAttrs = {}; - updatedAttrs[ key ] = 'straaang'; - spaceghost.api.assertRaises( function(){ - returned = spaceghost.api.hdas.update( hdaShow.history_id, hdaShow.id, updatedAttrs ); - }, 400, key + ' must be a boolean', 'type validation error' ); - }); - [ 'you\'re it', [ true ] ].forEach( function( badVal ){ - spaceghost.api.assertRaises( function(){ - returned = spaceghost.api.hdas.update( hdaShow.history_id, hdaShow.id, { tags: badVal }); - }, 400, 'tags must be a list', 'type validation error' ); - }); - - // ------------------------------------------------------------------------------------------- DELETE - this.test.comment( 'calling delete on an hda should mark it as deleted but not change the history size' ); - lastHistory = this.api.histories.show( lastHistory.id ); - var sizeBeforeDelete = lastHistory.nice_size; - - returned = this.api.hdas.delete_( lastHistory.id, firstHda.id ); - //this.debug( this.jsonStr( returned ) ); - - hdaShow = this.api.hdas.show( lastHistory.id, firstHda.id ); - this.test.assert( hdaShow.deleted, 'hda is marked deleted' ); - lastHistory = this.api.histories.show( lastHistory.id ); - this.test.assert( lastHistory.nice_size === sizeBeforeDelete, 'history size has not changed' ); - - // by default, purging fails bc uni.ini:allow_user_dataset_purge=False - this.api.assertRaises( function(){ - returned = this.api.hdas.delete_( lastHistory.id, firstHda.id, { purge : true }); - }, 403, 'This instance does not allow user dataset purging', 'Purge failed' ); -/* -*/ -}); -//spaceghost.user.logout(); - - -// =================================================================== + // =================================================================== spaceghost.run( function(){ test.done(); }); }); This diff is so big that we needed to truncate the remainder. Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.