Skip to content

Commit 2ce9518

Browse files
authored
fix the bug (#47)
* fix the bug * update changelog * version bump * fix test * fix test for real * add test for OrderedDicts
1 parent dc0b394 commit 2ce9518

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
99
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.
1010

11+
## 0.5.2 - 2020-04-29
12+
13+
### Fixed
14+
15+
- Issue that prevented bulk csv loading.
16+
1117
## 0.5.1 - 2020-04-27
1218

1319
### Fixed

src/code42cli/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.5.1"
1+
__version__ = "0.5.2"

src/code42cli/bulk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def run(self):
8585
self._print_result()
8686

8787
def _process_row(self, row):
88-
if type(row) is dict:
88+
if isinstance(row, dict):
8989
self._process_csv_row(row)
9090
elif row:
9191
self._process_flat_file_row(row.strip())

tests/test_bulk.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import OrderedDict
12
from io import IOBase
23
import pytest
34

@@ -93,6 +94,28 @@ def test_run_bulk_process_when_not_given_reader_uses_csv_reader(bulk_processor_f
9394

9495

9596
class TestBulkProcessor(object):
97+
def test_run_when_reader_returns_ordered_dict_process_kwargs(self, mock_open):
98+
errors.ERRORED = False
99+
processed_rows = []
100+
101+
def func_for_bulk(test1, test2):
102+
processed_rows.append((test1, test2))
103+
104+
class MockDictReader(object):
105+
def __call__(self, *args, **kwargs):
106+
return [
107+
OrderedDict({"test1": 1, "test2": 2}),
108+
OrderedDict({"test1": 3, "test2": 4}),
109+
OrderedDict({"test1": 5, "test2": 6}),
110+
]
111+
112+
processor = BulkProcessor("some/path", func_for_bulk, MockDictReader())
113+
processor.run()
114+
assert (1, 2) in processed_rows
115+
assert (3, 4) in processed_rows
116+
assert (5, 6) in processed_rows
117+
118+
96119
def test_run_when_reader_returns_dict_process_kwargs(self, mock_open):
97120
errors.ERRORED = False
98121
processed_rows = []

tests/test_invoker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import pytest
22

3+
from requests.exceptions import HTTPError
4+
from requests import Response
5+
36
from py42.exceptions import Py42ForbiddenError
47

58
from code42cli import PRODUCT_NAME
@@ -74,8 +77,10 @@ def test_run_when_errors_occur_from_handler_calls_log_error(self, mocker, mock_p
7477

7578
def test_run_when_forbidden_error_occurs_prints_message(self, mocker, mock_parser, capsys):
7679
mocker.patch("{}.invoker.log_error".format(PRODUCT_NAME))
80+
http_error = mocker.MagicMock(spec=HTTPError)
81+
http_error.response = mocker.MagicMock(spec=Response)
7782
cmd = Command("", "top level desc", subcommand_loader=load_subcommands)
78-
mock_parser.parse_args.side_effect = Py42ForbiddenError(Exception())
83+
mock_parser.parse_args.side_effect = Py42ForbiddenError(http_error)
7984
mock_subparser = mocker.MagicMock()
8085
mock_parser.prepare_command.return_value = mock_subparser
8186
invoker = CommandInvoker(cmd, mock_parser)

0 commit comments

Comments
 (0)