Ejemplo n.º 1
0
 def test_SignUpSchema_trims_email(self):
     email = fake.email()
     body = get_mock_sign_up_body(email=f"  {email}  ")
     errors = sign_up_schema.validate(body)
     assert not errors
     dumped = sign_up_schema.dump(body)
     assert dumped["email"] == email
Ejemplo n.º 2
0
 def test_SignUpSchema_trims_name(self):
     name = fake.name()
     body = get_mock_sign_up_body(name=f"  {name}  ")
     errors = sign_up_schema.validate(body)
     assert not errors
     dumped = sign_up_schema.dump(body)
     assert dumped["name"] == name
Ejemplo n.º 3
0
 def test_SignUpSchema_blank_email(self):
     body = get_mock_sign_up_body(email=" ")
     errors = sign_up_schema.validate(body)
     assert errors == {
         "email": [
             "Missing data for required field.",
         ],
     }
Ejemplo n.º 4
0
 def test_SignUpSchema_name_equal_to_max(self):
     name = fake.pystr(
         min_chars=Limits.MAX_USER_NAME_LENGTH,
         max_chars=Limits.MAX_USER_NAME_LENGTH,
     )
     body = get_mock_sign_up_body(name=name)
     errors = sign_up_schema.validate(body)
     assert not errors
Ejemplo n.º 5
0
 def test_SignUpSchema_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_sign_up_body(password=password)
     errors = sign_up_schema.validate(body)
     assert not errors
Ejemplo n.º 6
0
 def test_SignUpSchema_invalid_email(self):
     email = fake.sentence()
     body = get_mock_sign_up_body(email=email)
     errors = sign_up_schema.validate(body)
     assert errors == {
         "email": [
             "Not a valid email address.",
         ],
     }
Ejemplo n.º 7
0
 def test_SignUpSchema_no_name(self):
     body = get_mock_sign_up_body()
     del body["name"]
     errors = sign_up_schema.validate(body)
     assert errors == {
         "name": [
             "Missing data for required field.",
         ],
     }
Ejemplo n.º 8
0
 def test_SignUpSchema_name_greater_than_max(self):
     name = fake.pystr(
         min_chars=Limits.MAX_USER_NAME_LENGTH + 1,
         max_chars=Limits.MAX_USER_NAME_LENGTH + 1,
     )
     body = get_mock_sign_up_body(name=name)
     errors = sign_up_schema.validate(body)
     assert errors == {
         "name": [
             f"Longer than maximum length {Limits.MAX_USER_NAME_LENGTH}.",
         ],
     }
Ejemplo n.º 9
0
 def test_SignUpSchema_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_sign_up_body(password=password)
     errors = sign_up_schema.validate(body)
     assert errors == {
         "password": [
             f"Length must be between {Limits.MIN_USER_PASSWORD_LENGTH} "
             f"and {Limits.MAX_USER_PASSWORD_LENGTH}.",
         ],
     }
Ejemplo n.º 10
0
def sign_up_POST():
    errors = sign_up_schema.validate(request.json)

    if errors:
        return build_400_error_response(errors)

    parsed_schema = sign_up_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.",
            ],
        })

    user = save_new_user(
        parsed_schema["name"],
        parsed_schema["email"],
        parsed_schema["password"],
    )

    send_verification_email(user)

    return "", 201
Ejemplo n.º 11
0
 def test_SignUpSchema_unrecognised_field(self):
     body = get_mock_sign_up_body()
     key = fake.pystr()
     body[key] = fake.pystr()
     assert not sign_up_schema.validate(body)
     assert key not in sign_up_schema.dump(body)