Skip to content

Commit

Permalink
Lint fixes with black
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurk93 committed Jan 5, 2024
1 parent 4678078 commit e632b48
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
14 changes: 9 additions & 5 deletions secureli/actions/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,21 @@ def scan_repo(
scan_result.failures
)

log_data = self.logging.success(LogAction.scan) if scan_result.successful else self.logging.failure(
log_data = (
self.logging.success(LogAction.scan)
if scan_result.successful
else self.logging.failure(
LogAction.scan,
scan_result_failures_json_string,
failure_count,
individual_failure_count,
)
)
self.publish_results(
publish_results_condition,
action_successful=scan_result.successful,
log_str=log_data.json(exclude_none=True),
)
publish_results_condition,
action_successful=scan_result.successful,
log_str=log_data.json(exclude_none=True),
)
if scan_result.successful:
self.echo.print("Scan executed successfully and detected no issues!")
else:
Expand Down
34 changes: 17 additions & 17 deletions tests/actions/test_scan_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ def scan_action(
scanner=action_deps.scanner,
)


@pytest.fixture()
def mock_post_log(mocker: MockerFixture) -> MagicMock:
return mocker.patch('secureli.actions.scan.post_log')
return mocker.patch("secureli.actions.scan.post_log")


# @mock.patch.dict(os.environ, {"API_KEY": "", "API_ENDPOINT": ""}, clear=True)
# def test_that_scan_repo_errors_if_not_successful(
Expand Down Expand Up @@ -286,35 +288,33 @@ def test_that_scan_update_check_updates_last_check_time(
mock_secureli_config.save.assert_called_once()
assert mock_secureli_config.save.call_args.args[0].last_hook_update_check == 1e6

def test_publish_results_always(
scan_action: ScanAction,
mock_post_log: MagicMock
):

def test_publish_results_always(scan_action: ScanAction, mock_post_log: MagicMock):
mock_post_log.return_value.result = Result.SUCCESS
mock_post_log.return_value.result_message = 'Success'
mock_post_log.return_value.result_message = "Success"

scan_action.publish_results(PublishResultsOption.ALWAYS, True, 'log_str')
scan_action.publish_results(PublishResultsOption.ALWAYS, True, "log_str")

mock_post_log.assert_called_once_with('log_str')
mock_post_log.assert_called_once_with("log_str")
scan_action.logging.success.assert_called_once_with(LogAction.publish)


def test_publish_results_on_fail_and_action_successful(
scan_action: ScanAction,
mock_post_log: MagicMock
scan_action: ScanAction, mock_post_log: MagicMock
):
scan_action.publish_results(PublishResultsOption.ON_FAIL, True, 'log_str')
scan_action.publish_results(PublishResultsOption.ON_FAIL, True, "log_str")

mock_post_log.assert_not_called()
scan_action.logging.success.assert_not_called()


def test_publish_results_on_fail_and_action_not_successful(
scan_action: ScanAction,
mock_post_log: MagicMock
scan_action: ScanAction, mock_post_log: MagicMock
):
mock_post_log.return_value.result = Result.FAILURE
mock_post_log.return_value.result_message = 'Failure'
mock_post_log.return_value.result_message = "Failure"

scan_action.publish_results(PublishResultsOption.ON_FAIL, False, 'log_str')
scan_action.publish_results(PublishResultsOption.ON_FAIL, False, "log_str")

mock_post_log.assert_called_once_with('log_str')
scan_action.logging.failure.assert_called_once_with(LogAction.publish, 'Failure')
mock_post_log.assert_called_once_with("log_str")
scan_action.logging.failure.assert_called_once_with(LogAction.publish, "Failure")

0 comments on commit e632b48

Please sign in to comment.