Skip to content

Commit

Permalink
Fix issue astropy#200 - treat keywords str value as single keyword
Browse files Browse the repository at this point in the history
Update changelog
  • Loading branch information
tomdonaldson committed Dec 18, 2019
1 parent d32a6de commit 6b02d3d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

- Handle description of None when describing a TAP service's tables. [#197]

- Properly handle single string keywords value for regsearch(). [#201]

1.0 (2019-09-20)
================

Expand Down
4 changes: 4 additions & 0 deletions docs/registry/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ quasars.

>>> services = regsearch(keywords=['quasar'])

A single keyword can be specified as a single string instead of a list.

>>> services = regsearch(keywords='quasar')

Furthermore the search can be limited to a certain ``servicetype``, one of
sia, ssa, scs, sla, tap.

Expand Down
5 changes: 4 additions & 1 deletion pyvo/registry/regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def search(keywords=None, servicetype=None, waveband=None, datamodel=None):
Parameters
----------
keywords : list of str
keywords : str or list of str
keyword terms to match to registry records.
Use this parameter to find resources related to a
particular topic.
Expand Down Expand Up @@ -87,6 +87,9 @@ def search(keywords=None, servicetype=None, waveband=None, datamodel=None):
wheres = list()
wheres.append("intf_role = 'std'")

if isinstance(keywords, str):
keywords = [keywords]

if keywords:
def _unions():
for i, keyword in enumerate(keywords):
Expand Down
31 changes: 31 additions & 0 deletions pyvo/registry/tests/test_regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ def keywordstest_callback(request, context):
yield matcher


@pytest.fixture()
def single_keyword_fixture(mocker):
def keywordstest_callback(request, context):
data = dict(parse_qsl(request.body))
query = data['QUERY']

assert "WHERE isub0.res_subject ILIKE '%single%'" in query
assert "WHERE 1=ivo_hasword(ires0.res_description, 'single')" in query
assert "OR 1=ivo_hasword(ires0.res_title, 'single')" in query

assert "'ivo://ivoa.net/std/conesearch'" in query
assert "'ivo://ivoa.net/std/sia'" in query
assert "'ivo://ivoa.net/std/ssa'" in query
assert "'ivo://ivoa.net/std/slap'" in query
assert "'ivo://ivoa.net/std/tap'" in query

return get_pkg_data_contents('data/regtap.xml')

with mocker.register_uri(
'POST', 'http://dc.g-vo.org/tap/sync',
content=keywordstest_callback
) as matcher:
yield matcher


@pytest.fixture()
def servicetype_fixture(mocker):
def servicetypetest_callback(request, context):
Expand Down Expand Up @@ -119,6 +144,12 @@ def test_keywords():
regsearch(keywords=['vizier', 'pulsar'])


@pytest.mark.usefixtures('single_keyword_fixture', 'capabilities')
def test_single_keyword():
regsearch(keywords=['single'])
regsearch(keywords='single')


@pytest.mark.usefixtures('servicetype_fixture', 'capabilities')
def test_servicetype():
regsearch(servicetype='tap')
Expand Down

0 comments on commit 6b02d3d

Please sign in to comment.