Skip to content

Commit

Permalink
Implement registry query api call
Browse files Browse the repository at this point in the history
  • Loading branch information
duytnguyendtn committed Oct 22, 2024
1 parent 98c8304 commit 920b4b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_query_registry_args(self, imviz_helper):
# If waveband isn't selected, plugin should ignore our registry query attempts
vo_plugin = imviz_helper.plugins[vo_plugin_label]
vo_plugin.waveband = ""
vo_plugin._obj.vue_query_registry_resources()
vo_plugin.query_registry_resources()
assert len(vo_plugin.resource.choices) == 0

# If waveband selected and coverage filtering, can't query registry if don't have a source
Expand All @@ -244,7 +244,7 @@ def test_query_registry_args(self, imviz_helper):

# If waveband selected, but NOT filtering by coverage, then allow registry query
vo_plugin.resource_filter_coverage = False
vo_plugin._obj.vue_query_registry_resources()
vo_plugin.query_registry_resources()
assert len(vo_plugin.resource.choices) > 0

def test_coverage_toggle(self, imviz_helper):
Expand All @@ -260,14 +260,14 @@ def test_coverage_toggle(self, imviz_helper):

# Retrieve registry options with filtering on
vo_plugin.resource_filter_coverage = True
vo_plugin._obj.vue_query_registry_resources()
vo_plugin.query_registry_resources()
assert vo_plugin._obj.resources_loading is False
filtered_resources = vo_plugin.resource.choices
assert len(filtered_resources) > 0

# Retrieve registry options with filtering off
vo_plugin.resource_filter_coverage = False
vo_plugin._obj.vue_query_registry_resources()
vo_plugin.query_registry_resources()
assert vo_plugin._obj.resources_loading is False
nonfiltered_resources = vo_plugin.resource.choices

Expand All @@ -292,7 +292,7 @@ def test_target_lookup_warnings(self, imviz_helper):
vo_plugin.resource_filter_coverage = True
with pytest.raises(LookupError, match=expected_error_msg):
vo_plugin.waveband = "optical"
vo_plugin._obj.vue_query_registry_resources()
vo_plugin.query_registry_resources()
assert any(
expected_error_msg in d["text"]
for d in imviz_helper.app.state.snackbar_history
Expand All @@ -302,7 +302,7 @@ def test_target_lookup_warnings(self, imviz_helper):
# By clearing coverage filtering, we should now be able to query the registry
# and return the full list of available resources:
vo_plugin.resource_filter_coverage = False
vo_plugin._obj.vue_query_registry_resources()
vo_plugin.query_registry_resources()
assert len(vo_plugin.resource.choices) > 0

# However, if we try to query a resource, we should be prevented
Expand Down Expand Up @@ -333,7 +333,7 @@ def test_HSTM51_load_data(self, imviz_helper):
# Select HST.M51 survey
# Coverage not implemented for HST.M51
vo_plugin.resource_filter_coverage = False
vo_plugin._obj.vue_query_registry_resources()
vo_plugin.query_registry_resources()
assert "HST.M51" in vo_plugin.resource.choices
vo_plugin.resource = "HST.M51"

Expand Down
11 changes: 7 additions & 4 deletions jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ def __init__(self, *args, **kwargs):

@property
def user_api(self):
# NOTE: leaving save_as_fits out for now - we may want a more general API to do that
# accross all plugins at some point
return PluginUserApi(
self,
expose=(
Expand All @@ -119,6 +117,7 @@ def user_api(self):
"resource",
# Methods
"center_on_data",
"query_registry_resources",
"load_selected_data",
),
)
Expand Down Expand Up @@ -208,9 +207,13 @@ def center_on_data(self, event=None):

self.viewer_centered = True

@observe("waveband_selected", "change")
@with_spinner(spinner_traitlet="resources_loading")
@observe("waveband_selected", type="change")
def vue_query_registry_resources(self, _=None):
"""UI entrypoint for resource selection and manual resource refresh btn"""
self.query_registry_resources()

@with_spinner(spinner_traitlet="resources_loading")
def query_registry_resources(self, _=None):
"""
Query Virtual Observatory registry for all SIA services
that serve data in that waveband around the source.
Expand Down

0 comments on commit 920b4b8

Please sign in to comment.