-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import smtplib | ||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
|
||
class SMTPMock: | ||
msg = "" | ||
|
||
def __init__(self, *args, **kwargs): | ||
pass | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, *args): | ||
pass | ||
|
||
def send_message(self, msg: str): | ||
print(msg) | ||
SMTPMock.msg = msg | ||
|
||
|
||
@pytest.fixture | ||
def smtp_mock(monkeypatch: pytest.MonkeyPatch): | ||
monkeypatch.setattr(smtplib, "SMTP", SMTPMock) | ||
return SMTPMock | ||
|
||
|
||
def test_register_new_user(public_client: TestClient, smtp_mock: SMTPMock): | ||
assert smtp_mock.msg == "" | ||
response = public_client.post( | ||
"/auth/register", json={"email": "[email protected]", "password": "p1"} | ||
) | ||
assert response.status_code == 201 | ||
assert "mondey.lkeegan.dev/verify" in smtp_mock.msg |