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

## 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

  host | the hostname passed to the connect callback
  helo | the hostname passed to the helo callback
  ip | the IP address passed to the connect callback

References _body, _bodyreplaced, Milter.Base._setctx(), _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(), connect(), Milter.Base.hello(), Milter.Milter.hello(), and Milter.Base.negotiate().

Referenced by 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

  fp | the file with rfc2822 message stream
  sender | the MAIL FROM
  rcpt | RCPT TO - additional recipients may follow

References _body, _bodyreplaced, _close(), _headerschanged, _msg, _reply, _sender, _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 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

  sender | MAIL FROM
  rcpts | RCPT TO, multiple recipients may be supplied

References feedFile().

## setsymval()

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

Set a macro value.

These are retrieved by the milter with getsymval.

Parameters

  name | the macro name, as passed to getsymval
  val | the macro value

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

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

- Milter/test.py