Add test cases against usegalaxy.org's genomes api

This commit is contained in:
mvdbeek
2024-02-12 15:48:00 +01:00
parent 1b7fc8ab8b
commit d96dc3dfa5
2 changed files with 37 additions and 11 deletions
@@ -9,6 +9,8 @@ import os
import re
from io import StringIO
import requests
from galaxy.model import (
DatasetCollectionElement,
HistoryDatasetAssociation,
@@ -781,11 +783,15 @@ class DynamicOptions:
return [str(values[0]), str(values[1]), bool(values[2])]
if self.from_url:
import requests
context = User.user_template_environment(trans.user)
url = fill_template(self.from_url, context)
data = requests.get(url).json()
try:
response = requests.get(url)
response.raise_for_status()
except Exception as e:
log.warning("Fetching from url '%s' failed: %s", url, str(e))
return []
data = response.json()
if self.from_url_postprocess:
data = do_eval(
+28 -8
View File
@@ -1,25 +1,45 @@
<tool id="select_from_url" name="select_from_url" version="0.1.0" profile="23.1">
<command>
echo '$url_param_value' > '$the_value'
</command>
<command><![CDATA[
echo '$url_param_value' > '$param_value' &&
echo '$url_param_value_postprocessed' > '$param_value_postprocessed'
]]></command>
<inputs>
<param name="url_param_value" type="select">
<options from_url="http://localhost:8000/data">
<options from_url="https://usegalaxy.org/api/genomes">
</options>
</param>
<!--
<param name="url_param_value_templated" type="select">
<options from_url="http://localhost:8000/data?user=$__user_id__">
</options>
</param>
<param name="url_param_value_templated_and_postprocessed" type="select">
<options from_url="http://localhost:8000/data_paginated?user=$__user_id__">
-->
<param name="url_param_value_postprocessed" type="select">
<options from_url="https://usegalaxy.org/api/genomes/dm6">
<postprocess_expression><![CDATA[
$( inputs.map((v) => [`name: ${v[0]}`, `value: ${v[1]}`]) )
$( Object.values(inputs.chrom_info).map((v) => [v.chrom, v.len]) )
]]></postprocess_expression>
</options>
</param>
</inputs>
<outputs>
<data format="txt" name="the_value"></data>
<data format="txt" label="url param value" name="param_value"></data>
<data format="txt" label="url param value postprocessed" name="param_value_postprocessed"></data>
</outputs>
<tests>
<test>
<param name="url_param_value" value="dm6" />
<param name="url_param_value_postprocessed" value="chr2L" />
<output name="param_value">
<assert_contents>
<has_text text="dm6"></has_text>
</assert_contents>
</output>
<output name="param_value_postprocessed">
<assert_contents>
<has_text text="23513712"></has_text>
</assert_contents>
</output>
</test>
</tests>
</tool>