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_EmailPasswordSchema_trims_email(self): email = fake.email() body = get_mock_email_password_body(email=f" {email} ") errors = email_password_schema.validate(body) assert not errors dumped = email_password_schema.dump(body) assert dumped["email"] == email
def test_ContactSchema_trims_email(self): email = fake.email() body = get_mock_contact_body(email=f" {email} ") errors = contact_schema.validate(body) assert not errors dumped = contact_schema.dump(body) assert dumped["email"] == email
def test_send_contact_emails(self, sengrid): receiver = fake.email() self._app.config.update({"CONTACT_EMAIL": receiver}) sender = fake.email() subject = fake.sentence() message = fake.sentence() send_contact_emails(sender, subject, message) data = { "email": sender, "subject": subject, "message": message, } sengrid.send.assert_has_calls([ call(TemplateIds.CONTACT_RECEIVER, receiver, data), call(TemplateIds.CONTACT_SENDER, sender, data), ], any_order=True)
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 get_mock_sign_up_body(**kwargs): return { "email": kwargs.get("email", fake.email()), "name": kwargs.get("name", fake.name()), "password": kwargs.get("password", fake.password()), }
def get_mock_email_password_body(**kwargs): return { "email": kwargs.get("email", fake.email()), "password": kwargs.get("password", fake.password()), }
def get_mock_email_body(**kwargs): return { "email": kwargs.get("email", fake.email()), }
def get_mock_contact_body(**kwargs): return { "email": kwargs.get("email", fake.email()), "subject": kwargs.get("subject", fake.sentence()), "message": kwargs.get("message", fake.sentence()), }