[Zope3-dev] Re: [Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/SmtpService/Views - __init__.py:1.1 configure.zcml:1.1

Steve Alexander steve@cat-box.net
Sun, 27 Oct 2002 22:24:41 +0200


>> The main problem is that there are no unit tests.
> 
> I told Merthy that he could skip unit tests, at least for the content
> class because, frankly, I couldn't think of how he would write them,
> The class does pretty much nothing but send mail. You don't want to
> send mail in a unit test.  The only way I could see to do this would
> be to actually write an SMTP server that the class could connect to.
> I suppose that this would be possible, but it would, obviously, be a
> significant effort.

The implementation basically processes its input, instantiates a python 
library SMTP object, and makes calls that object.

We should be testing the "processes its input" part at least. We can do 
that by writing the class so that it allows us to configure a factory to 
produce SMTP objects. The default is to use the one in the Python 
library. For the test, we make use an SMTP factory that produces an 
object that remembers the calls made to it, and allows us to query these 
calls later.

Something like the following should do:

class SMTP:

     def __init__(self, host, port):
         self.host = host
         self.port = port

     def sendmail(self, from, to, text):
         self.from = from
         self.to = to
         self.text = text

     # used by unit tests
     def compare(self, **kw): host, port, from, to, text):
         for key, value in kw:
             if getattr(self, key) != value:
                 raise ValueError, '%s:%s' % (key, value)


--
Steve Alexander