Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
Add test for failure to fetch manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
ramosbugs committed Nov 10, 2023
1 parent e3793a3 commit a7b5043
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 104 deletions.
25 changes: 16 additions & 9 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,11 @@ def assert_regex(regex: str, string: str) -> None:
assert re.match(regex, string) is not None, f'`{string}` does not match regex {regex}'


@requests_mock.Mocker(case_sensitive=True, kw='requests_mocker')
def run_test_case(
pytester: pytest.Pytester,
requests_mock: requests_mock.Mocker,
manifest: _api.TestSuiteManifest,
manifest: Optional[_api.TestSuiteManifest],
requests_mocker: requests_mock.Mocker,
expected_test_file_outcomes: List[
Tuple[str, List[Tuple[Tuple[str, ...], List[_TestAttemptOutcome]]]]],
expected_test_result_counts: _TestResultCounts,
Expand All @@ -266,15 +267,21 @@ def run_test_case(
expect_xdist: bool = False,
) -> None:
api_key_path = pytester.makefile('', expected_api_key) if use_api_key_path else None
requests_mock.get(
requests_mocker.get(
url='https://app.unflakable.com/api/v1/test-suites/MOCK_SUITE_ID/manifest',
request_headers={'Authorization': f'Bearer {expected_api_key}'},
complete_qs=True,
status_code=200,
json=manifest,
**(
{
'status_code': 200,
'json': manifest,
} if manifest is not None else {
'exc': requests.exceptions.ConnectTimeout
} # type: ignore
),
)

requests_mock.post(
requests_mocker.post(
url='https://app.unflakable.com/api/v1/test-suites/MOCK_SUITE_ID/runs',
request_headers={
'Authorization': f'Bearer {expected_api_key}',
Expand Down Expand Up @@ -482,7 +489,7 @@ def run_test_case(
expected_test_result_counts.non_skipped_tests > 0) else [])
)

assert requests_mock.call_count == (
assert requests_mocker.call_count == (
(
2 if expected_uploaded_test_runs is not None and (
expected_test_result_counts.non_skipped_tests > 0) else 1
Expand All @@ -491,7 +498,7 @@ def run_test_case(

# Checked expected User-Agent. We do this here instead of using an `additional_matcher` to make
# errors easier to diagnose.
for request in requests_mock.request_history:
for request in requests_mocker.request_history:
assert_regex(
r'^unflakable-pytest-plugin/.* \(PyTest .*; Python .*; Platform .*\)$',
request.headers.get('User-Agent', '')
Expand All @@ -500,7 +507,7 @@ def run_test_case(
if plugin_enabled and (
expected_uploaded_test_runs is not None and
expected_test_result_counts.non_skipped_tests > 0):
create_test_suite_run_request = requests_mock.request_history[1]
create_test_suite_run_request = requests_mocker.request_history[1]
assert create_test_suite_run_request.url == (
'https://app.unflakable.com/api/v1/test-suites/MOCK_SUITE_ID/runs')
assert create_test_suite_run_request.method == 'POST'
Expand Down
Loading

0 comments on commit a7b5043

Please sign in to comment.