Skip to content

Commit

Permalink
HARMONY-1764: Add --harmony-input-file to known arguments and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
indiejames committed May 16, 2024
1 parent c1c1687 commit a861530
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions harmony/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def setup_cli(parser):
parser.add_argument('--harmony-input',
help=('the input data for the action provided by Harmony, required for '
'--harmony-action=invoke'))
parser.add_argument('--harmony-input-file',
help=('the optional path to the input data for the action provided by Harmony, required for '))
parser.add_argument('--harmony-sources',
help=('file path that contains a STAC catalog with items and metadata to '
'be processed by the service. Required for non-deprecated '
Expand Down
13 changes: 12 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import unittest
from unittest.mock import patch

Expand Down Expand Up @@ -50,8 +51,11 @@ def test_when_passing_nothing_it_returns_false(self, parser):
class TestCliInvokeAction(unittest.TestCase):
def setUp(self):
self.config = harmony.util.config(validate=False)
with open('/tmp/operation.json', 'w') as f:
f.write('{"test": "input"}')

def tearDown(self):
os.remove('/tmp/operation.json')
MockAdapter.messages = []
MockAdapter.errors = []
MockAdapter.cleaned_up = []
Expand All @@ -62,14 +66,21 @@ def test_when_harmony_input_is_not_provided_it_terminates_with_error(self, parse
args = parser.parse_args()
cli.run_cli(parser, args, MockAdapter, self.config)
error_method.assert_called_once_with(
'--harmony-input must be provided for --harmony-action=invoke')
'--harmony-input or --harmony-input-file must be provided for --harmony-action=invoke')

@cli_test('--harmony-action', 'invoke', '--harmony-input', '{"test": "input"}')
def test_when_harmony_input_is_provided_it_creates_and_invokes_an_adapter(self, parser):
args = parser.parse_args()
cli.run_cli(parser, args, MockAdapter, self.config)
self.assertListEqual([{'test': 'input'}], MockAdapter.messages)

@cli_test('--harmony-action', 'invoke', '--harmony-input-file', '/tmp/operation.json')
def test_when_harmony_input_file_is_provided_it_creates_and_invokes_an_adapter(self, parser):
args = parser.parse_args()

cli.run_cli(parser, args, MockAdapter, self.config)
self.assertListEqual([{'test': 'input'}], MockAdapter.messages)

@cli_test('--harmony-action', 'invoke', '--harmony-input', '{"test": "input"}')
def test_when_the_backend_service_doesnt_respond_it_responds_with_an_error(self, parser):
class MockImpl(MockAdapter):
Expand Down

0 comments on commit a861530

Please sign in to comment.