Skip to content

Commit dd7dc24

Browse files
committed
Add more tests.
Signed-off-by: Thapelo Tsotetsi <[email protected]>
1 parent 6197f0a commit dd7dc24

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

backend/user_service/.coverage

0 Bytes
Binary file not shown.

backend/user_service/users/api/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PasswordResetSerializer(serializers.Serializer):
3535
def validate_email(self, value):
3636
# Check if the email exists in the database.
3737
if not User.objects.filter(email=value).exists():
38-
raise serializers.ValidationError("use with this email address does not exist.")
38+
raise serializers.ValidationError("User with this email address does not exist.")
3939
return value
4040

4141
def save(self, **kwargs):

backend/user_service/users/tests/test_drf_views.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ def test_user_registration_success(self, mock_complete_signup, api_client_factor
8282
assert len(mail.outbox) == 1
8383
assert mail.outbox[0].subject == '[example.com] Please Confirm Your Email Address'
8484

85-
@patch('allauth.account.utils.complete_signup') # Mock the complete_signup function
8685
@pytest.mark.django_db
87-
def test_user_registration_validation_errors(self, mock_complete_signup, api_client_factory, url_factory, user_factory):
86+
def test_user_registration_validation_errors(self, api_client_factory, url_factory, user_factory):
8887
# Pick variables that you only need for registration form.
8988
user_exist_data = { k: v for k, v in model_to_dict(user_factory).items() if k in ['name', 'email', 'phone_number', 'password']}
9089
response = api_client_factory.post(url_factory('register'), user_exist_data)
@@ -98,3 +97,33 @@ def test_user_registration_validation_errors(self, mock_complete_signup, api_cli
9897
assert response.data['email'][0] == 'This field is required.'
9998
assert response.data['phone_number'][0] == 'This field is required.'
10099
assert response.data['password'][0] == 'This field is required.'
100+
101+
102+
class TestPasswordResetView:
103+
def test_password_reset_url(self, url_factory):
104+
password_reset_url = url_factory("password_reset")
105+
assert password_reset_url == "/api/password/reset/"
106+
107+
@pytest.mark.django_db
108+
def test_password_reset_link_success(self, api_client_factory, url_factory, user_factory):
109+
data = { 'email': '[email protected]'}
110+
response = api_client_factory.post(url_factory("password_reset"), data)
111+
assert str(response.data['email'][0]) == 'User with this email address does not exist.'
112+
113+
# Use existing, registered user email
114+
data = {"email": model_to_dict(user_factory)['email']}
115+
response = api_client_factory.post(url_factory("password_reset"), data)
116+
assert response.status_code == 200
117+
118+
# Check that the reset password email was sent.
119+
assert len(mail.outbox) == 1
120+
assert mail.outbox[0].to[0] == data['email']
121+
122+
class TestCustomPasswordResetFromKey:
123+
def test_custom_reset_password(self, url_factory):
124+
pass
125+
126+
127+
class TestCustomConfirmEmailView:
128+
def test_confirm_email_url(self, url_factory):
129+
pass

0 commit comments

Comments
 (0)