-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement request header and body templating
- Loading branch information
Showing
5 changed files
with
192 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from galaxy.app_unittest_utils.galaxy_mock import MockApp | ||
from galaxy.tools.parameters.dynamic_options import DynamicOptions | ||
from galaxy.util import XML | ||
from galaxy.util.bunch import Bunch | ||
from galaxy.work.context import WorkRequestContext | ||
|
||
|
||
def get_from_url_option(): | ||
return DynamicOptions( | ||
XML( | ||
""" | ||
<options from_url="https://usegalaxy.org/api/genomes/dm6" request_method="POST"> | ||
<request_headers type="json"> | ||
{"x-api-key": "${__user__.extra_preferences.resource_api_key if $__user__ else "anon"}"} | ||
</request_headers> | ||
<request_body type="json"> | ||
{"some_key": "some_value"} | ||
</request_body> | ||
<postprocess_expression type="ecma5.1"><![CDATA[${ | ||
if (inputs) { | ||
return Object.values(inputs.chrom_info).map((v) => [v.chrom, v.len]) | ||
} else { | ||
return [["The fallback value", "default"]] | ||
} | ||
}]]></postprocess_expression> | ||
</options> | ||
""" | ||
), | ||
Bunch(), | ||
) | ||
|
||
|
||
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, {}) == [["chr2L", "23513712", False]] |