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