Example #1
0
    def test_run_when_reader_returns_ordered_dict_process_kwargs(self):
        processed_rows = []

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

        rows = [
            OrderedDict({
                "test1": 1,
                "test2": 2
            }),
            OrderedDict({
                "test1": 3,
                "test2": 4
            }),
            OrderedDict({
                "test1": 5,
                "test2": 6
            }),
        ]
        processor = BulkProcessor(func_for_bulk, rows)
        processor.run()
        assert (1, 2) in processed_rows
        assert (3, 4) in processed_rows
        assert (5, 6) in processed_rows
Example #2
0
    def test_run_when_dict_reader_has_none_for_key_ignores_key(self):
        processed_rows = []

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

        rows = [{"test1": 1, None: 2}]
        processor = BulkProcessor(func_for_bulk, rows)
        processor.run()
        assert processed_rows == [1]
Example #3
0
    def test_processor_stores_results_in_stats(self, ):
        def func_for_bulk(test):
            return test

        rows = ["row1", "row2", "row3"]
        processor = BulkProcessor(func_for_bulk, rows)
        processor.run()
        assert "row1" in processor._stats.results
        assert "row2" in processor._stats.results
        assert "row3" in processor._stats.results
Example #4
0
    def test_run_when_no_errors_occur_does_not_print_error_message(
            self, capsys):
        def func_for_bulk(test):
            pass

        rows = ["row1", "row2", "row3"]
        processor = BulkProcessor(func_for_bulk, rows)

        processor.run()
        output = capsys.readouterr()
        assert get_view_error_details_message() not in output.out
Example #5
0
    def test_run_when_error_occurs_raises_expected_logged_cli_error(self):
        def func_for_bulk(test):
            if test == "row2":
                raise Exception()

        rows = ["row1", "row2", "row3"]
        with pytest.raises(errors.LoggedCLIError) as err:
            processor = BulkProcessor(func_for_bulk, rows)
            processor.run()

        assert err.value.message == "Some problems occurred during bulk processing."
Example #6
0
    def test_run_when_reader_returns_dict_rows_containing_empty_strs_converts_them_to_none(
        self, ):
        processed_rows = []

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

        rows = [{"test1": "", "test2": "foo"}, {"test1": "bar", "test2": ""}]
        processor = BulkProcessor(func_for_bulk, rows)
        processor.run()
        assert (None, "foo") in processed_rows
        assert ("bar", None) in processed_rows
Example #7
0
    def test_run_when_reader_returns_strs_processes_strs(self):
        processed_rows = []

        def func_for_bulk(test):
            processed_rows.append(test)

        rows = ["row1", "row2", "row3"]
        processor = BulkProcessor(func_for_bulk, rows)
        processor.run()
        assert "row1" in processed_rows
        assert "row2" in processed_rows
        assert "row3" in processed_rows
Example #8
0
    def test_run_when_row_is_endline_does_not_process_row(self):
        processed_rows = []

        def func_for_bulk(test):
            processed_rows.append(test)

        rows = ["row1", "row2", "\n"]
        processor = BulkProcessor(func_for_bulk, rows)
        processor.run()

        assert "row1" in processed_rows
        assert "row2" in processed_rows
        assert "row3" not in processed_rows