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_min(self): password = fake.pystr( min_chars=Limits.MIN_USER_PASSWORD_LENGTH, max_chars=Limits.MIN_USER_PASSWORD_LENGTH, ) body = get_mock_sign_up_body(password=password) errors = sign_up_schema.validate(body) assert not errors
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_ContactSchema_subject_equal_to_max(self): subject = fake.pystr( min_chars=Limits.MAX_CONTACT_SUBJECT_LENGTH, max_chars=Limits.MAX_CONTACT_SUBJECT_LENGTH, ) body = get_mock_contact_body(subject=subject) errors = contact_schema.validate(body) assert not errors
def test_ContactSchema_message_equal_to_max(self): message = fake.pystr( min_chars=Limits.MAX_CONTACT_MESSAGE_LENGTH, max_chars=Limits.MAX_CONTACT_MESSAGE_LENGTH, ) body = get_mock_contact_body(message=message) errors = contact_schema.validate(body) assert not errors
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_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 test_SignUpSchema_password_less_than_min(self): password = fake.pystr( min_chars=Limits.MIN_USER_PASSWORD_LENGTH - 1, max_chars=Limits.MIN_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_ContactSchema_subject_greater_than_max(self): subject = fake.pystr( min_chars=Limits.MAX_CONTACT_SUBJECT_LENGTH + 1, max_chars=Limits.MAX_CONTACT_SUBJECT_LENGTH + 1, ) body = get_mock_contact_body(subject=subject) errors = contact_schema.validate(body) assert errors == { "subject": [ "Longer than maximum length " f"{Limits.MAX_CONTACT_SUBJECT_LENGTH}.", ], }
def test_ContactSchema_message_greater_than_max(self): message = fake.pystr( min_chars=Limits.MAX_CONTACT_MESSAGE_LENGTH + 1, max_chars=Limits.MAX_CONTACT_MESSAGE_LENGTH + 1, ) body = get_mock_contact_body(message=message) errors = contact_schema.validate(body) assert errors == { "message": [ "Longer than maximum length " f"{Limits.MAX_CONTACT_MESSAGE_LENGTH}.", ], }
def test_send(self, client): app = MockApp() sendgrid.init_app(app) template_id = fake.pystr() recipient = fake.email() data = fake.pydict(4, True, ["str"]) sendgrid.send(template_id, recipient, data) message = client().send.call_args[0][0] assert message.from_email.name == "Dawdle" assert message.from_email.email == app.config["SENDER_EMAIL"] assert message.personalizations[0].tos[0]["email"] == recipient assert message.template_id.template_id == template_id assert message.personalizations[0].dynamic_template_data == data
class MockApp: config = { "SENDGRID_API_KEY": fake.pystr(), "SENDER_EMAIL": fake.email(), }
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)
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)
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)