Skip to content

Commit 81600c6

Browse files
authored
remove broken OutputFormat.echo_formatted_generated_output() (#322)
* remove broken OutputFormat.echo_formatted_generated_output() * "no results" message to stderr * revert header params * changelog update * exclude flake8 rule * black
1 parent 9ab3328 commit 81600c6

File tree

5 files changed

+16
-38
lines changed

5 files changed

+16
-38
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
2222

2323
- `code42 profile use` now prompts you to select a profile when not given a profile name argument.
2424

25+
### Fixed
26+
27+
- Bug where `audit-logs search` with `--use-checkpoint` option was causing output formatting problems.
28+
2529
## 1.9.0 - 2021-08-19
2630

2731
### Added

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ ignore =
2727
E722
2828
# binary operation line break, different opinion from black
2929
W503
30+
# exception chaining
31+
B904
3032
# up to 88 allowed by bugbear B950
3133
max-line-length = 80

src/code42cli/cmds/auditlogs.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,20 @@ def search(
141141
affected_user_ids=affected_user_id,
142142
affected_usernames=affected_username,
143143
)
144-
if not events:
145-
click.echo("No results found.")
146-
return
147144

148145
if use_checkpoint:
149146
checkpoint_name = use_checkpoint
150-
events_gen = _dedupe_checkpointed_events_and_store_updated_checkpoint(
151-
cursor, checkpoint_name, events
147+
events = list(
148+
_dedupe_checkpointed_events_and_store_updated_checkpoint(
149+
cursor, checkpoint_name, events
150+
)
152151
)
153-
formatter.echo_formatted_generated_output(events_gen)
154-
else:
155-
formatter.echo_formatted_list(events)
152+
153+
if not events:
154+
click.echo("No results found.", err=True)
155+
return
156+
157+
formatter.echo_formatted_list(events)
156158

157159

158160
@audit_logs.command(cls=SendToCommand)

src/code42cli/output_formats.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,6 @@ def echo_formatted_list(self, output_list, force_pager=False):
7979
if self.output_format in [OutputFormat.TABLE]:
8080
click.echo()
8181

82-
def echo_formatted_generated_output(self, output_generator):
83-
def _gen():
84-
include_header = True
85-
for output in output_generator:
86-
if output:
87-
formatted_output = self._format_output(
88-
output, include_header=include_header
89-
)
90-
yield formatted_output
91-
include_header = False
92-
93-
click.echo_via_pager(_gen)
94-
9582
@property
9683
def _requires_list_output(self):
9784
return self.output_format in (OutputFormat.TABLE, OutputFormat.CSV)

tests/cmds/test_auditlogs.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -586,23 +586,6 @@ def test_search_and_send_when_timestamps_have_nanoseconds_saves_checkpoint(
586586
assert call_args[0][1] == 1625150833.093616
587587

588588

589-
def test_search_if_error_occurs_when_processing_event_timestamp_still_outputs_results(
590-
cli_state,
591-
runner,
592-
mock_audit_log_response_with_error_causing_timestamp,
593-
audit_log_cursor_with_checkpoint,
594-
):
595-
cli_state.sdk.auditlogs.get_all.return_value = (
596-
mock_audit_log_response_with_error_causing_timestamp
597-
)
598-
res = runner.invoke(
599-
cli, ["audit-logs", "search", "--use-checkpoint", "test"], obj=cli_state,
600-
)
601-
assert TEST_AUDIT_LOG_TIMESTAMP_1 in res.output
602-
assert "I AM NOT A TIMESTAMP" in res.output
603-
assert "Error: Unknown problem occurred." in res.output
604-
605-
606589
def test_search_if_error_occurs_when_processing_event_timestamp_does_not_store_error_timestamp(
607590
cli_state,
608591
runner,

0 commit comments

Comments
 (0)