Module testing
source code
A bag of generally useful things when writing unit tests for your
Lamson server. The most important things are the spelling function and
using the TestConversation vs. RouterConversation to talk to your
server.
The TestConversation will use the lamson.server.Relay you have
configured to talk to your actual running Lamson server. Since by
default Lamson reloads each file you change it will work to run your
tests.
However, this isn't that fast, doesn't give you coverage analysis, and
doesn't let you test the results. For that you use RouterConversation to
do the exact same API (they should be interchangeable) but rather than
talk to a running server through the relay, it just runs all the messages
through the router directly.
This is faster and will give you code coverage as well as make sure
that all the modules (not just your handlers) will get reloaded.
The spelling function will use PyEnchant to spell check a string. If
it finds any errors it prints them out, and returns False.
|
|
TestConversation
Used to easily do conversations with an email server such that you
send a message and then expect certain responses.
|
|
|
RouterConversation
An implementation of TestConversation that routes the messages
internally to the Router, rather than connecting with a relay.
|
|
|
spelling(file_name,
contents,
language='en_US')
You give it a file_name and the contents of that file and it tells
you if it's spelled correctly. |
source code
|
|
|
|
relay(hostname='127.0.0.1',
port=8824)
Wires up a default relay on port 8824 (the default lamson log port). |
source code
|
|
|
|
queue(queue_dir='run/queue')
Creates a queue for you to analyze the results of a send, uses the
TEST_QUEUE setting in settings.py if that exists, otherwise defaults
to run/queue. |
source code
|
|
|
|
clear_queue(queue_dir='run/queue')
Clears the default test queue out, as created by
lamson.testing.queue. |
source code
|
|
|
|
delivered(pattern,
to_queue=None)
Checks that a message with that patter is delivered, and then returns
it. |
source code
|
|
|
|
|
spelling(file_name,
contents,
language='en_US')
| source code
|
You give it a file_name and the contents of that file and it tells you
if it's spelled correctly. The reason you give it contents is that you
will typically run a template through the render process, so spelling
can't just load a file and check it.
It assumes you have PyEnchant installed correctly and configured in
your config/testing.py file. Use "lamson spell" to make sure
it works right.
|
|
Wires up a default relay on port 8824 (the default lamson log
port).
|
|
Creates a queue for you to analyze the results of a send, uses the
TEST_QUEUE setting in settings.py if that exists, otherwise defaults to
run/queue.
|
|
Clears the default test queue out, as created by
lamson.testing.queue.
|
|
Checks that a message with that patter is delivered, and then returns
it.
It does this by searching through the queue directory and finding
anything that matches the pattern regex.
|
|
Makes sure a user is in a certain state for a certain user. Use these
sparingly, since every time you change your handler you'll have to change
up your tests. It's better to focus on the interaction with your handler
and expected outputs.
|