Commits

Mike Orr committed 60f4269

Add three unfinished files from James.

Comments (0)

Files changed (3)

unfinished/helpers.patch

+diff -r 5b974015c354 unfinished/helpers.py
+--- a/unfinished/helpers.py	Thu Apr 24 10:59:10 2008 -0700
++++ b/unfinished/helpers.py	Mon Apr 28 16:28:41 2008 +0100
+@@ -2,8 +2,6 @@
+ A series of useful helper functions which aren't found in other libraries.
+ """
+ 
+-from time import seconds
+-import jimmyg.helpers.mail as mail
+ 
+ def divide(a,b):
+     """\
+@@ -12,9 +10,9 @@
+     For example::
+ 
+         >>> divide(3,2)
+-        >>> 1.5
++        1.5
+         >>> divide(3,1)
+-        >>> 3
++        3
+     """
+     if a%b:
+         return a/float(b)
+@@ -79,8 +77,9 @@
+         '522.3 KB'
+ 
+     >>> size_to_human(534813)
++    '522.3 KB'
+     >>> size_to_human(534813, format='decimal')
+-
++    '534.8 KB'
+     """
+     if format == 'binary':  
+         format = 1024
+@@ -106,3 +105,7 @@
+         size = long(size)
+     return "%s %s"%(size, units[counter])
+ 
++if __name__ == '__main__':
++    import doctest
++    doctest.testmod()
++

unfinished/test_mail.py

+#!/usr/bin/env python
+
+"""Test program to send mail to recipients.
+
+Use the -s option with nose to have the verbose output logged and for the raw_input text to be displayed.
+
+So, you run this test like this from the root of the webhelpers.mail package::
+    
+    ~/bin/nosetests test/test_mail.py -s 
+"""
+import sys; sys.path.append('../')
+import webhelpers.mail
+
+# Simulate a Pylons helpers setup
+class H:
+    mail = webhelpers.mail
+h=H()
+
+def setup():
+    global address, ccaddress, bccaddress, smtp, username, password
+    address = raw_input('Email address to recieve tests: ')
+    ccaddress = raw_input('Email another address to recieve tests: ')
+    bccaddress = raw_input('Email another address to recieve tests: ')
+    smtp = raw_input('SMTP Server: ')
+    username = raw_input('Username: ')
+    password = raw_input('Password: ')
+
+def test_sendmail_plain():
+    h.mail.send(
+        h.mail.plain(
+            "Hi Jim\n\nHere's the photo from sendmail.\n\nJames",
+            from_name = 'James Gardner',
+            from_email = address,
+            to=[address], 
+            subject='Holiday Photos',
+        ),
+        sendmail='/usr/sbin/sendmail',
+        verbose=True
+    )
+
+def test_sendmail_multi():
+    h.mail.send(
+        h.mail.multi(
+            parts = [
+                h.mail.part("Here is the photo from sendmail again.", content_type="text/plain", attach=False),
+                h.mail.part(filename='test/attachment.jpg'),
+            ],
+            from_name = 'James Gardner',
+            from_email = address,
+            to=['Test Address <'+address+'>'], 
+            cc=['Test Address CC <'+ccaddress+'>'], 
+            bcc=['Test Address BCC <'+bccaddress+'>'], 
+            subject='Holiday Photos',
+        ),
+        smtp=smtp,
+        username=username,
+        password = password,
+        verbose=True,
+    )
+
+def test_smtp_plain():
+    h.mail.send(
+        h.mail.plain(
+            "Hi Jim\n\nHere's the photo from SMTP.\n\nJames",
+            from_name = 'James Gardner',
+            from_email = address,
+            to=[address], 
+            subject='Holiday Photos',
+        ),
+        smtp=smtp,
+        username=username,
+        password = password,
+        verbose=True,
+    )
+    
+def test_smtp_multi():
+    h.mail.send(
+        h.mail.multi(
+            parts = [
+                h.mail.part("Here is the photo from SMTP again.", content_type="text/plain", attach=False),
+                h.mail.part(filename='test/attachment.jpg'),
+            ],
+            from_name = 'James Gardner',
+            from_email = address,
+            to=['Test Address <'+address+'>'], 
+            cc=['Test Address CC <'+ccaddress+'>'], 
+            bcc=['Test Address BCC <'+bccaddress+'>'], 
+            subject='Holiday Photos',
+        ),
+        smtp=smtp,
+        username=username,
+        password = password,
+        verbose=True,
+    )
+
+def test_smtp_html():
+    h.mail.send(
+        h.mail.multi(
+            parts = [
+                h.mail.part("<html>This is an <b>html</b> email</html>", content_type="text/html", attach=False),
+                h.mail.part(filename='test/attachment.jpg'),
+            ],
+            preamble='This is an HTML email but your email client does not support mulit-part emails.',
+            from_name = 'James Gardner',
+            from_email = address,
+            to=[address], 
+            subject='Holiday Photos',
+        ),
+        smtp=smtp,
+        username=username,
+        password = password,
+        verbose=True,
+    )
+

unfinished/wsgiapp_image.jpg

Added
New image