[TIP] (Unit | Functional) testing of imaplib apps .

Kumar McMillan kumar.mcmillan at gmail.com
Wed Nov 10 08:59:10 PST 2010


On Mon, Nov 1, 2010 at 8:46 AM, Olemis Lang <olemis at gmail.com> wrote:
> Hi !
>
> I'm developing an IMAP4-based app using `imaplib` . I'd like to know
> what's used to either mock (for unit tests) or launch a lightweight
> (in-memory ?) IMAP server (for functional tests), and how to
> setup all this at testing-time.

As another reply mentioned, I think it doesn't hurt to setup a real
IMAP account and run some tests against it (maybe during CI since they
will be slow).  But for error handling it would help to have mock
objects.  Also, the IMAP spec isn't going to change anytime soon.  I
used Fudge -- http://farmdev.com/projects/fudge/ -- for some error
checking once like this:

import fudge
from fudge import patched_context
from nose.tools import raises

from campsite.lib import safe_imaplib

@raises(safe_imaplib.IMAPResponseNotOK)
def test_safe_imap_raises_exceptions():
    StubIMAP4_SSL = (fudge.Fake('IMAP4_SSL')
                            .provides('__init__')
                            .with_args("<some server>")
                            .provides('login')
                            .with_args("<user>", "<password>")
                            .returns(('OK', '<ignored>'))
                            .provides('select')
                            .returns(('FAILED', '<ignored>'))
                    )

    with patched_context(safe_imaplib, 'IMAP4_SSL', StubIMAP4_SSL):
        imap = safe_imaplib.SafeIMAP4_SSL("<some server>")
        imap.login("<user>", "<password>")
        imap.select()


-Kumar

>
> Right now what I do is to use a local `hMailServer` instance on
> Windows , but it's so «lightweight» that I even had to install
> MySql and ... to make it work . So I'm hoping there's something
> out there like `twill` or `wsgi_intercept` that may help under
> these circumstances .
>
> Thnx in advance !
>
>
> --
> Regards,
>
> Olemis.
>
> Blog ES: http://simelo-es.blogspot.com/
> Blog EN: http://simelo-en.blogspot.com/
>
> Featured article:
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>



More information about the testing-in-python mailing list