Skip to content

Commit

Permalink
WIP test for email verification
Browse files Browse the repository at this point in the history
  • Loading branch information
lkeegan committed Dec 5, 2024
1 parent 8865dc8 commit a681016
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions mondey_backend/tests/routers/test_auth.py
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

0 comments on commit a681016

Please sign in to comment.