commit/galaxy-central: davebgx: Fix functional tests for history functions.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/d2717865114c/ Changeset: d2717865114c User: davebgx Date: 2014-04-21 21:42:22 Summary: Fix functional tests for history functions. Affected #: 2 files diff -r 9856484a0dcf784ff4bf9e087c14de2e4d6d9506 -r d2717865114c0c577fcd508201acf5eeac2cc54a test/base/twilltestcase.py --- a/test/base/twilltestcase.py +++ b/test/base/twilltestcase.py @@ -270,11 +270,31 @@ return from_json_string( self.last_page() ) # Functions associated with histories - def get_history_from_api( self, encoded_history_id=None ): + def get_history_from_api( self, encoded_history_id=None, show_deleted=None, show_details=False ): if encoded_history_id is None: history = self.get_latest_history() encoded_history_id = history[ 'id' ] - return self.json_from_url( '/api/histories/%s/contents' % encoded_history_id ) + params = dict() + if show_deleted is not None: + params[ 'deleted' ] = show_deleted + api_url = '/api/histories/%s/contents?%s' % ( encoded_history_id, urllib.urlencode( params ) ) + json_data = self.json_from_url( api_url ) + if show_deleted is not None: + hdas = [] + for hda in json_data: + if show_deleted: + hdas.append( hda ) + else: + if not hda[ 'deleted' ]: + hdas.append( hda ) + json_data = hdas + if show_details: + params[ 'details' ] = ','.join( [ hda[ 'id' ] for hda in json_data ] ) + api_url = '/api/histories/%s/contents?%s' % ( encoded_history_id, urllib.urlencode( params ) ) + json_data = self.json_from_url( api_url ) + log.debug( 'detailed url: %s' % api_url ) + log.debug( 'detailed json data: %s' % json_data ) + return json_data def get_latest_history( self ): return self.json_from_url( '/api/histories' )[ 0 ] @@ -325,33 +345,21 @@ raise AssertionError( errmsg ) self.home() - def check_history_json( self, pattern, check_fn, show_deleted=None, multiline=True ): + def check_history_json( self, check_fn, show_deleted=None ): """ Tries to find a JSON string in the history page using the regex pattern, parse it, and assert check_fn returns True when called on that parsed data. """ - self.home() - if show_deleted: - self.visit_page( "history?show_deleted=True" ) - elif show_deleted == False: - self.visit_page( "history?show_deleted=False" ) - else: - self.visit_page( "history" ) - json_data = {} try: - tc.find( pattern, flags=( 'm' if multiline else '' ) ) - # twill stores the regex match in a special stack variable - match = twill.namespaces.get_twill_glocals()[1][ '__match__' ] - json_data = from_json_string( match ) - assert check_fn( json_data ), 'failed check_fn: %s' % ( check_fn.func_name ) - - except Exception, exc: - log.error( exc, exc_info=True ) + json_data = self.get_history_from_api( show_deleted=show_deleted, show_details=True ) + check_result = check_fn( json_data ) + assert check_result, 'failed check_fn: %s (got %s)' % ( check_fn.func_name, str( check_result ) ) + except Exception, e: + log.exception( e ) log.debug( 'json_data: %s', ( '\n' + pprint.pformat( json_data ) if json_data else '(no match)' ) ) fname = self.write_temp_file( tc.browser.get_html() ) - errmsg = ( "json '%s' could not be found or failed check_fn" % ( pattern ) + - "\npage content written to '%s'" % ( fname ) ) + errmsg = ( "json could not be read\npage content written to '%s'" % ( fname ) ) raise AssertionError( errmsg ) self.home() diff -r 9856484a0dcf784ff4bf9e087c14de2e4d6d9506 -r d2717865114c0c577fcd508201acf5eeac2cc54a test/functional/test_history_functions.py --- a/test/functional/test_history_functions.py +++ b/test/functional/test_history_functions.py @@ -665,7 +665,7 @@ if hda[ 'id' ] == self.security.encode_id( hda_2_bed.id ): return ( not hda[ 'accessible' ] ) return False - self.check_history_json( r'\bhdaJSON\s*=\s*(.*);', hda_2_bed_is_inaccessible ) + self.check_history_json( hda_2_bed_is_inaccessible ) # Admin users can view all datasets ( using the history/view feature ), so make sure 2.bed is accessible to the admin self.logout() @@ -738,28 +738,26 @@ .order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ) .first() ) - # delete that item and make sure the 'history empty' message shows + # delete that item and make sure the history is not empty self.home() log.info( 'deleting last hda' ) self.delete_history_item( str( latest_hda.id ) ) - # check the historyPanel settings.show_deleted for a null json value (no show_deleted in query string) - self.check_history_json( r'\bshow_deleted\s*:\s*(.*),', lambda x: x == None ) + # check the number of items returned from the api + self.check_history_json( lambda x: len( x ) != 0 ) # reload this history with the show_deleted flag set in the query string # the deleted dataset should be there with the proper 'deleted' text - self.home() log.info( 'turning show_deleted on' ) - #self.visit_url( "%s/history/?show_deleted=True" % self.url ) - # check the historyPanel settings.show_deleted for a true json value - self.check_history_json( r'\bshow_deleted\s*:\s*(.*),', lambda x: x == True, show_deleted=True ) + #self.visit_url( "/api/histories/<id>/contents?deleted=True" ) + # check the number of items returned from the api + self.check_history_json( lambda x: len( x ) != 0, show_deleted=True ) # reload this history again with the show_deleted flag set TO FALSE in the query string - # make sure the 'history empty' message shows - self.home() + # make sure the history is empty log.info( 'turning show_deleted off' ) - #self.visit_url( "%s/history/?show_deleted=False" % self.url ) - # check the historyPanel settings.show_deleted for a false json value - self.check_history_json( r'\bshow_deleted\s*:\s*(.*),', lambda x: x == False, show_deleted=False ) + #self.visit_url( "/api/histories/<id>/contents?deleted=False" ) + # check the number of items returned from the api + self.check_history_json( lambda x: len( x ) == 0, show_deleted=False ) # delete this history self.delete_history( self.security.encode_id( latest_history.id ) ) 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.
participants (1)
-
commits-noreply@bitbucket.org