-
Notifications
You must be signed in to change notification settings - Fork 8
Fix issue #54: Add SendingDomainsApi, related models, tests, examples #58
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
Conversation
WalkthroughAdds a Sending Domains feature: new pydantic models, an API resource class with CRUD and "send setup instructions" endpoints, client integration exposing the feature, example usage script, and unit tests covering success and error paths. Changes
Sequence Diagram(s)sequenceDiagram
participant User as Example Script / Caller
participant Client as MailtrapClient
participant BaseAPI as SendingDomainsBaseApi
participant ResAPI as SendingDomainsApi
participant HTTP as HttpClient
participant Models as Response Models
User->>Client: access sending_domains_api
Client->>Client: validate account_id
Client->>BaseAPI: construct with client & account_id
BaseAPI->>ResAPI: instantiate SendingDomainsApi
ResAPI-->>User: configured API returned
Note over User,ResAPI: Example flow — create then fetch
User->>ResAPI: create(CreateSendingDomainParams)
ResAPI->>ResAPI: build POST /api/accounts/{id}/sending_domains
ResAPI->>HTTP: POST request (body params)
HTTP-->>Models: return JSON
Models->>ResAPI: map to SendingDomain
ResAPI-->>User: return SendingDomain
User->>ResAPI: send_setup_instructions(id, SendSetupInstructionsParams)
ResAPI->>HTTP: POST /api/accounts/{id}/sending_domains/{id}/send_setup_instructions
HTTP-->>Models: return JSON {message}
Models->>ResAPI: map to SendSetupInstructionsResponse
ResAPI-->>User: return SendSetupInstructionsResponse
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (9)
🚧 Files skipped from review as they are similar to previous changes (6)
🧰 Additional context used🧬 Code graph analysis (2)mailtrap/client.py (3)
examples/sending_domains/sending_domains.py (5)
🪛 Ruff (0.14.6)examples/sending_domains/sending_domains.py6-6: Possible hardcoded password assigned to: "API_TOKEN" (S105) ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🔇 Additional comments (15)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
mailtrap/models/sending_domains.py (2)
16-23: DNS record model is straightforward; consider stricter types only if API is stableThe
DnsRecorddataclass cleanly mirrors a typical DNS record payload. If the API’sstatusortypefields have a known finite set of values, you might later considerLiteral[...]/Enumtypes for stronger validation, but it’s not required for this PR.
26-42:SendingDomainaggregation and defaults look correct; one minor optional improvement
- Composition of booleans, permissions, and
dns_recordsis consistent and matches how you’d typically model the resource.- Using
Field(default_factory=list)fordns_recordsavoids shared mutable defaults, which is correct in combination withpydantic.dataclasses.dataclass.- Optional string fields for
alert_recipient_emailanddns_verified_atwork fine withexclude_none=TrueinRequestParams.api_datafor request-type usage.If the backend returns
dns_verified_atas an ISO8601 timestamp and you want automatic parsing, you could switch that field toOptional[datetime]later; otherwise leaving it asstris perfectly acceptable.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
README.md(1 hunks)examples/sending_domains/sending_domains.py(1 hunks)mailtrap/__init__.py(1 hunks)mailtrap/api/resources/sending_domains.py(1 hunks)mailtrap/api/sending_domains.py(1 hunks)mailtrap/client.py(2 hunks)mailtrap/models/sending_domains.py(1 hunks)tests/unit/api/sending_domains/test_sending_domains.py(1 hunks)tests/unit/models/test_sending_domains.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
examples/sending_domains/sending_domains.py (4)
mailtrap/models/common.py (1)
DeletedObject(23-24)mailtrap/models/sending_domains.py (4)
SendingDomain(27-42)SendSetupInstructionsResponse(56-57)CreateSendingDomainParams(46-47)SendSetupInstructionsParams(51-52)mailtrap/client.py (1)
sending_domains_api(98-103)mailtrap/api/resources/sending_domains.py (5)
get_list(16-22)get_by_id(24-29)create(31-40)delete(42-47)send_setup_instructions(49-63)
tests/unit/models/test_sending_domains.py (1)
mailtrap/models/sending_domains.py (2)
CreateSendingDomainParams(46-47)SendSetupInstructionsParams(51-52)
mailtrap/models/sending_domains.py (2)
mailtrap/models/common.py (1)
RequestParams(13-19)mailtrap/api/general.py (1)
permissions(25-26)
mailtrap/api/sending_domains.py (2)
mailtrap/api/resources/sending_domains.py (1)
SendingDomainsApi(11-69)mailtrap/http.py (1)
HttpClient(14-106)
tests/unit/api/sending_domains/test_sending_domains.py (5)
mailtrap/api/resources/sending_domains.py (6)
SendingDomainsApi(11-69)get_list(16-22)get_by_id(24-29)create(31-40)delete(42-47)send_setup_instructions(49-63)mailtrap/http.py (2)
HttpClient(14-106)post(32-34)mailtrap/models/common.py (1)
DeletedObject(23-24)mailtrap/models/sending_domains.py (4)
CreateSendingDomainParams(46-47)SendingDomain(27-42)SendSetupInstructionsParams(51-52)SendSetupInstructionsResponse(56-57)mailtrap/client.py (1)
sending_domains_api(98-103)
mailtrap/__init__.py (2)
mailtrap/api/sending_domains.py (1)
sending_domains(11-12)mailtrap/models/sending_domains.py (2)
CreateSendingDomainParams(46-47)SendSetupInstructionsParams(51-52)
🪛 Ruff (0.14.6)
examples/sending_domains/sending_domains.py
6-6: Possible hardcoded password assigned to: "API_TOKEN"
(S105)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Test python3.9 on windows-latest
🔇 Additional comments (14)
README.md (1)
244-246: LGTM!The new Sending Domains API section follows the established documentation pattern and correctly links to the example file.
tests/unit/models/test_sending_domains.py (1)
1-14: LGTM!The model tests are well-structured and follow the existing test patterns. They correctly verify that the
api_dataproperty returns the expected dictionary for both parameter classes.mailtrap/client.py (1)
97-103: LGTM!The
sending_domains_apiproperty follows the established pattern used by other API properties in the client. It correctly validates the account_id and initializes the SendingDomainsBaseApi with the appropriate configuration.mailtrap/__init__.py (1)
33-34: LGTM!The new model exports follow the existing pattern and are properly placed in alphabetical order with other model imports.
mailtrap/api/sending_domains.py (1)
1-12: LGTM!The
SendingDomainsBaseApiclass follows the established pattern for base API wrappers in the codebase. It provides a clean abstraction layer for accessing the SendingDomainsApi with pre-configured account and client instances.tests/unit/api/sending_domains/test_sending_domains.py (1)
1-346: LGTM!This test suite is comprehensive and well-organized. It provides excellent coverage of all API methods with both success and error scenarios. The use of pytest fixtures and parametrization makes the tests clean and maintainable.
examples/sending_domains/sending_domains.py (1)
1-49: LGTM!The example script clearly demonstrates all available operations for the Sending Domains API. It follows the patterns established by other example scripts in the repository.
Note: The static analysis warning about a hardcoded password on line 6 is a false positive—this is just a placeholder string in example code that users need to replace with their actual API token.
mailtrap/api/resources/sending_domains.py (5)
16-22: LGTM!The
get_listmethod correctly handles the API response structure by extracting the "data" field with a defensive default. The list comprehension properly instantiates SendingDomain objects from the response data.
31-40: LGTM!The
createmethod properly wraps the domain parameters in a{"sending_domain": ...}structure, which aligns with the API's expected request format. The response is correctly parsed into a SendingDomain object.
42-47: LGTM!The
deletemethod follows a clean pattern by delegating to the HTTP client and returning a DeletedObject with the domain ID. This is consistent with similar delete operations in the codebase.
49-63: LGTM!The
send_setup_instructionsmethod correctly handles the 204 (No Content) response from the API by constructing a SendSetupInstructionsResponse with a descriptive success message. This is an appropriate pattern when the API doesn't return meaningful response data.
65-69: LGTM!The
_api_pathhelper method cleanly constructs API paths with optional domain ID. The implementation is straightforward and follows good practices.mailtrap/models/sending_domains.py (2)
9-13: Permissions model looks clean and sufficientThe
SendingDomainPermissionsdataclass is minimal, well-typed, and aligns with the common read/update/destroy permission pattern. No changes needed here.
45-57: Params/response modeling is compatible withRequestParams.api_data
CreateSendingDomainParamsandSendSetupInstructionsParamsinheriting fromRequestParamsas pydantic dataclasses should integrate cleanly with the existingapi_datahelper (single required field each, no defaults).SendSetupInstructionsResponseas a simple dataclass withmessage: strmatches a typical API “acknowledge” payload and will be easy to validate/serialize via pydantic.No issues spotted here.
Motivation
In this MR I added SendingDomainsApi, related models, tests, examples.
Changes
README.md updated with new link to examples
Change 1
Change 2
How to test
Summary by CodeRabbit
New Features
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.