Beispiel #1
0
    def test_mail_class_setters(self):
        """ Test Mail class setters functionality"""
        recipients = ['*****@*****.**']
        content = {'text/plain': 'Hello World!'}
        optional_headers = {

            'cc': ['*****@*****.**'],
            'forceSecureNotification': 'false',
            'allowNonTLS': False
        }
        mail = Mail('', '', recipients, content, optional_headers)
        mail.from_ = '*****@*****.**'
        mail.subject = 'Testing!'
        expected_mail = {
            'data': {
                'message': {
                    'content': {
                        'text/plain': 'Hello World!'
                    },
                    'headers': {
                        'from': '*****@*****.**',
                        'subject': 'Testing!'
                    },
                    'recipients': ['*****@*****.**'],
                    'cc': ['*****@*****.**'],
                    'forceSecureNotification': False,
                    'allowNonTLS': False
                }
            }
        }
        self.assertEqual(
            mail.get(),
            expected_mail
        )
Beispiel #2
0
    def test_sending(self):
        """Test send email functionality"""
        paubox_client = paubox.PauboxApiClient()
        recipients = [os.environ.get('RECIPIENT')]
        from_ = os.environ.get('APPROVED_SENDER')
        subject = 'Testing!'
        attachment_content = base64.b64encode(b'Hello World!')
        content = {
            'text/plain': 'Hello World!',
            'text/html': b"<html><body><h1>Hello World!</h1></body></html>"
        }
        optional_headers = {
            'attachments': [{
                'fileName': 'the_file.txt',
                'contentType': 'text/plain',
                'content': attachment_content
            }],
            'reply_to': os.environ.get('APPROVED_SENDER'),
            'bcc': os.environ.get('RECIPIENT2'),
            'cc': [os.environ.get('RECIPIENT3')],
            'forceSecureNotification': 'false'
        }

        mail = Mail(from_, subject, recipients, content, optional_headers)
        paubox_response = paubox_client.send(mail.get())
        self.assertEqual(paubox_response.status_code, 200)
        self.assertTrue('sourceTrackingId' in paubox_response.text)
Beispiel #3
0
    def test_mail_class_all_headers(self):
        """Test Mail class formatting"""
        recipients = ['*****@*****.**']
        from_ = '*****@*****.**'
        subject = 'Testing!'
        plain_html_content = '<html><body><h1>Hello World!</h1></body></html>'
        content = {
            'text/plain': 'Hello World!',
            'text/html': plain_html_content
        }
        attachment_content = base64.b64encode('Hello World!')
        optional_headers = {
            'attachments': [{
                'fileName': 'the_file.txt',
                'contentType': 'text/plain',
                'content': attachment_content
            }],
            'reply_to':
            '*****@*****.**',
            'bcc':
            '*****@*****.**',
            'cc': ['*****@*****.**'],
            'forceSecureNotification':
            'true',
            'allowNonTLS':
            True
        }

        encodedHtmlContent = base64.b64encode(plain_html_content)
        mail = Mail(from_, subject, recipients, content, optional_headers)
        expected_mail = {
            'data': {
                'message': {
                    'content': {
                        'text/plain': 'Hello World!',
                        'text/html': encodedHtmlContent
                    },
                    'headers': {
                        'reply-to': '*****@*****.**',
                        'from': '*****@*****.**',
                        'subject': 'Testing!'
                    },
                    'attachments': [{
                        'content': 'SGVsbG8gV29ybGQh',
                        'contentType': 'text/plain',
                        'fileName': 'the_file.txt'
                    }],
                    'recipients': ['*****@*****.**'],
                    'bcc':
                    '*****@*****.**',
                    'cc': ['*****@*****.**'],
                    'forceSecureNotification':
                    True,
                    'allowNonTLS':
                    True
                }
            }
        }
        self.assertEqual(mail.get(), expected_mail)
Beispiel #4
0
    def test_retrieve_disposition(self):
        """Test get email disposition functionality"""
        recipients = [os.environ.get('RECIPIENT')]
        from_ = os.environ.get('APPROVED_SENDER')
        subject = 'Testing!'
        content = {'text/plain': 'Hello World!'}
        optional_headers = {
            'cc': [os.environ.get('RECIPIENT3')],
            'forceSecureNotification': 'true',
            'allowNonTLS': False
        }
        mail = Mail(from_, subject, recipients, content, optional_headers)

        paubox_client = paubox.PauboxApiClient()
        send_response = paubox_client.send(mail.get())
        source_tracking_id = send_response.to_dict['sourceTrackingId']

        get_response = paubox_client.get(source_tracking_id)
        self.assertEqual(get_response.status_code, 200)
        self.assertTrue('errors' not in get_response.text)