salmon.testing module¶
A bag of generally useful things when writing unit tests for your Salmon server. The most important thing using the TestConversation vs. RouterConversation to talk to your server.
The TestConversation will use the salmon.server.Relay you have configured to talk to your actual running Salmon server. Since by default Salmon 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.
- class salmon.testing.RouterConversation(From, Subject)[source]¶
Bases:
salmon.testing.TestConversation
An implementation of TestConversation that routes the messages internally to the Router, rather than connecting with a relay. Use it in tests that are not integration tests.
This creates a set of default values for the conversation so that you can easily send most basic message. Each method lets you override the Subject and Body when you send.
- class salmon.testing.TestConversation(relay_to_use, From, Subject)[source]¶
Bases:
object
Used to easily do conversations with an email server such that you send a message and then expect certain responses.
This creates a set of default values for the conversation so that you can easily send most basic message. Each method lets you override the Subject and Body when you send.
- salmon.testing.assert_in_state(module, To, From, state)[source]¶
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.
- salmon.testing.clear_queue(queue_dir='run/queue')[source]¶
Clears the default test queue out, as created by salmon.testing.queue.
- salmon.testing.delivered(pattern, to_queue=None)[source]¶
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.