Skip to content

Support sandbox and bulk modes #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: deprecate-dead-python-versions
Choose a base branch
from

Conversation

andrii-porokhnavets
Copy link
Contributor

@andrii-porokhnavets andrii-porokhnavets commented Apr 30, 2025

Motivation

Changes

  • Add sanbox mode support in MailtrapClient
    • It requires inbox_id parameter to be set
  • Add bulk mode support in MailtrapClient
  • Bumb tool versions
  • Remove non-supported python versions (3.6, 3.7, 3.8) from CI

How to test

  • Test bulk email sending (bulk=True)
  • Test sandbox email sending (sandbox=True, inbox_id=123)
  • Regression for regular email sending

@andrii-porokhnavets andrii-porokhnavets marked this pull request as ready for review April 30, 2025 08:29
@andrii-porokhnavets andrii-porokhnavets changed the title support-sandbox-env Support sandbox and bulk modes Apr 30, 2025
Copy link

@sebaszap123-dev sebaszap123-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall! Just suggested improving the _host logic to make it more flexible and future-proof in case the sandbox host changes or needs to be overridden. Also added an exception to clarify errors when inbox_id is missing in sandbox mode. Great work so far!

Comment on lines +72 to +79
@property
def _host(self) -> str:
if self.api_host:
return self.api_host
if self.sandbox:
return self.SANDBOX_HOST
if self.bulk:
return self.BULK_HOST
return self.DEFAULT_HOST

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should find a way to make it more flexible for future changes—hopefully unnecessary—but what if the sandbox host changes? In that case, we wouldn’t be able to handle it.

Suggested change
@property
def _host(self) -> str:
if self.api_host:
return self.api_host
if self.sandbox:
return self.SANDBOX_HOST
if self.bulk:
return self.BULK_HOST
return self.DEFAULT_HOST
@property
def _host(self) -> str:
if self.api_host and self.sandbox:
return self.api_host
if self.api_host and self.bulk:
return self.api_host
if self.sandbox:
return self.SANDBOX_HOST
if self.bulk:
return self.BULK_HOST
if self.api_host:
return self.api_host
return self.DEFAULT_HOST

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's doubtful that the host will be changed, but the client supports api_host, which has the highest priority and always takes part of the API URL if it's present, regardless of other parameters.

Introduced `sandbox` mode, allowing configuration for sandbox environments via `inbox_id`. Implemented validation to ensure correct usage of `sandbox` and `inbox_id`, along with related tests. Updated URL generation logic and error handling for enhanced flexibility.
Introduce a new `bulk` mode in the Mailtrap client, setting a dedicated `BULK_HOST` for bulk operations. Updated validation logic to prevent conflicts between bulk and sandbox modes. Added corresponding test cases to ensure correct functionality and URL generation.
@andrii-porokhnavets andrii-porokhnavets changed the base branch from main to deprecate-dead-python-versions May 1, 2025 08:53
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.

3 participants