From af8424f0a1aaf254b2a7c142512feefda8027db7 Mon Sep 17 00:00:00 2001 From: Poderyagin Egor Date: Sun, 13 Dec 2015 22:03:38 +0300 Subject: [PATCH] Test for restore password by email in different case --- rest_auth/serializers.py | 4 ++-- rest_auth/tests/settings.py | 2 +- rest_auth/tests/test_api.py | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/rest_auth/serializers.py b/rest_auth/serializers.py index a2d1a82..1026d6b 100644 --- a/rest_auth/serializers.py +++ b/rest_auth/serializers.py @@ -50,11 +50,11 @@ class LoginSerializer(serializers.Serializer): msg = _('Must include either "username" or "email" and "password".') raise exceptions.ValidationError(msg) - elif username and password: + elif username or email and password: user = authenticate(username=username, password=password) else: - msg = _('Must include "username" and "password".') + msg = _('Must include either "username" or "email" and "password".') raise exceptions.ValidationError(msg) # Did we get back an active user? diff --git a/rest_auth/tests/settings.py b/rest_auth/tests/settings.py index 5c7a940..1f1b05d 100644 --- a/rest_auth/tests/settings.py +++ b/rest_auth/tests/settings.py @@ -72,5 +72,5 @@ ACCOUNT_ACTIVATION_DAYS = 1 SITE_ID = 1 MIGRATION_MODULES = { - 'authtoken': 'authtoken.migrations', + 'authtoken': 'rest_auth.migrations', } diff --git a/rest_auth/tests/test_api.py b/rest_auth/tests/test_api.py index 7adcf71..e7ed636 100644 --- a/rest_auth/tests/test_api.py +++ b/rest_auth/tests/test_api.py @@ -224,6 +224,15 @@ class APITestCase1(TestCase, BaseAPITestCase): } self.post(self.login_url, data=payload, status_code=200) + def test_password_reset_with_email_in_different_cases(self): + user = get_user_model().objects.create_user(self.USERNAME, self.EMAIL.lower(), self.PASS) + + # call password reset with email in Upper case + mail_count = len(mail.outbox) + payload = {'email': self.EMAIL.upper()} + self.post(self.password_reset_url, data=payload, status_code=200) + self.assertEqual(len(mail.outbox), mail_count + 1) + def test_password_reset_with_invalid_email(self): get_user_model().objects.create_user(self.USERNAME, self.EMAIL, self.PASS)