from galaxy.app_unittest_utils.galaxy_mock import MockApp from galaxy.tools.parameters.dynamic_options import DynamicOptions from galaxy.tools.parameters.options import ParameterOption from galaxy.util import XML from galaxy.util.bunch import Bunch from galaxy.work.context import WorkRequestContext def get_from_url_option(): tool_param = Bunch( tool=Bunch( app=Bunch(), ), ) return DynamicOptions( XML(""" {"x-api-key": "${__user__.extra_preferences.resource_api_key if $__user__ else "anon"}"} {"some_key": "some_value"} [v.chrom, v.len]) } else { return [["The fallback value", "default"]] } }]]> """), tool_param, ) def test_dynamic_option_parsing(): from_url_option = get_from_url_option() assert from_url_option.from_url_options assert from_url_option.from_url_options.from_url == "https://usegalaxy.org/api/genomes/dm6" def test_dynamic_option_cache(): app = MockApp() trans = WorkRequestContext(app=app) from_url_option = get_from_url_option() options = from_url_option.from_url_options assert options args = (options.from_url, options.request_method, options.request_body, '{"x-api-key": "anon"}') trans.set_cache_value( args, { "id": "dm6", "reference": True, "chrom_info": [{"chrom": "chr2L", "len": 23513712}], "prev_chroms": False, "next_chroms": False, "start_index": 0, }, ) assert from_url_option.get_options(trans, {}) == [ParameterOption("chr2L", "23513712", False)]