Skip to content

Commit 743e6b6

Browse files
committed
Add Metadata to CLI
1 parent 44123b7 commit 743e6b6

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

opus/cli/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ def data(argv=None, desc='Get Data from OPUS-SETI API', args=[], defaults={}, ap
6363
os.sys.exit(2)
6464

6565
return api.data(**vars(args))
66+
67+
68+
def metadata(argv=None, api=api):
69+
'''OPUS SETI API metadata entry point'''
70+
parser = argparse.ArgumentParser(description='Get detail for a single observation from OPUS-SETI API')
71+
parser.add_argument('ring_obs_id', help='Valid ring_obs_id')
72+
args, others = parser.parse_known_args(argv)
73+
74+
return api.metadata(args.ring_obs_id)

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ addopts = -vv --cov-report term-missing --cov-report html --cov-report xml
3434
[entry_points]
3535
console_scripts =
3636
opus = opus.cli:data
37+
opus-meta = opus.cli:metadata
3738
opus-vims = opus.cli.cassini:vims

tests/test_cli.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import six
55

66
from opus.api import API
7-
from opus.cli import read, data
7+
from opus.cli import read, data, metadata
88

99

1010
@pytest.fixture
@@ -84,3 +84,20 @@ def test_data_argv_none(api):
8484
with pytest.raises(SystemExit):
8585
resp = data(argv, api=api)
8686
assert len(responses.calls) == 0
87+
88+
89+
@responses.activate
90+
def test_cli_metadata(api):
91+
json = open('tests/api/metadata/S_IMG_CO_ISS_1459551972_N.json', 'r').read()
92+
responses.add(responses.GET,
93+
'http://localhost/metadata/S_IMG_CO_ISS_1459551972_N.json',
94+
body=json)
95+
96+
argv = ['S_IMG_CO_ISS_1459551972_N']
97+
resp = metadata(argv, api=api)
98+
99+
assert len(responses.calls) == 1
100+
assert responses.calls[0].request.url == 'http://localhost/metadata/S_IMG_CO_ISS_1459551972_N.json'
101+
assert responses.calls[0].response.text == json
102+
103+
assert resp.ring_obs_id == 'S_IMG_CO_ISS_1459551972_N'

0 commit comments

Comments
 (0)