-
Notifications
You must be signed in to change notification settings - Fork 0
Add unit tests for email sender #9
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
…into feature/notifications
…into test/email_sender
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||
…into test/email_sender
app/core/tests/test_email_sender.py
Outdated
| class ConcreteSender(EmailSender): | ||
| @override | ||
| async def send_email(self, email: Email) -> str: | ||
| return await super().send_email(email) # type: ignore |
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.
Remove concrete sender and use the base sender
app/core/tests/test_email_sender.py
Outdated
| @pytest.fixture | ||
| def email_factory(email_templates: tuple[Path, Path]): | ||
| html_template, text_template = email_templates | ||
|
|
||
| def _create_email( | ||
| sender: str = "test@testmail.com", | ||
| receivers: list[EmailStr] | None = None, | ||
| subject: str = "Test", | ||
| template_data: dict[str, object] | None = None, | ||
| ): | ||
| return Email( | ||
| sender=sender, | ||
| receivers=receivers or ["receiver@testemail.com"], | ||
| subject=subject, | ||
| body_html_template=html_template, | ||
| body_text_template=text_template, | ||
| template_data=template_data or {"name": "TestUser"}, | ||
| ) | ||
|
|
||
| return _create_email |
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.
Try to use factory-boy library
Or try to use email_fixture directly
If using this fixture, rename to email_factory_fixture
app/core/tests/test_email_sender.py
Outdated
|
|
||
|
|
||
| def test_get_email_sender_raises_not_implemented_error_for_invalid_email_sender_types(settings_fixture: SettingsDep): | ||
| settings_fixture.email_sender_type = "invalid" # type: ignore |
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.
Narrow the type ignore to the specific type check
app/conftest.py
Outdated
| @pytest.fixture | ||
| def email_templates(tmp_path: Path) -> tuple[Path, Path]: | ||
| html_template = tmp_path / "test.mjml" | ||
| text_template = tmp_path / "test.txt" | ||
|
|
||
| _ = html_template.write_text(""" | ||
| <mjml> | ||
| <mj-body> | ||
| <mj-text>Hello {{ name}}</mj-text> | ||
| </mj-body> | ||
| </mjml> | ||
| """) | ||
|
|
||
| _ = text_template.write_text("Hello {{ name }}") | ||
|
|
||
| return html_template, text_template | ||
|
|
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.
Move this to test_email_sender file
app/conftest.py
Outdated
| @pytest.fixture | ||
| def fake_settings(settings_fixture: Settings) -> Settings: | ||
| return settings_fixture |
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.
Remove this
Summary
Checklist
Screenshots
Screenshots of the API documentation (swagger) or other relevant artifacts associated with this PR (if applicable).