pymilter  1.0.5
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
Milter.test.TestBase Class Reference

Test mixin for unit testing milter applications. More...

Inheritance diagram for Milter.test.TestBase:

Public Member Functions

def __init__ (self, logfile='test/milter.log')
 
def log (self, *msg)
 
def setsymval (self, name, val)
 Set a macro value. More...
 
def getsymval (self, name)
 
def replacebody (self, chunk)
 
def chgfrom (self, sender, params=None)
 
def quarantine (self, reason)
 
def progress (self)
 
def chgheader (self, field, idx, value)
 
def addheader (self, field, value, idx=-1)
 
def delrcpt (self, rcpt)
 
def addrcpt (self, rcpt)
 
def setreply (self, rcode, xcode, *msg)
 Save the reply codes and messages in self._reply.
 
def setsymlist (self, stage, macros)
 
def feedFile (self, fp, sender="spam@adv.com", rcpt="victim@lamb.com", *rcpts)
 Feed a file like object to the milter. More...
 
def feedMsg (self, fname, sender="spam@adv.com", *rcpts)
 Feed an email contained in a file to the milter. More...
 
def connect (self, host='localhost', helo='spamrelay', ip='1.2.3.4')
 Call the connect and helo callbacks. More...
 

Public Attributes

 logfp
 

Private Member Functions

def _close (self)
 

Private Attributes

 _protocol
 
 _sender
 The MAIL FROM for the current email being fed to the milter.
 
 _delrcpt
 List of recipients deleted.
 
 _addrcpt
 List of recipients added.
 
 _macros
 Macros defined.
 
 _body
 The message body.
 
 _bodyreplaced
 True if the milter replaced the message body.
 
 _headerschanged
 True if the milter changed any headers.
 
 _envfromchanged
 True if the milter changed the envelope from.
 
 _reply
 Reply codes and messages set by the milter.
 
 _msg
 The rfc822 message object for the current email being fed to the milter.
 
 _stage
 The protocol stage for macros returned.
 
 _symlist
 The macros returned by protocol stage.
 

Detailed Description

Test mixin for unit testing milter applications.

This mixin overrides many Milter.MilterBase methods with stub versions that simply record what was done.

Deprecated:
Use Milter.test.TestCtx
Since
0.9.8

Member Function Documentation

◆ connect()

def Milter.test.TestBase.connect (   self,
  host = 'localhost',
  helo = 'spamrelay',
  ip = '1.2.3.4' 
)

Call the connect and helo callbacks.

The helo callback is not called if connect does not return CONTINUE.

Parameters
hostthe hostname passed to the connect callback
helothe hostname passed to the helo callback
ipthe IP address passed to the connect callback

References Milter.test.TestBase._body, Milter.test.TestBase._bodyreplaced, Milter.Base._setctx(), Milter.test.TestBase._stage, Milter.Base.close(), Milter.Milter.close(), Milter.greylist.Greylist.close(), Milter.greysql.Greylist.close(), Milter.policy.DB.close(), Milter.policy.MTAPolicy.close(), Milter.sgmllib.SGMLParser.close(), Milter.sgmllib.TestSGMLParser.close(), Milter.Base.hello(), Milter.Milter.hello(), and Milter.Base.negotiate().

◆ feedFile()

def Milter.test.TestBase.feedFile (   self,
  fp,
  sender = "spam@adv.com",
  rcpt = "victim@lamb.com",
rcpts 
)

Feed a file like object to the milter.

Calls envfrom, envrcpt for each recipient, header for each header field, body for each body block, and finally eom. A return code from the milter other than CONTINUE returns immediately with that return code.

This is a convenience method, a test could invoke the callbacks in sequence on its own - and for some complex tests, this may be necessary.

Parameters
fpthe file with rfc2822 message stream
senderthe MAIL FROM
rcptRCPT TO - additional recipients may follow

References Milter.test.TestBase._body, Milter.test.TestBase._bodyreplaced, Milter.test.TestBase._close(), Milter.test.TestBase._headerschanged, Milter.test.TestBase._msg, Milter.test.TestBase._reply, Milter.test.TestBase._sender, Milter.test.TestBase._stage, Milter.Base.body(), Milter.Base.close(), Milter.Milter.close(), Milter.greylist.Greylist.close(), Milter.greysql.Greylist.close(), Milter.policy.DB.close(), Milter.policy.MTAPolicy.close(), Milter.sgmllib.SGMLParser.close(), Milter.sgmllib.TestSGMLParser.close(), Milter.Base.data(), Milter.Base.envfrom(), Milter.Milter.envfrom(), Milter.Base.envrcpt(), Milter.Milter.envrcpt(), Milter.Base.eoh(), Milter.Milter.eoh(), Milter.Base.eom(), Milter.Milter.eom(), and Milter.Base.header_bytes.

Referenced by Milter.test.TestBase.feedMsg().

◆ feedMsg()

def Milter.test.TestBase.feedMsg (   self,
  fname,
  sender = "spam@adv.com",
rcpts 
)

Feed an email contained in a file to the milter.

This is a convenience method that invokes feedFile .

Parameters
senderMAIL FROM
rcptsRCPT TO, multiple recipients may be supplied

References Milter.test.TestBase.feedFile().

◆ setsymval()

def Milter.test.TestBase.setsymval (   self,
  name,
  val 
)

Set a macro value.

These are retrieved by the milter with getsymval.

Parameters
namethe macro name, as passed to getsymval
valthe macro value

References Milter.test.TestBase._body, Milter.test.TestBase._bodyreplaced, Milter.test.TestBase._envfromchanged, Milter.test.TestBase._macros, Milter.test.TestBase._sender, Milter.test.TestBase._stage, Milter.test.TestBase._symlist, Milter.Base.log(), Milter.Milter.log(), and Milter.test.TestBase.log().


The documentation for this class was generated from the following file: