Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverting debug and port values in Mailer.from_settings #67 #68

Merged
merged 3 commits into from
May 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ Contributors
- Supreet Sethi, 2013-07-23

- Nejc Zupan, 2013-11-08

- Mário Idival, 2015-05-21
5 changes: 5 additions & 0 deletions pyramid_mailer/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ def from_settings(cls, settings, prefix='mail.'):
if val:
kwargs[key] = asbool(val)

for key in ('debug', 'port'):
val = kwargs.get(key)
if val:
kwargs[key] = int(val)

# list values
for key in ('sendmail_template', ):
if key in kwargs:
Expand Down
36 changes: 36 additions & 0 deletions pyramid_mailer/tests/test_mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,42 @@ def test_from_settings(self):
self.assertEqual(mailer.sendmail_mailer.sendmail_template,
['{sendmail_app}', '--option1', '--option2', '{sender}'])

def test_from_settings_with_str_values(self):
from smtplib import SMTP
from pyramid_mailer._compat import SMTP_SSL
settings = {'mymail.host': 'my.server.com',
'mymail.port': '123',
'mymail.username': 'tester',
'mymail.password': 'test',
'mymail.tls': 'false',
'mymail.ssl': True,
'mymail.keyfile': 'ssl.key',
'mymail.certfile': 'ssl.crt',
'mymail.queue_path': '/tmp',
'mymail.debug': '1',
'mymail.sendmail_app': 'sendmail_app',
'mymail.sendmail_template':
'{sendmail_app} --option1 --option2 {sender}'}
mailer = self._getTargetClass().from_settings(settings,
prefix='mymail.')
self.assertEqual(mailer.direct_delivery.mailer.hostname,
'my.server.com')
self.assertEqual(mailer.direct_delivery.mailer.port, 123)
self.assertEqual(mailer.direct_delivery.mailer.username, 'tester')
self.assertEqual(mailer.direct_delivery.mailer.password, 'test')
self.assertEqual(mailer.direct_delivery.mailer.force_tls, False)
if SMTP_SSL is not None:
self.assertEqual(mailer.direct_delivery.mailer.smtp, SMTP_SSL)
else: # pragma: no cover
self.assertEqual(mailer.direct_delivery.mailer.smtp, SMTP)
self.assertEqual(mailer.direct_delivery.mailer.keyfile, 'ssl.key')
self.assertEqual(mailer.direct_delivery.mailer.certfile, 'ssl.crt')
self.assertEqual(mailer.queue_delivery.queuePath, '/tmp')
self.assertEqual(mailer.direct_delivery.mailer.debug_smtp, 1)
self.assertEqual(mailer.sendmail_mailer.sendmail_app, 'sendmail_app')
self.assertEqual(mailer.sendmail_mailer.sendmail_template,
['{sendmail_app}', '--option1', '--option2', '{sender}'])

def test_send_immediately(self):
import socket
mailer = self._makeOne(host='localhost', port='28322')
Expand Down