Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-407, JUPY-884: Add '--upload-to-source' param for JupyterNotebookCommand #321

Merged
merged 6 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 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