Permalink
Browse files

added mailer factory function

  • Loading branch information...
1 parent fc2bc79 commit 31475a5da8eab2758381a57e3affb1a43a3fb01b @danjac danjac committed Feb 25, 2011
Showing with 43 additions and 5 deletions.
  1. +4 −0 pyramid_mailer/__init__.py
  2. +39 −5 pyramid_mailer/tests.py
@@ -0,0 +1,4 @@
+from pyramid_mailer.mailer import Mailer
+
+def mailer_factory_from_settings(settings, prefix='mail.'):
+ return Mailer.from_settings(settings, prefix)
View
@@ -366,23 +366,23 @@ def test_use_ssl_mailer(self):
from ssl import SSLError
try:
self.assert_(mailer.direct_delivery.mailer.smtp_factory())
- except SSLError:
+ except (IOError, SSLError):
pass
else:
self.assert_(mailer.direct_delivery.mailer.smtp == SMTP)
self.assert_(mailer.direct_delivery.mailer.smtp_factory())
- def test_from_settings(self):
-
+ def test_from_settings_factory(self):
+
try:
from smtplib import SMTP_SSL
ssl_enabled = True
except ImportError:
from smtplib import SMTP
ssl_enabled = False
- from pyramid_mailer.mailer import Mailer
+ from pyramid_mailer import mailer_factory_from_settings
settings = {'mymail.host' : 'my.server.com',
'mymail.port' : 123,
@@ -395,7 +395,7 @@ def test_from_settings(self):
'mymail.queue_path' : '/tmp',
'mymail.debug' : 1}
- mailer = Mailer.from_settings(settings, prefix='mymail.')
+ mailer = mailer_factory_from_settings(settings, prefix='mymail.')
self.assert_(mailer.direct_delivery.mailer.hostname=='my.server.com')
self.assert_(mailer.direct_delivery.mailer.port==123)
@@ -413,7 +413,41 @@ def test_from_settings(self):
self.assert_(mailer.direct_delivery.mailer.debug_smtp == 1)
+ def test_from_settings(self):
+
+ try:
+ from smtplib import SMTP_SSL
+ ssl_enabled = True
+ except ImportError:
+ from smtplib import SMTP
+ ssl_enabled = False
+ from pyramid_mailer.mailer import Mailer
+ settings = {'mymail.host' : 'my.server.com',
+ 'mymail.port' : 123,
+ 'mymail.username' : 'tester',
+ 'mymail.password' : 'test',
+ 'mymail.tls' : True,
+ 'mymail.ssl' : True,
+ 'mymail.keyfile' : 'ssl.key',
+ 'mymail.certfile' : 'ssl.crt',
+ 'mymail.queue_path' : '/tmp',
+ 'mymail.debug' : 1}
+ mailer = Mailer.from_settings(settings, prefix='mymail.')
+ self.assert_(mailer.direct_delivery.mailer.hostname=='my.server.com')
+ self.assert_(mailer.direct_delivery.mailer.port==123)
+ self.assert_(mailer.direct_delivery.mailer.username=='tester')
+ self.assert_(mailer.direct_delivery.mailer.password=='test')
+ self.assert_(mailer.direct_delivery.mailer.force_tls==True)
+ if ssl_enabled:
+ self.assert_(mailer.direct_delivery.mailer.smtp == SMTP_SSL)
+ else:
+ self.assert_(mailer.direct_delivery.mailer.smtp == SMTP)
+
+ self.assert_(mailer.direct_delivery.mailer.keyfile == 'ssl.key')
+ self.assert_(mailer.direct_delivery.mailer.certfile == 'ssl.crt')
+ self.assert_(mailer.queue_delivery.queuePath == '/tmp')
+ self.assert_(mailer.direct_delivery.mailer.debug_smtp == 1)

0 comments on commit 31475a5

Please sign in to comment.