예제 #1
0
    def test_extracting_attachment(self, get_message_info_mock, get_attachment_mock):
        message_id = '16740205f39700d1'
        self.mock_get_message_info(get_message_info_mock, message_id)
        self.mock_get_attachment(get_attachment_mock, message_id)

        connector = GmailConnector(self.email_account)
        message_info = connector.get_message_info(message_id)

        payload = message_info['payload']

        body_html = get_body_html_from_payload(payload, message_id)
        attachments = get_attachments_from_payload(payload, body_html, message_id, connector)
        self.email_message.attachments.add(bulk=False, *attachments)

        get_message_info_mock.assert_called_once()
        get_attachment_mock.assert_called_once()

        self.assertEqual(len(attachments), 1)
예제 #2
0
    def test_get_message_info(self, get_http_mock):
        """
        Test the GmailConnector in retrieving the info of a single email message.
        """
        get_http_mock.return_value = HttpMock('lily/messaging/email/tests/data/get_message_info_15a6008a4baa65f3.json',
                                              {'status': '200'})

        email_account = EmailAccount.objects.first()

        connector = GmailConnector(email_account)
        response = connector.get_message_info('15a6008a4baa65f3')

        # Verify that the service call returned the correct json object.
        with open('lily/messaging/email/tests/data/get_message_info_15a6008a4baa65f3.json') as infile:
            json_obj = json.load(infile)
            self.assertEqual(response, json_obj)

        # Verify that the history id is not retrieved from the get API response.
        self.assertEqual(connector.history_id, None)
예제 #3
0
    def test_get_message_info(self, get_http_mock):
        """
        Test the GmailConnector in retrieving the info of a single email message.
        """
        get_http_mock.return_value = HttpMock(
            'lily/messaging/email/tests/data/get_message_info_15a6008a4baa65f3.json',
            {'status': '200'})

        email_account = EmailAccount.objects.first()

        connector = GmailConnector(email_account)
        response = connector.get_message_info('15a6008a4baa65f3')

        # Verify that the service call returned the correct json object.
        with open(
                'lily/messaging/email/tests/data/get_message_info_15a6008a4baa65f3.json'
        ) as infile:
            json_obj = json.load(infile)
            self.assertEqual(response, json_obj)

        # Verify that the history id is not retrieved from the get API response.
        self.assertEqual(connector.history_id, None)