Skip to content

Commit

Permalink
Fix tests for new password format
Browse files Browse the repository at this point in the history
  • Loading branch information
meshy committed Jan 23, 2015
1 parent 064a91a commit 2d7d26e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions user_management/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def validate_old_password(self, attrs, source):
return attrs

def validate_new_password2(self, attrs, source):
if attrs['new_password'] != attrs[source]:
if attrs.get('new_password') != attrs[source]:
msg = _('Your new passwords do not match.')
raise serializers.ValidationError(msg)
return attrs
Expand Down Expand Up @@ -144,7 +144,7 @@ def restore_object(self, attrs, instance=None):
return instance

def validate_new_password2(self, attrs, source):
if attrs['new_password'] != attrs[source]:
if attrs.get('new_password') != attrs[source]:
msg = _('Your new passwords do not match.')
raise serializers.ValidationError(msg)
return attrs
Expand Down
24 changes: 12 additions & 12 deletions user_management/api/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import string

from django.test import TestCase
from rest_framework.reverse import reverse
from rest_framework.fields import WritableField
from rest_framework.reverse import reverse

from user_management.models.tests.factories import UserFactory
from user_management.models.tests.utils import RequestTestCase
Expand Down Expand Up @@ -32,8 +32,8 @@ def test_deserialize(self):

class PasswordChangeSerializerTest(TestCase):
def test_deserialize_passwords(self):
old_password = 'old_password'
new_password = 'new_password'
old_password = '0ld_passworD'
new_password = 'n3w_Password'

user = UserFactory.create(password=old_password)

Expand All @@ -48,8 +48,8 @@ def test_deserialize_passwords(self):
self.assertTrue(user.check_password(new_password))

def test_deserialize_invalid_old_password(self):
old_password = 'old_password'
new_password = 'new_password'
old_password = '0ld_passworD'
new_password = 'n3w_Password'

user = UserFactory.build(password=old_password)

Expand All @@ -62,8 +62,8 @@ def test_deserialize_invalid_old_password(self):
self.assertIn('old_password', serializer.errors)

def test_deserialize_invalid_new_password(self):
old_password = 'old_password'
new_password = '2short'
old_password = '0ld_passworD'
new_password = '2Short'

user = UserFactory.build(password=old_password)

Expand All @@ -77,8 +77,8 @@ def test_deserialize_invalid_new_password(self):
self.assertTrue(serializer.object.check_password(old_password))

def test_deserialize_mismatched_passwords(self):
old_password = 'old_password'
new_password = 'new_password'
old_password = '0ld_passworD'
new_password = 'n3w_Password'
other_password = 'other_new_password'

user = UserFactory.create(password=old_password)
Expand All @@ -93,7 +93,7 @@ def test_deserialize_mismatched_passwords(self):

class PasswordResetSerializerTest(TestCase):
def test_deserialize_passwords(self):
new_password = 'new_password'
new_password = 'n3w_Password'
user = UserFactory.create()

serializer = serializers.PasswordResetSerializer(user, data={
Expand All @@ -106,7 +106,7 @@ def test_deserialize_passwords(self):
self.assertTrue(user.check_password(new_password))

def test_deserialize_invalid_new_password(self):
new_password = '2short'
new_password = '2Short'
user = UserFactory.build()

serializer = serializers.PasswordResetSerializer(user, data={
Expand All @@ -118,7 +118,7 @@ def test_deserialize_invalid_new_password(self):
self.assertFalse(serializer.object.check_password(new_password))

def test_deserialize_mismatched_passwords(self):
new_password = 'new_password'
new_password = 'n3w_Password'
other_password = 'other_new_password'
user = UserFactory.create()

Expand Down
28 changes: 14 additions & 14 deletions user_management/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ def test_options(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_put(self):
old_password = 'old_password'
new_password = 'new_password'
old_password = '0ld_passworD'
new_password = 'n3w_Password'
user = UserFactory.create(password=old_password)

token = default_token_generator.make_token(user)
Expand All @@ -349,8 +349,8 @@ def test_put(self):
self.assertTrue(user.check_password(new_password))

def test_password_mismatch(self):
old_password = 'old_password'
new_password = 'new_password'
old_password = '0ld_passworD'
new_password = 'n3w_Password'
invalid_password = 'different_new_password'
user = UserFactory.create(password=old_password)

Expand Down Expand Up @@ -410,8 +410,8 @@ class TestPasswordChange(APIRequestTestCase):
view_class = views.PasswordChange

def test_update(self):
old_password = 'old_password'
new_password = 'new_password'
old_password = '0ld_passworD'
new_password = 'n3w_Password'

user = UserFactory.create(password=old_password)

Expand All @@ -431,8 +431,8 @@ def test_update(self):
self.assertTrue(user.check_password(new_password))

def test_update_anonymous(self):
old_password = 'old_password'
new_password = 'new_password'
old_password = '0ld_passworD'
new_password = 'n3w_Password'

request = self.create_request(
'put',
Expand All @@ -448,8 +448,8 @@ def test_update_anonymous(self):
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

def test_update_wrong_old_password(self):
old_password = 'old_password'
new_password = 'new_password'
old_password = '0ld_passworD'
new_password = 'n3w_Password'

user = UserFactory.create(password=old_password)

Expand All @@ -469,8 +469,8 @@ def test_update_wrong_old_password(self):
self.assertTrue(user.check_password(old_password))

def test_update_invalid_new_password(self):
old_password = 'old_password'
new_password = '2short'
old_password = '0ld_passworD'
new_password = '2Short'

user = UserFactory.create(password=old_password)

Expand All @@ -490,8 +490,8 @@ def test_update_invalid_new_password(self):
self.assertTrue(user.check_password(old_password))

def test_update_mismatched_passwords(self):
old_password = 'old_password'
new_password = 'new_password'
old_password = '0ld_passworD'
new_password = 'n3w_Password'
invalid_password = 'different_new_password'

user = UserFactory.create(password=old_password)
Expand Down

0 comments on commit 2d7d26e

Please sign in to comment.