-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improving test to check if the email is sent successfully
- Loading branch information
1 parent
bab8896
commit dc77181
Showing
1 changed file
with
20 additions
and
5 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from datetime import timedelta | ||
|
||
from django.core import mail | ||
from django.test import override_settings | ||
from django.utils.timezone import now | ||
from django_rest_passwordreset.models import ResetPasswordToken | ||
|
@@ -99,7 +100,7 @@ def test_auth_verify_with_invalid_token(self): | |
self.assertEqual(response.data["detail"], "Token is invalid or expired") | ||
|
||
|
||
@override_settings(DISABLE_RATELIMIT=True) | ||
@override_settings(DISABLE_RATELIMIT=True, IS_PRODUCTION=False) | ||
class TestPasswordReset(TestUtils, APITestCase): | ||
@classmethod | ||
def setUpTestData(cls) -> None: | ||
|
@@ -118,13 +119,21 @@ def create_reset_password_token( | |
token.save() | ||
return token | ||
|
||
@override_settings( | ||
EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend", | ||
) | ||
def test_forgot_password_with_valid_input(self): | ||
mail.outbox = [] | ||
response = self.client.post( | ||
"/api/v1/password_reset/", | ||
{"username": self.user.username}, | ||
) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(len(mail.outbox), 1) | ||
self.assertEqual("Password Reset for Care", mail.outbox[0].subject) | ||
self.assertEqual(mail.outbox[0].to, [self.user.email]) | ||
self.assertTrue(ResetPasswordToken.objects.filter(user=self.user).exists()) | ||
self.assertTrue(ResetPasswordToken.objects.filter(user=self.user).exists()) | ||
|
||
@override_settings(IS_PRODUCTION=True) | ||
|
@@ -142,17 +151,23 @@ def test_forgot_password_without_email_configration(self): | |
|
||
@override_settings( | ||
IS_PRODUCTION=True, | ||
EMAIL_HOST="smtp.gmail.com", | ||
EMAIL_HOST_USER="[email protected]", | ||
EMAIL_HOST_PASSWORD="your-app-password", | ||
EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend", | ||
EMAIL_HOST="dummy.smtp.server", | ||
EMAIL_HOST_USER="[email protected]", | ||
EMAIL_HOST_PASSWORD="dummy-password", | ||
) | ||
def test_forgot_password_with_email_configration(self): | ||
def test_forgot_password_with_email_configuration(self): | ||
mail.outbox = [] | ||
|
||
response = self.client.post( | ||
"/api/v1/password_reset/", | ||
{"username": self.user.username}, | ||
) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(len(mail.outbox), 1) | ||
self.assertEqual("Password Reset for Care", mail.outbox[0].subject) | ||
self.assertEqual(mail.outbox[0].to, [self.user.email]) | ||
self.assertTrue(ResetPasswordToken.objects.filter(user=self.user).exists()) | ||
|
||
def test_forgot_password_with_missing_fields(self): | ||
|