@@ -0,0 +1,2098 @@
+from django.test import TestCase, override_settings%0Afrom django.core.exceptions import ValidationError%0Afrom corehq.apps.domain.models import Domain%0Afrom corehq.apps.hqwebapp.models import UsedPasswords%0Afrom corehq.apps.hqwebapp.password_validation import UsedPasswordValidator%0Afrom corehq.apps.users.dbaccessors.all_commcare_users import delete_all_users%0Afrom corehq.apps.users.models import WebUser%0Afrom corehq.apps.hqwebapp.const import RESTRICT_USED_PASSWORDS_NUM%0A%0A%0Aclass TestUsedPasswordsRestriction(TestCase):%0A    def setUp(self):%0A        delete_all_users()%0A        self.domain = Domain.get_or_create_with_name('qwerty', is_active=True)%0A        self.username = 'auser@qwerty.commcarehq.org'%0A        self.password = 'apassword'%0A        self.user = WebUser.create(self.domain.name, self.username, self.password).get_django_user()%0A%0A    def tearDown(self):%0A        self.user.delete()%0A        self.domain.delete()%0A        UsedPasswords.objects.all().delete()%0A%0A    def test_used_password_reset(self):%0A        with override_settings(AUTH_PASSWORD_VALIDATORS=%5B%7B%0A            'NAME': 'corehq.apps.hqwebapp.password_validation.UsedPasswordValidator',%0A        %7D%5D):%0A            with self.assertRaisesMessage(%0A                    ValidationError,%0A                    %22Your password can not be same as last %7Bnum%7D passwords.%22.format(num=RESTRICT_USED_PASSWORDS_NUM)):%0A                UsedPasswordValidator().validate(self.password, self.user)%0A                # set as same password%0A                self.user._password = self.password%0A                self.user.save()%0A%0A            self.user._password = %22123456%22%0A            self.user.save()%0A%0A            self.user._password = %22987654%22%0A            self.user.save()%0A%0A            with self.assertRaisesMessage(%0A                    ValidationError,%0A                    %22Your password can not be same as last %7Bnum%7D passwords.%22.format(num=RESTRICT_USED_PASSWORDS_NUM)):%0A                UsedPasswordValidator().validate(self.password, self.user)%0A                # set as an old password%0A                self.user._password = %22123456%22%0A                self.user.save()%0A

add test cases for UsedPasswordValidator