Skip to content

Commit

Permalink
Merge pull request #114 from phac-nml/fix_batch_not_starting
Browse files Browse the repository at this point in the history
Fixed batch uploads crashing, added unit tests to catch errors
  • Loading branch information
deepsidhu85 authored Jun 8, 2021
2 parents 76ae493 + d387ded commit 188b172
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changes
=======

Beta 0.6.1
----------
Bug fixes:
* Fixed issue where starting a batch upload from the command line would crash instead of running.

Beta 0.6.0
----------
Added functionality:
Expand Down
2 changes: 1 addition & 1 deletion iridauploader/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION_NUMBER = "0.6.0"
VERSION_NUMBER = "0.6.1"
2 changes: 1 addition & 1 deletion iridauploader/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def main():

# Start Upload
if args.batch:
return upload_batch(args.directory, args.force, args.upload_mode, args.coninue_partial)
return upload_batch(args.directory, args.force, args.upload_mode, args.continue_partial)
else:
return upload(args.directory, args.force, args.upload_mode, args.continue_partial)

Expand Down
122 changes: 122 additions & 0 deletions iridauploader/tests/core/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import unittest
from unittest.mock import patch
from os import path

from iridauploader.core import cli

path_to_module = path.abspath(path.dirname(__file__))
if len(path_to_module) == 0:
path_to_module = '.'


class TestCliEntryPoints(unittest.TestCase):
"""
Tests the core.cli package entry points into core.upload via main()
"""

def setUp(self):
print("\nStarting " + self.__module__ + ": " + self._testMethodName)

@patch("iridauploader.core.upload.upload_run_single_entry")
@patch("iridauploader.core.cli._config_uploader")
@patch("iridauploader.core.cli.init_argparser")
def test_upload_regular(self, mock_init_argparser, mock_configure_uploader, mock_upload_run_single_entry):

class StubArgs:
"""
Contains dummy properties that mimic the actual arguments object
"""
@property
def directory(self):
return path_to_module

@property
def force(self):
return False

@property
def continue_partial(self):
return False

@property
def batch(self):
return False

@property
def upload_mode(self):
return None

stub_args_object = StubArgs()
# stub_argparser returns the above args object
stub_argparser = unittest.mock.MagicMock()
stub_argparser.parse_args.side_effect = [stub_args_object]
# mock_init_argparser returns the above stub_argparser, which contains the args object
mock_init_argparser.side_effect = [stub_argparser]

mock_configure_uploader.side_effect = [None]
# mock the core code exiting
stub_upload_exit = unittest.mock.MagicMock()
stub_upload_exit.exit_code.side_effect = 0
mock_upload_run_single_entry.side_effect = [stub_upload_exit]

cli.main()

# ensure the configuration is called
mock_configure_uploader.assert_called_once_with(stub_args_object)
# Verify final call
mock_upload_run_single_entry.assert_called_once_with(stub_args_object.directory,
stub_args_object.force,
stub_args_object.upload_mode,
stub_args_object.continue_partial)

@patch("iridauploader.core.upload.batch_upload_single_entry")
@patch("iridauploader.core.cli._config_uploader")
@patch("iridauploader.core.cli.init_argparser")
def test_upload_batch(self, mock_init_argparser, mock_configure_uploader, mock_batch_upload_single_entry):

class StubArgs:
"""
Contains dummy properties that mimic the actual arguments object
"""
@property
def directory(self):
return path_to_module

@property
def force(self):
return False

@property
def continue_partial(self):
return False

@property
def batch(self):
return True

@property
def upload_mode(self):
return None

stub_args_object = StubArgs()
# stub_argparser returns the above args object
stub_argparser = unittest.mock.MagicMock()
stub_argparser.parse_args.side_effect = [stub_args_object]
# mock_init_argparser returns the above stub_argparser, which contains the args object
mock_init_argparser.side_effect = [stub_argparser]

mock_configure_uploader.side_effect = [None]
# mock the core code exiting
stub_upload_exit = unittest.mock.MagicMock()
stub_upload_exit.exit_code.side_effect = 0
mock_batch_upload_single_entry.side_effect = [stub_upload_exit]

cli.main()

# ensure the configuration is called
mock_configure_uploader.assert_called_once_with(stub_args_object)
# Verify final call
mock_batch_upload_single_entry.assert_called_once_with(stub_args_object.directory,
stub_args_object.force,
stub_args_object.upload_mode,
stub_args_object.continue_partial)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name='iridauploader',
version='0.6.0',
version='0.6.1',
description='IRIDA uploader: upload NGS data to IRIDA system',
url='https://github.com/phac-nml/irida-uploader',
author='Jeffrey Thiessen',
Expand Down
2 changes: 1 addition & 1 deletion windows-installer.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Application]
name=IRIDA Uploader GUI
version=0.6.0
version=0.6.1
entry_point=iridauploader.gui.gui:main
icon=iridauploader/gui/images/icon.ico
# Uncomment this to have a console show alongside the application
Expand Down

0 comments on commit 188b172

Please sign in to comment.