[pypy-svn] buildbot default: make email sending a global
RonnyPfannschmidt
commits-noreply at bitbucket.org
Wed Apr 20 15:53:26 CEST 2011
Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch:
Changeset: r463:70c9e99b114d
Date: 2011-04-19 12:17 +0200
http://bitbucket.org/pypy/buildbot/changeset/70c9e99b114d/
Log: make email sending a global
diff --git a/bitbucket_hook/hook.py b/bitbucket_hook/hook.py
--- a/bitbucket_hook/hook.py
+++ b/bitbucket_hook/hook.py
@@ -77,26 +77,26 @@
seen_nodes.add(key)
yield commit
+def send(from_, to, subject, body, test=False):
+ from email.mime.text import MIMEText
+ # Is this a valid workaround for unicode errors?
+ body = body.encode('ascii', 'xmlcharrefreplace')
+ msg = MIMEText(body, _charset='utf-8')
+ msg['From'] = from_
+ msg['To'] = to
+ msg['Subject'] = subject
+ if test:
+ print '#' * 20
+ print "Email contents:\n"
+ print from_
+ print to
+ print msg.get_payload(decode=True)
+ else:
+ smtp = SMTP(SMTP_SERVER, SMTP_PORT)
+ smtp.sendmail(from_, [to], msg.as_string())
class BitbucketHookHandler(object):
- def send(self, from_, to, subject, body, test=False):
- from email.mime.text import MIMEText
- # Is this a valid workaround for unicode errors?
- body = body.encode('ascii', 'xmlcharrefreplace')
- msg = MIMEText(body, _charset='utf-8')
- msg['From'] = from_
- msg['To'] = to
- msg['Subject'] = subject
- if test:
- print '#' * 20
- print "Email contents:\n"
- print from_
- print to
- print msg.get_payload(decode=True)
- else:
- smtp = SMTP(SMTP_SERVER, SMTP_PORT)
- smtp.sendmail(from_, [to], msg.as_string())
def send_irc_message(self, message, test=False):
@@ -173,7 +173,7 @@
'--template', template)
diff = self.get_diff(hgid, commit['files'])
body = body+diff
- self.send(sender, ADDRESS, subject, body, test)
+ send(sender, ADDRESS, subject, body, test)
def get_diff(self, hgid, files):
import re
diff --git a/bitbucket_hook/test/test_hook.py b/bitbucket_hook/test/test_hook.py
--- a/bitbucket_hook/test/test_hook.py
+++ b/bitbucket_hook/test/test_hook.py
@@ -9,12 +9,8 @@
def __init__(self):
hook.BitbucketHookHandler.__init__(self)
- self.mails = []
self.messages = []
- def send(self, from_, to, subject, body, test=False):
- self.mails.append((from_, to, subject, body))
-
def send_irc_message(self, message, test=False):
self.messages.append(message)
@@ -159,7 +155,7 @@
handler.handle(test_payload, test=True)
-def test_ignore_duplicate_commits(monkeypatch):
+def test_ignore_duplicate_commits(monkeypatch, mails):
def hg( *args):
return '<hg %s>' % ' '.join(map(str, args))
monkeypatch.setattr(hook, 'hg', hg)
@@ -179,7 +175,7 @@
handler.handle(payload)
#
num_commits = len(commits['commits'])
- assert len(handler.mails) == num_commits
+ assert len(mails) == num_commits
assert len(handler.messages) == num_commits
More information about the Pypy-commit
mailing list