Skip to content

tests: replace aioresponses with custom aiohttp mock, consolidate tests#205

Merged
firstof9 merged 1 commit into
mainfrom
custom-aiohttp-mock
Jun 3, 2026
Merged

tests: replace aioresponses with custom aiohttp mock, consolidate tests#205
firstof9 merged 1 commit into
mainfrom
custom-aiohttp-mock

Conversation

@firstof9

@firstof9 firstof9 commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Summary

Replaces the aioresponses third-party dependency with a custom AiohttpClientMocker class that patches aiohttp.ClientSession._request directly. Also consolidates several groups of redundant tests into parameterized equivalents.

Changes

requirements_test.txt

  • Removed aioresponses dependency

tests/conftest.py

  • Added MockResponse — a lightweight async context manager for mocked HTTP responses
  • Added AiohttpClientMocker — patches aiohttp.ClientSession._request to intercept requests, supporting:
    • Regex or exact URL matching (with full query string resolution via yarl)
    • repeat=True for indefinitely reusable mocks
    • exception=... for simulating network errors
  • Removed 5 redundant fixtures that are no longer needed:
    • test_lookup_tier_med, test_lookup_tier_high
    • test_lookup_monthly_tier_low, test_lookup_monthly_tier_med, test_lookup_monthly_tier_high

tests/test_init.py

  • Consolidated 6 individual tier rate tests → test_get_tier_rate_data (@pytest.mark.parametrize)
  • Consolidated 3 monthly tier rate tests → test_get_monthly_tier_rate_data (@pytest.mark.parametrize)
  • Consolidated 3 sell rate tests → test_get_sell_rate_data (@pytest.mark.parametrize)

Test Results

55 tests passing, ruff lint/format clean, mypy clean.

Summary by CodeRabbit

  • Tests
    • Refactored test infrastructure and fixtures to reduce code duplication.
    • Updated test mocking approach for improved maintainability.

- Remove aioresponses dependency from requirements_test.txt
- Implement AiohttpClientMocker class in tests/conftest.py that patches
  aiohttp.ClientSession._request directly, supporting regex URL matching,
  query parameter resolution, repeat, and exception kwargs
- Remove 5 redundant fixtures (test_lookup_tier_{med,high},
  test_lookup_monthly_tier_{low,med,high})
- Consolidate 6 individual tier rate tests into one parametrized
  test_get_tier_rate_data
- Consolidate 3 monthly tier rate tests into one parametrized
  test_get_monthly_tier_rate_data
- Consolidate 3 sell rate tests into one parametrized test_get_sell_rate_data
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ec6490bd-5c4d-4db9-b715-e67e8c0ad8d0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@firstof9 firstof9 merged commit 1a5a22d into main Jun 3, 2026
10 checks passed
@firstof9 firstof9 deleted the custom-aiohttp-mock branch June 3, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant