Ejemplo n.º 1
0
 def test_api_key_on_send(self, mock_request):
     mock_request.return_value = self.mock_response('')
     msg = Message(to='me', text='hi')
     sender = Sender(message=msg)
     url = sender._get_api_url(secure=True)
     data = msg.json()
     headers = sender._get_headers(api_key=POSTMARK_API_TEST_KEY)
     sender.send(api_key=POSTMARK_API_TEST_KEY)
     mock_request.assert_called_with('POST', url, data=data,
                                     headers=headers)
Ejemplo n.º 2
0
 def _test_secure_overrides(self, mock_request, init_secure=None,
                            send_secure=None):
     mock_request.return_value = self.mock_response('')
     msg = Message(to='me', text='hi')
     sender = Sender(test=True, secure=init_secure)
     if init_secure or init_secure is None:
         url = POSTMARK_API_URL_SECURE
     else:
         url = POSTMARK_API_URL
     if not send_secure and send_secure is not None:
         url = POSTMARK_API_URL
     elif send_secure:
         url = POSTMARK_API_URL_SECURE
     url = urljoin(url, Sender.endpoint)
     data = msg.json()
     headers = sender._get_headers(api_key=POSTMARK_API_TEST_KEY)
     sender.send(secure=send_secure, message=msg)
     mock_request.assert_called_with('POST', url, data=data,
                                     headers=headers)
Ejemplo n.º 3
0
 def _test_secure_overrides(self, mock_request, init_secure=None,
                            send_secure=None):
     mock_request.return_value = self.mock_response('')
     msg = Message(to='me', text='hi')
     sender = Sender(test=True, secure=init_secure)
     if init_secure or init_secure is None:
         url = POSTMARK_API_URL_SECURE
     else:
         url = POSTMARK_API_URL
     if not send_secure and send_secure is not None:
         url = POSTMARK_API_URL
     elif send_secure:
         url = POSTMARK_API_URL_SECURE
     url = urljoin(url, Sender.endpoint)
     data = msg.json()
     headers = sender._get_headers(api_key=POSTMARK_API_TEST_KEY)
     sender.send(secure=send_secure, message=msg)
     mock_request.assert_called_with('POST', url, data=data,
                                     headers=headers)
Ejemplo n.º 4
0
 def test_api_key_on_send(self, mock_request):
     mock_request.return_value = self.mock_response('')
     msg = Message(to='me', text='hi')
     sender = Sender(message=msg)
     url = sender._get_api_url(secure=True)
     data = msg.json()
     headers = sender._get_headers(api_key=POSTMARK_API_TEST_KEY)
     sender.send(api_key=POSTMARK_API_TEST_KEY)
     mock_request.assert_called_with('POST', url, data=data,
                                     headers=headers)
Ejemplo n.º 5
0
 def test_create_with_dict(self):
     sender = Sender(message=self.message)
     self.assertEqual(sender.message, self.message)
     self.assertNotEqual(sender.message, Message(to='me', text='hi'))
Ejemplo n.º 6
0
 def test_missing_api_key(self, mock_request):
     mock_request.return_value = self.mock_response('')
     sender = Sender()
     msg = 'Postmark API Key not provided'
     self.assertRaisesMessage(ValueError, msg, sender.send)
Ejemplo n.º 7
0
 def sender(self):
     return Sender(test=True)