Commits

Mike Orr committed 6f5190b Merge

Merge changeset '60f426996a02' for unfinished/ directory.

  • Participants
  • Parent commits 7697166, 60f4269

Comments (0)

Files changed (5)

 functions. Currently `Pylons <http://pylons.groovie.org/>`_, `TurboGears
 <http://trac.turbogears.org/turbogears/wiki/RoutesIntegration>`_, and `Aquarium
 <http://aquarium.sourceforge.net/>`_ support Routes.
+
+Update 2008-04-29
+-----------------
+helpers.patch addresses some of the issues in helpers.py.
+
+test_mail.py is a test suite for webhelpers.mail.  It depends on an SMTP server
+being available, so we're unsure how to integrate it with the standard test
+suite.  
+
+wsgiapp_image.jpg is a file used by test_mail.py.

File 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()
++

File 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,
+    )
+

File unfinished/time.py

-import re, string
-
-class Time:
-    
-    def __init__(self):
-        self.seconds=['s','sec','seconds','seconds']
-        self.minutes=['min','minute','mins','minutes']
-        self.hours=['hr','hours','hour']
-        self.days=['day','days','d']
-        self.weeks=['w','week','weeks']
-        self.months=['month','months','mon']
-        
-    def getSeconds(self, parameter):
-        if parameter in self.seconds:   return 1
-        elif parameter in self.minutes: return 60
-        elif parameter in self.hours:   return 60 * 60
-        elif parameter in self.days:    return 60 * 60 * 24
-        elif parameter in self.weeks:   return 60 * 60 * 24 * 7
-        elif parameter in self.months:  return 60 * 60 * 24 * 30
-        else: return 0
-    
-    def convertIntoSeconds(self, age):
-        if age == None or age == '': return 0
-        if re.match('\d+$', age): return int(age)
-        match = re.match('(\d+)(' + string.join(self.seconds + self.minutes + self.hours + self.days + self.weeks + self.months, '|') + ')$', age)
-        if match != None:
-            number = int(match.group(1))
-            return number * self.getSeconds(match.group(2))
-        return -1
-        
-def seconds(value):
-    t = Time()
-    v = t.convertIntoSeconds(str(value))
-    if v == -1:
-        raise Exception('Invalid time, %s'%repr(value))
-    return v

File unfinished/wsgiapp_image.jpg

Added
New image