pymilter 1.0.5
Milter.test.TestBase Class Reference

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

Inheritance diagram for Milter.test.TestBase:

Public Member Functions

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

Public Attributes

 logfp = open(logfile,"a")
 
str _body = '':
 
list _bodyreplaced = [ Milter.CURR_ACTS,~0,0,0 ]
 

Protected Member Functions

 _close (self)
 

Protected Attributes

int _protocol = 0
 
str _sender = None
 The MAIL FROM for the current email being fed to the milter.
 
list _delrcpt = []
 List of recipients deleted.
 
list _addrcpt = []
 List of recipients added.
 
dict _macros = { }
 Macros defined.
 
 _body = None
 The message body.
 
bool _bodyreplaced = False
 True if the milter replaced the message body.
 
bool _headerschanged = False
 True if the milter changed any headers.
 
bool _envfromchanged = False
 True if the milter changed the envelope from.
 
tuple _reply = None
 Reply codes and messages set by the milter.
 
 _msg = None
 The rfc822 message object for the current email being fed to the milter.
 
int _stage = None
 The protocol stage for macros returned.
 
list _symlist = [ None, None, None, None, None, None, None ]
 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()

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.testctx.TestCtx._body, Milter.test.TestBase._bodyreplaced, Milter.testctx.TestCtx._bodyreplaced, Milter.Base._setctx(), Milter.test.TestBase._stage, Milter.testctx.TestCtx._stage, Milter.Base.close(), Milter.greylist.Greylist.close(), Milter.greysql.Greylist.close(), Milter.Milter.close(), Milter.policy.DB.close(), Milter.policy.MTAPolicy.close(), Milter.sgmllib.SGMLParser.close(), Milter.sgmllib.TestSGMLParser.close(), Milter.test.TestBase.connect(), Milter.Base.hello(), Milter.Milter.hello(), and Milter.Base.negotiate().

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

◆ feedFile()

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.testctx.TestCtx._body, Milter.test.TestBase._bodyreplaced, Milter.testctx.TestCtx._bodyreplaced, Milter.test.TestBase._close(), Milter.testctx.TestCtx._close(), Milter.test.TestBase._headerschanged, Milter.testctx.TestCtx._headerschanged, Milter.test.TestBase._msg, Milter.testctx.TestCtx._msg, Milter.test.TestBase._reply, Milter.testctx.TestCtx._reply, Milter.test.TestBase._sender, Milter.testctx.TestCtx._sender, Milter.test.TestBase._stage, Milter.testctx.TestCtx._stage, Milter.Base.body(), Milter.Base.close(), Milter.greylist.Greylist.close(), Milter.greysql.Greylist.close(), Milter.Milter.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(), Milter.Base.header_bytes(), and Milter.Base.header_bytes.

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

◆ feedMsg()

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

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

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