def create_email(message_data): Intercom.app_id = settings.INTERCOM_APP_ID Intercom.app_api_key = settings.INTERCOM_API_KEY try: Message.create(**message_data) except (ResourceNotFound, UnexpectedError) as e: raise create_email.retry(exc=e, countdown=10, max_retries=None) except RateLimitExceeded as e: # pragma: no cover # We don't want to continue bashing their API if we've # hit our limit. Intercom may then reduce our overall limit as # highlighted here # https://developers.intercom.io/reference#rate-limiting # Not covering because Intercom does not have a good way of # simulating these conditions as of 06/04/2016 - Devon Bleibtrey raise create_email.retry(exc=e, countdown=3600, max_retries=None) except AuthenticationError as e: # pragma: no cover # AuthenticationError can be caused by a user selecting # Unsubscribe from email. So we only retry this a limited amount of # times before giving up. # Not covering because Intercom does not have a good way of # simulating these conditions as of 06/04/2016 - Devon Bleibtrey raise create_email.retry(exc=e, countdown=3600, max_retries=10) except (ServerError, ServiceUnavailableError, BadGatewayError, HttpError) as e: # pragma: no cover # Not covering because Intercom does not have a good way of # simulating these conditions as of 04/16/2016 - Devon Bleibtrey raise create_email.retry(exc=e, countdown=60, max_retries=None)
def authenticate_representative(request): Intercom.app_id = settings.INTERCOM_APP_ID Intercom.app_api_key = settings.INTERCOM_API_KEY pleb = Pleb.get(request.user.username) message_data = { 'message_type': 'email', 'subject': "Representative Authentication", 'body': render_to_string( "email_templates/internal_representative_confirmation.html", { "username": pleb.username, "phone": pleb.get_official_phone() }), 'template': "personal", 'from': { 'type': "admin", 'id': settings.INTERCOM_ADMIN_ID_DEVON }, 'to': { 'type': "user", 'user_id': "devon_bleibtrey" } } Message.create(**message_data) return Response( {"detail": "We will be call your office phone to " "verify soon."}, status=status.HTTP_200_OK)
def setup_class(cls): # get admin cls.admin = Admin.all()[1] # get user timestamp = get_timestamp() cls.user = get_or_create_user(timestamp) cls.email = cls.user.email # send user message message_data = { 'from': { 'type': "user", 'id': cls.user.id }, 'body': "Hey" } cls.user_message = Message.create(**message_data) conversations = Conversation.find_all() user_init_conv = conversations[0] # send admin reply cls.admin_conv = user_init_conv.reply(type='admin', admin_id=cls.admin.id, message_type='comment', body='There')
def setup_class(cls): # get admin cls.admin = Admin.all()[1] # get user timestamp = get_timestamp() cls.user = get_or_create_user(timestamp) cls.email = cls.user.email # send user message message_data = { 'from': { 'type': "user", 'id': cls.user.id }, 'body': "Hey" } cls.user_message = Message.create(**message_data) conversations = Conversation.find_all() user_init_conv = conversations[0] # send admin reply cls.admin_conv = user_init_conv.reply( type='admin', admin_id=cls.admin.id, message_type='comment', body='There')
def it_creates_a_user_message_with_string_keys(self): data = { 'from': { 'type': 'user', 'email': '*****@*****.**', }, 'body': 'halp' } with patch.object(Intercom, 'post', return_value=data) as mock_method: message = Message.create(**data) mock_method.assert_called_once_with('/messages/', **data) eq_('halp', message.body)
def it_creates_an_admin_message(self): data = { 'from': { 'type': 'admin', 'id': '1234', }, 'to': { 'type': 'user', 'id': '5678', }, 'body': 'halp', 'message_type': 'inapp' } with patch.object(Intercom, 'post', return_value=data) as mock_method: message = Message.create(**data) mock_method.assert_called_once_with('/messages/', **data) eq_('halp', message.body) eq_('inapp', message.message_type)