Skip to content

Commit

Permalink
mock report status
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshalX committed Dec 4, 2023
1 parent 0f25dc8 commit 094a260
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tests/cli/test_main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json
from typing import TYPE_CHECKING
from uuid import uuid4

import pytest
import responses
from click.testing import CliRunner

from cycode.cli.main import main_cli
from tests.conftest import CLI_ENV_VARS, TEST_FILES_PATH, ZIP_CONTENT_PATH
from tests.cyclient.mocked_responses.scan_client import mock_scan_responses
from tests.cyclient.test_scan_client import get_zipped_file_scan_response, get_zipped_file_scan_url

_PATH_TO_SCAN = TEST_FILES_PATH.joinpath('zip_content').absolute()
Expand All @@ -27,12 +29,11 @@ def _is_json(plain: str) -> bool:
@pytest.mark.parametrize('output', ['text', 'json'])
def test_passing_output_option(output: str, scan_client: 'ScanClient', api_token_response: responses.Response) -> None:
scan_type = 'secret'
scan_id = uuid4()

mock_scan_responses(responses, scan_type, scan_client, scan_id, ZIP_CONTENT_PATH)
responses.add(get_zipped_file_scan_response(get_zipped_file_scan_url(scan_type, scan_client), ZIP_CONTENT_PATH))
responses.add(api_token_response)
# Scan report is not mocked.
# This raises connection error on the attempt to report scan.
# It doesn't perform real request

args = ['--output', output, 'scan', '--soft-fail', 'path', str(_PATH_TO_SCAN)]
result = CliRunner().invoke(main_cli, args, env=CLI_ENV_VARS)
Expand Down
9 changes: 9 additions & 0 deletions tests/cyclient/mocked_responses/scan_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,12 @@ def mock_scan_async_responses(
responses_module.add(get_scan_detections_count_response(get_scan_detections_count_url(scan_client)))
responses_module.add(get_scan_detections_response(get_scan_detections_url(scan_client), scan_id, zip_content_path))
responses_module.add(get_report_scan_status_response(get_report_scan_status_url(scan_type, scan_id, scan_client)))


def mock_scan_responses(
responses_module: responses, scan_type: str, scan_client: ScanClient, scan_id: UUID, zip_content_path: Path
) -> None:
responses_module.add(
get_zipped_file_scan_response(get_zipped_file_scan_url(scan_type, scan_client), zip_content_path)
)
responses_module.add(get_report_scan_status_response(get_report_scan_status_url(scan_type, scan_id, scan_client)))

0 comments on commit 094a260

Please sign in to comment.