Permalink
Browse files

Merge pull request #70 from themartorana/nicholasserra-httpconnection…

…-import

Fix HTTPConnection import
  • Loading branch information...
2 parents 53aef47 + 7811c6d commit c10085bbbe56705fbef570988409a0c003896c39 @nicholasserra nicholasserra committed on GitHub Feb 14, 2017
Showing with 17 additions and 4 deletions.
  1. +4 −3 postmark/core.py
  2. +13 −1 tests.py
View
@@ -1,17 +1,18 @@
#
# Imports (JSON library based on import try)
+import sys
from postmark import __version__
try:
from email.mime.base import MIMEBase
except ImportError as e:
from email import MIMEBase
- from httplib import HTTPConnection
- from urllib import urlencode
-import sys
+
if sys.version_info[0] < 3:
from urllib2 import Request, urlopen, HTTPError, URLError
+ from httplib import HTTPConnection
+ from urllib import urlencode
else:
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError
View
@@ -5,15 +5,18 @@
from io import BytesIO
if sys.version_info[0] < 3:
+ from StringIO import StringIO
from urllib2 import HTTPError
else:
+ from io import StringIO
from urllib.error import HTTPError
import mock
from postmark import (
PMBatchMail, PMMail, PMMailInactiveRecipientException,
- PMMailUnprocessableEntityException, PMMailServerErrorException
+ PMMailUnprocessableEntityException, PMMailServerErrorException,
+ PMBounceManager
)
from django.conf import settings
@@ -147,6 +150,15 @@ def test_500_error_server_error(self):
self.assertRaises(PMMailServerErrorException, batch.send)
+class PMBounceManagerTests(unittest.TestCase):
+ def test_activate(self):
+ bounce = PMBounceManager(api_key='test')
+
+ with mock.patch('postmark.core.HTTPConnection.getresponse') as mock_response:
+ mock_response.return_value = StringIO('{"test": "test"}')
+ self.assertEquals(bounce.activate(1), {'test': 'test'})
+
+
if __name__ == '__main__':
if not settings.configured:
settings.configure(

0 comments on commit c10085b

Please sign in to comment.