def test_exception_raised_if_message_id_is_not_found(self): message = Message( connection=self.connection, collector_id=self.collector_id, ) with HTTMock(self.mock.send): with pytest.raises(AttributeError): message.send()
def test_reminder_created(self): config = ReminderConfig() message = Message(connection=self.connection, collector_id=self.collector_id, config=config) with HTTMock(MessagesMock(config).create): reminder = message.create() expect(reminder).to(be_reminder)
def test_exception_raised_when_recipient_has_empty_email(self, recipients): message = Message( connection=self.connection, collector_id=self.collector_id, message_id=self.message_id, ) with HTTMock(self.mock.recipient_add): with pytest.raises(ValueError): message.recipients(recipients)
def test_exception_raised_when_no_message_id_is_provided_and_message_is_not_newly_created( self, recipients): # noqa:E501 message = Message( connection=self.connection, collector_id=self.collector_id, ) with HTTMock(self.mock.recipient_add): with pytest.raises(AttributeError): message.recipients(recipients)
def test_message_sent(self): message = Message( connection=self.connection, collector_id=self.collector_id, message_id=self.message_id, ) with HTTMock(self.mock.send): response = message.send() expect(response).to(have_key("is_scheduled", True))
def test_exception_raised_when_recipient_dictionary_is_missing_email_key( self, recipients): message = Message( connection=self.connection, collector_id=self.collector_id, message_id=self.message_id, ) with HTTMock(self.mock.recipient_add): with pytest.raises(KeyError): message.recipients(recipients)
def test_add_recipients_to_existing_message(self, recipients): message = Message( connection=self.connection, collector_id=self.collector_id, message_id=self.message_id, ) with HTTMock(self.mock.recipient_add): response = message.recipients(recipients) expect(response["succeeded"]).to(have_length(be_above_or_equal(1)))
def test_invite_created(self): config = InviteConfig() message = Message(connection=self.connection, collector_id=self.collector_id, config=config) with HTTMock(MessagesMock(config).create): invite = message.create() expect(invite).to_not(be_sent) expect(invite).to(be_invite) expect(invite).to(have_key("id"))
def test_exception_raised_when_recipient_has_empty_extra_field( self, recipients): message = Message( connection=self.connection, collector_id=self.collector_id, message_id=self.message_id, ) with HTTMock(self.mock.recipient_add): with pytest.raises(ValueError): message.recipients( recipients, extra_field_mapping={'some_field': 'some_key'})
def test_exception_raised_when_recipient_dictionary_is_missing_custom_field_key( self, recipients): message = Message( connection=self.connection, collector_id=self.collector_id, message_id=self.message_id, ) with HTTMock(self.mock.recipient_add): with pytest.raises(KeyError): message.recipients(recipients, custom_field_mapping={'1': 'name'})
def test_create_new_message_and_add_a_recipients(self, recipients): message = Message(connection=self.connection, collector_id=self.collector_id, config=self.config) with HTTMock(MessagesMock(self.config).create): message.create() with HTTMock(self.mock.recipient_add): response = message.recipients(recipients) expect(response["succeeded"]).to(have_length(be_above_or_equal(1)))
def test_scheduled_date_correctly_formatted_for_post(self): message = Message( connection=self.connection, collector_id=self.collector_id, message_id=self.message_id, ) message.post = MagicMock() with HTTMock(self.mock.send): message.send(scheduled_date=datetime.now() + timedelta(days=3)) url = URL_MESSAGE_SEND.format(collector_id=self.collector_id, message_id=self.message_id) message.post.assert_called_with( base_url=url, data={'scheduled_date': '2015-10-09T12:56:55+00:00'})