def test_PasswordSchema_password_equal_to_max(self): password = fake.pystr( min_chars=Limits.MAX_USER_PASSWORD_LENGTH, max_chars=Limits.MAX_USER_PASSWORD_LENGTH, ) body = get_mock_password_body(password=password) errors = password_schema.validate(body) assert not errors
def test_PasswordSchema_no_password(self): body = get_mock_password_body() del body["password"] errors = password_schema.validate(body) assert errors == { "password": [ "Missing data for required field.", ], }
def users_user_password_POST(user, **_): errors = password_schema.validate(request.json) if errors: return build_400_error_response(errors) parsed_schema = password_schema.dump(request.json) update_user_password(user, parsed_schema["password"]) return "", 204
def test_PasswordSchema_password_greater_than_max(self): password = fake.pystr( min_chars=Limits.MAX_USER_PASSWORD_LENGTH + 1, max_chars=Limits.MAX_USER_PASSWORD_LENGTH + 1, ) body = get_mock_password_body(password=password) errors = password_schema.validate(body) assert errors == { "password": [ f"Length must be between {Limits.MIN_USER_PASSWORD_LENGTH} " f"and {Limits.MAX_USER_PASSWORD_LENGTH}.", ], }
def reset_password_token_POST(token): errors = password_schema.validate(request.json) if errors: return build_400_error_response(errors) user = get_user_from_password_reset_token(token) if not user: return build_400_error_response({ "token": [ "Invalid token.", ], }) parsed_schema = password_schema.dump(request.json) update_user_password(user, parsed_schema["password"]) return "", 204
def test_PasswordSchema_unrecognised_field(self): body = get_mock_password_body() key = fake.pystr() body[key] = fake.pystr() assert not password_schema.validate(body) assert key not in password_schema.dump(body)