Skip to content

Commit

Permalink
SDK-407, JUPY-884: Add '--upload-to-source' param for JupyterNotebook…
Browse files Browse the repository at this point in the history
…Command (#321)
  • Loading branch information
tgvr authored and chattarajoy committed Jun 3, 2020
1 parent ba1fbc5 commit 1311b39
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
17 changes: 14 additions & 3 deletions qds_sdk/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,9 +1387,10 @@ class JupyterNotebookCommand(Command):
optparser.add_option("--print-logs-live", action="store_true",
dest="print_logs_live", default=False, help="Fetch logs \
and print them to stderr while command is running.")
optparser.add_option("--skip-upload-to-source", action="store_false",
dest="upload_to_source", default=True, help="Do not \
upload notebook to source after completion of execution")
optparser.add_option("--upload-to-source", dest="upload_to_source", default='true',
help="Upload notebook to source after completion of \
execution. Specify the value as either 'true' or 'false'.\
Default value is 'true'.")

@classmethod
def parse(cls, args):
Expand Down Expand Up @@ -1417,6 +1418,16 @@ def parse(cls, args):
options.macros = validate_json_input(options.macros, 'Macros', cls)
if options.retry is not None:
options.retry = int(options.retry)
if options.upload_to_source is not None:
options.upload_to_source = options.upload_to_source.lower()
if options.upload_to_source == 'true':
options.upload_to_source = True
elif options.upload_to_source == 'false':
options.upload_to_source = False
else:
msg = "Upload to Source parameter takes a value of either 'true' \
or 'false' only."
raise ParseError(msg, cls.optparser.format_help())
except OptionParsingError as e:
raise ParseError(e.msg, cls.optparser.format_help())
except OptionParsingExit as e:
Expand Down
52 changes: 50 additions & 2 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2247,9 +2247,50 @@ def test_submit_pool(self):
'can_notify': False,
'pool': 'batch'})

def test_submit_skip_upload_to_source(self):
def test_submit_no_upload_to_source(self):
sys.argv = ['qds.py', 'jupyternotebookcmd', 'submit', '--path', 'folder/file']
print_command()
Connection._api_call = Mock(return_value={'id': 1234})
qds.main()
Connection._api_call.assert_called_with('POST', 'commands',
{'retry': None,
'name': None,
'tags': None,
'label': None,
'macros': None,
'arguments': None,
'timeout': None,
'path': 'folder/file',
'retry_delay': None,
'command_type': 'JupyterNotebookCommand',
'upload_to_source': True,
'can_notify': False,
'pool': None})

def test_submit_upload_to_source(self):
sys.argv = ['qds.py', 'jupyternotebookcmd', 'submit', '--path', 'folder/file',
'--upload-to-source', 'True']
print_command()
Connection._api_call = Mock(return_value={'id': 1234})
qds.main()
Connection._api_call.assert_called_with('POST', 'commands',
{'retry': None,
'name': None,
'tags': None,
'label': None,
'macros': None,
'arguments': None,
'timeout': None,
'path': 'folder/file',
'retry_delay': None,
'command_type': 'JupyterNotebookCommand',
'upload_to_source': True,
'can_notify': False,
'pool': None})

def test_submit_upload_to_source_false(self):
sys.argv = ['qds.py', 'jupyternotebookcmd', 'submit', '--path', 'folder/file',
'--skip-upload-to-source']
'--upload-to-source', 'False']
print_command()
Connection._api_call = Mock(return_value={'id': 1234})
qds.main()
Expand All @@ -2268,6 +2309,13 @@ def test_submit_skip_upload_to_source(self):
'can_notify': False,
'pool': None})

def test_submit_upload_to_source_wrong_param(self):
sys.argv = ['qds.py', 'jupyternotebookcmd', 'submit', '--path', 'folder/file',
'--upload-to-source', 'wrong']
print_command()
with self.assertRaises(qds_sdk.exception.ParseError):
qds.main()

def test_submit_retry(self):
sys.argv = ['qds.py', 'jupyternotebookcmd', 'submit', '--path', 'folder/file',
'--retry', '1']
Expand Down

0 comments on commit 1311b39

Please sign in to comment.