def test_send_with_sendgrid_success(self): mock_client = mock.MagicMock() mock_client.send.return_value = 200, 'success' from_addr, to_addr = fake.email(), fake.email() category1, category2 = fake.word(), fake.word() subject = fake.bs() message = fake.text() ret = _send_with_sendgrid(from_addr=from_addr, to_addr=to_addr, subject=subject, message=message, mimetype='txt', client=mock_client, categories=(category1, category2)) assert_true(ret) assert_equal(mock_client.send.call_count, 1) # First call's argument should be a Mail object with # the correct configuration first_call_arg = mock_client.send.call_args[0][0] assert_is_instance(first_call_arg, sendgrid.Mail) assert_equal(first_call_arg.from_email, from_addr) assert_equal(first_call_arg.to[0], to_addr) assert_equal(first_call_arg.subject, subject) assert_equal(first_call_arg.text, message) # Categories are set assert_equal(first_call_arg.smtpapi.data['category'], (category1, category2))
def test_send_with_sendgrid_success(self): mock_client = mock.MagicMock() mock_client.send.return_value = 200, 'success' from_addr, to_addr = fake_email(), fake_email() category1, category2 = fake.word(), fake.word() subject = fake.bs() message = fake.text() ret = _send_with_sendgrid( from_addr=from_addr, to_addr=to_addr, subject=subject, message=message, mimetype='html', client=mock_client, categories=(category1, category2) ) assert_true(ret) assert_equal(mock_client.send.call_count, 1) # First call's argument should be a Mail object with # the correct configuration first_call_arg = mock_client.send.call_args[0][0] assert_is_instance(first_call_arg, sendgrid.Mail) assert_equal(first_call_arg.from_email, from_addr) assert_equal(first_call_arg.to[0], to_addr) assert_equal(first_call_arg.subject, subject) assert_in(message, first_call_arg.html) # Categories are set assert_equal(first_call_arg.smtpapi.data['category'], (category1, category2))
def test_send_with_sendgrid_failure_returns_false(self): mock_client = mock.MagicMock() mock_client.send.return_value = 400, 'failed' from_addr, to_addr = fake_email(), fake_email() subject = fake.bs() message = fake.text() ret = _send_with_sendgrid(from_addr=from_addr, to_addr=to_addr, subject=subject, message=message, client=mock_client) assert_false(ret)
def test_send_with_sendgrid_failure_returns_false(self): mock_client = mock.MagicMock() mock_client.send.return_value = 400, 'failed' from_addr, to_addr = fake_email(), fake_email() subject = fake.bs() message = fake.text() ret = _send_with_sendgrid( from_addr=from_addr, to_addr=to_addr, subject=subject, message=message, mimetype='html', client=mock_client ) assert_false(ret)