Skip to content

fix the bug #47

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

Merged
merged 6 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.

## 0.5.2 - 2020-04-29

### Fixed

- Issue that prevented bulk csv loading.

## 0.5.1 - 2020-04-27

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/code42cli/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.1"
__version__ = "0.5.2"
2 changes: 1 addition & 1 deletion src/code42cli/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def run(self):
self._print_result()

def _process_row(self, row):
if type(row) is dict:
if isinstance(row, dict):
self._process_csv_row(row)
elif row:
self._process_flat_file_row(row.strip())
Expand Down
23 changes: 23 additions & 0 deletions tests/test_bulk.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import OrderedDict
from io import IOBase
import pytest

Expand Down Expand Up @@ -93,6 +94,28 @@ def test_run_bulk_process_when_not_given_reader_uses_csv_reader(bulk_processor_f


class TestBulkProcessor(object):
def test_run_when_reader_returns_ordered_dict_process_kwargs(self, mock_open):
errors.ERRORED = False
processed_rows = []

def func_for_bulk(test1, test2):
processed_rows.append((test1, test2))

class MockDictReader(object):
def __call__(self, *args, **kwargs):
return [
OrderedDict({"test1": 1, "test2": 2}),
OrderedDict({"test1": 3, "test2": 4}),
OrderedDict({"test1": 5, "test2": 6}),
]

processor = BulkProcessor("some/path", func_for_bulk, MockDictReader())
processor.run()
assert (1, 2) in processed_rows
assert (3, 4) in processed_rows
assert (5, 6) in processed_rows


def test_run_when_reader_returns_dict_process_kwargs(self, mock_open):
errors.ERRORED = False
processed_rows = []
Expand Down
7 changes: 6 additions & 1 deletion tests/test_invoker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest

from requests.exceptions import HTTPError
from requests import Response

from py42.exceptions import Py42ForbiddenError

from code42cli import PRODUCT_NAME
Expand Down Expand Up @@ -74,8 +77,10 @@ def test_run_when_errors_occur_from_handler_calls_log_error(self, mocker, mock_p

def test_run_when_forbidden_error_occurs_prints_message(self, mocker, mock_parser, capsys):
mocker.patch("{}.invoker.log_error".format(PRODUCT_NAME))
http_error = mocker.MagicMock(spec=HTTPError)
http_error.response = mocker.MagicMock(spec=Response)
cmd = Command("", "top level desc", subcommand_loader=load_subcommands)
mock_parser.parse_args.side_effect = Py42ForbiddenError(Exception())
mock_parser.parse_args.side_effect = Py42ForbiddenError(http_error)
mock_subparser = mocker.MagicMock()
mock_parser.prepare_command.return_value = mock_subparser
invoker = CommandInvoker(cmd, mock_parser)
Expand Down