Skip to content

fix(auth) :- resolve mock env TypeError in registration email dispatch - #83

Open
Aaravanand00 wants to merge 1 commit into
alphaonelabs:mainfrom
Aaravanand00:fix/auth-registration-email-handling
Open

Aaravanand00 wants to merge 1 commit into
alphaonelabs:mainfrom
Aaravanand00:fix/auth-registration-email-handling

Conversation

@Aaravanand00

Copy link
Copy Markdown

Summary of Changes

  • Fixed Email Provider Credential Extraction (src/worker.py):
    • Added safe string environment extractor helper _env_str() to verify values are actual strings before calling string methods or regex searches.
    • Previously, in test environments where env is a MagicMock, getattr(env, "MAILGUN_API_BASE", "").strip() produced another mock object rather than an empty string.
    • Passing this mock to re.search(r"/v\d+$", api_base) raised TypeError: expected string or bytes-like object, got 'MagicMock', which was breaking api_register and failing 5 registration unit tests.
    • Guarded provider availability checks before attempting URL formatting.
  • Added Clean Mock Env Defaults (tests/helpers.py):
    • Initialized default empty string bindings for SENDGRID_API_KEY, MAILGUN_API_KEY, MAILGUN_SENDING_KEY, MAILGUN_DOMAIN, and MAILGUN_API_BASE in make_env().

Testing & Verification

Ran pytest on auth and routing suites:

pytest tests/test_api_auth.py tests/test_dispatcher.py -v

Results:

============================= 54 passed in 1.59s ==============================

All 21 test_api_auth.py tests (including test_successful_registration, test_registration_sends_verification_message, test_name_defaults_to_username, test_custom_name_preserved, and test_register_is_rate_limited_per_ip) and all 33 test_dispatcher.py tests pass cleanly.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 0aac8b51-75dd-46a5-9716-f34d3d883027


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.

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