def test_check_length(self):
        user = User.testing_create()
        with pytest.raises(auth.PasswordPolicyError,
                           match='Password must be at least 8 characters long'):
            auth.PasswordPolicy().check_length('aBcDe1!', user)

        class LongerPolicy(auth.PasswordPolicy):
            min_length = 10

        with pytest.raises(auth.PasswordPolicyError,
                           match='Password must be at least 10 characters long'):
            LongerPolicy().check_length('aBcDeFg1!', user)

        auth.PasswordPolicy().check_length('aBcDeF1!', user)
        LongerPolicy().check_length('aBcDeFgH1!', user)
    def test_char_set_validator_failures(self, pw):
        user = User.testing_create()

        with pytest.raises(
            auth.PasswordPolicyError,
            match='Password must include at least 3 of lowercase letter, uppercase letter, number and/or symbol'  # noqa: E501
        ):
            auth.PasswordPolicy().check_character_set(pw, user)
 def test_check_does_not_contain_username_no_email_success(
         self, pw, username):
     user = UserNoEmail.testing_create(username=username)
     auth.PasswordPolicy().check_does_not_contain_username(pw, user)
 def test_check_does_not_contain_username_email_success(self, pw, email):
     user = User.testing_create(email=email)
     auth.PasswordPolicy().check_does_not_contain_username(pw, user)
 def test_check_does_not_contain_username_no_email_failures(
         self, pw, username):
     user = UserNoEmail.testing_create(username=username)
     with pytest.raises(auth.PasswordPolicyError,
                        match='Password may not contain username'):
         auth.PasswordPolicy().check_does_not_contain_username(pw, user)
 def test_check_char_set_success(self, pw):
     user = User.testing_create()
     auth.PasswordPolicy().check_character_set(pw, user)