Skip to content

Commit

Permalink
Add new test, resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hitenvidhani committed Apr 19, 2024
1 parent f06c44f commit 54056ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions mathesar/api/ui/serializers/users.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.auth.password_validation import validate_password
from django.core.exceptions import ValidationError as DjangoValidationError
from rest_access_policy import FieldAccessMixin, PermittedPkRelatedField
from rest_framework import serializers

Expand Down Expand Up @@ -83,8 +84,8 @@ def validate_old_password(self, value):
def validate_password(self, value):
try:
validate_password(value)
except serializers.ValidationError as exc:
raise serializers.ValidationError(str(exc))
except DjangoValidationError as exc:
raise DjangoValidationError(str(exc))
return value

def update(self, instance, validated_data):
Expand Down
15 changes: 14 additions & 1 deletion mathesar/tests/api/test_user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_user_password_change(client_bob, user_bob):
new_password = 'NewPass0!'
old_password = 'password'
data = {
'password': 'NewPass0!',
'password': new_password,
'old_password': old_password
}
response = client_bob.post('/api/ui/v0/users/password_change/', data=data)
Expand All @@ -73,6 +73,19 @@ def test_user_password_change(client_bob, user_bob):
assert user_bob.check_password(new_password) is True


def test_user_password_change_invalid(client_bob, user_bob):
new_password = 'new_pwd'
old_password = 'password'
data = {
'password': new_password,
'old_password': old_password
}
response = client_bob.post('/api/ui/v0/users/password_change/', data=data)
assert response.status_code == 400
user_bob.refresh_from_db()
assert user_bob.check_password(new_password) is False


def test_diff_user_detail_as_non_superuser(client_bob, admin_user):
response = client_bob.get(f'/api/ui/v0/users/{admin_user.id}/')
response_data = response.json()
Expand Down

0 comments on commit 54056ab

Please sign in to comment.