mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-11-01 01:48:46 +08:00
* Add unit tests to enforce email case insensitivity * Handle email as case insentitive while retrieving user in DB * Apply isort/black * Add migration doc
This commit is contained in:
@ -65,18 +65,24 @@ class TestRegister:
|
||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||
assert after_register.called is False
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"email", ["king.arthur@camelot.bt", "King.Arthur@camelot.bt"]
|
||||
)
|
||||
async def test_existing_user(
|
||||
self, test_app_client: httpx.AsyncClient, after_register
|
||||
self, email, test_app_client: httpx.AsyncClient, after_register
|
||||
):
|
||||
json = {"email": "king.arthur@camelot.bt", "password": "guinevere"}
|
||||
json = {"email": email, "password": "guinevere"}
|
||||
response = await test_app_client.post("/register", json=json)
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
data = cast(Dict[str, Any], response.json())
|
||||
assert data["detail"] == ErrorCode.REGISTER_USER_ALREADY_EXISTS
|
||||
assert after_register.called is False
|
||||
|
||||
async def test_valid_body(self, test_app_client: httpx.AsyncClient, after_register):
|
||||
json = {"email": "lancelot@camelot.bt", "password": "guinevere"}
|
||||
@pytest.mark.parametrize("email", ["lancelot@camelot.bt", "Lancelot@camelot.bt"])
|
||||
async def test_valid_body(
|
||||
self, email, test_app_client: httpx.AsyncClient, after_register
|
||||
):
|
||||
json = {"email": email, "password": "guinevere"}
|
||||
response = await test_app_client.post("/register", json=json)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
assert after_register.called is True
|
||||
@ -88,6 +94,7 @@ class TestRegister:
|
||||
|
||||
actual_user = after_register.call_args[0][0]
|
||||
assert str(actual_user.id) == data["id"]
|
||||
assert str(actual_user.email) == email
|
||||
request = after_register.call_args[0][1]
|
||||
assert isinstance(request, Request)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user