예제 #1
0
 def test_EmailSchema_trims_email(self):
     email = fake.email()
     body = get_mock_email_body(email=f"  {email}  ")
     errors = email_schema.validate(body)
     assert not errors
     dumped = email_schema.dump(body)
     assert dumped["email"] == email
예제 #2
0
 def test_EmailSchema_blank_email(self):
     body = get_mock_email_body(email=" ")
     errors = email_schema.validate(body)
     assert errors == {
         "email": [
             "Missing data for required field.",
         ],
     }
예제 #3
0
 def test_EmailSchema_invalid_email(self):
     email = fake.sentence()
     body = get_mock_email_body(email=email)
     errors = email_schema.validate(body)
     assert errors == {
         "email": [
             "Not a valid email address.",
         ],
     }
예제 #4
0
 def test_EmailSchema_no_email(self):
     body = get_mock_email_body()
     del body["email"]
     errors = email_schema.validate(body)
     assert errors == {
         "email": [
             "Missing data for required field.",
         ],
     }
예제 #5
0
def reset_password_POST():
    errors = email_schema.validate(request.json)

    if errors:
        return build_400_error_response(errors)

    parsed_schema = email_schema.dump(request.json)

    user = get_user_by_email(parsed_schema["email"])

    if not user:
        abort(404)

    send_password_reset_email(user)

    return "", 204
예제 #6
0
def users_user_email_POST(user, **_):
    errors = email_schema.validate(request.json)

    if errors:
        return build_400_error_response(errors)

    parsed_schema = email_schema.dump(request.json)

    if get_user_by_email(parsed_schema["email"]):
        return build_400_error_response({
            "email": [
                "There is already an account with this email.",
            ],
        })

    updated_user = update_user_email(user, parsed_schema["email"])

    send_verification_email(updated_user)

    return "", 204
예제 #7
0
def verify_POST():
    errors = email_schema.validate(request.json)

    if errors:
        return build_400_error_response(errors)

    parsed_schema = email_schema.dump(request.json)

    user = get_user_by_email(parsed_schema["email"])

    if not user:
        abort(404)

    if user.active:
        return build_400_error_response({
            "email": [
                "This email has already been verified.",
            ],
        })

    send_verification_email(user)

    return "", 204
예제 #8
0
 def test_EmailSchema_unrecognised_field(self):
     body = get_mock_email_body()
     key = fake.pystr()
     body[key] = fake.pystr()
     assert not email_schema.validate(body)
     assert key not in email_schema.dump(body)