Tests

Unit Tests

test_consumer

order_prep.tests.unit.test_consumer.test_consume_order(*args, **keywargs)

Test a call to consume_order() under normal circumstances.

Test that a call to consume_order() calls order_prep.preparation.prepare_order() with the order passed to it. As prepare_order() is successful (i.e. it does not raise an exception), no critical-level logging should occur, and the message should be acknowledged.

order_prep.tests.unit.test_consumer.test_consume_order_exception(*args, **keywargs)

Test a call to consume_order() where order processing fails.

Test that a call to consume_order() logs a critical-level message but does not itself raise an exception when order_prep.preparation.prepare_order() fails (i.e. raises an exception). The message should not be acknowledged.

test_preparation

order_prep.tests.unit.test_preparation.assert_not_order_lines_unchanged(before, after)

Assert all keys but order_lines unchanged in before and after.

order_prep.tests.unit.test_preparation.test_add_completion_stages()

Test add_completion_stages adds completion stages as expected.

This breaks down in to two parts:

Invariant testing
add_completion_stages should never modify any keys in the given order but order_lines.
Application/business logic
add_completion_stages currently does nothing and therefore returns the given order unmodified.
order_prep.tests.unit.test_preparation.test_normalise_lines()

Test normalise_lines splits order lines as expected.

This breaks down in to two parts:

Invariant testing
normalise_lines should never modify any keys in the given order but order_lines.
Application/business logic
normalise_lines currently does nothing and therefore returns the given order unmodified.
order_prep.tests.unit.test_preparation.test_prepare_order(*args, **keywargs)

Test prepare_order normalises lines before adding completion stages.

Also tests that prepare_order never modifies any keys in the given order but order_lines.

test_publisher

order_prep.tests.unit.test_publisher.test_get_producer(*args, **keywargs)

Test get_producer() uses Kombu appropriately.

order_prep.tests.unit.test_publisher.test_publish_order(*args, **keywargs)

Test that publish_order() publishes given order.

test_run

order_prep.tests.unit.test_run.test_connect_consumer(*args, **keywargs)

Test connect_consumer() uses settings to connect to queue.

order_prep.tests.unit.test_run.test_runloop(*args, **keywargs)

Test that runloop() repeatedly consumes from the connection.

This is done using the order_prep.tests.unit.tools.StatefulSideEffect class to check that the connection returned by connect_consumer() is called an appropriate number of times before an exception is raised.

order_prep.tests.unit.test_run.test_runloop_interrupt(*args, **keywargs)

Test that runloop() exits gracefully on interrupt.

test_tests

order_prep.tests.unit.test_tests.test_assert_not_order_lines_unchanged()

Test that equivalent before and after pass.

order_prep.tests.unit.test_tests.test_assert_not_order_lines_unchanged_changes()

Test that different before and after fail.

order_prep.tests.unit.test_tests.test_assert_not_order_lines_unchanged_order_lines_changed()

Test that different order_lines pass.

tools

class order_prep.tests.unit.tools.StatefulSideEffect(call_count)

A class that raises an exception after n calls of side_effect().

This should be used with Mock like this:

Mock(side_effect=StatefulSideEffect(7).side_effect)

Parameters:

call_count
The call on which the StatefulSideEffectException should be raised (i.e. side_effect() will have been called call_count times when the StatefulSideEffectException is raised).
side_effect(*args, **kwargs)

The method to pass to the Mock.

exception order_prep.tests.unit.tools.StatefulSideEffectException

The exception used by StatefulSideEffect.

order_prep.tests.unit.tools.assert_called_once(mock, expected_args=None, expected_kwargs=None)

Assert mock called once with expected args/kwargs.

order_prep.tests.unit.tools.assert_called_once_with_only_args(mock, expected_args)

Assert mock called once with expected_args and no keywords.

order_prep.tests.unit.tools.assert_called_once_with_only_kwargs(mock, expected_kwargs)

Asserts mock called once with kwargs only.

Functional Tests

order_prep.tests.functional.test_order_prep.test_order_prep(*args, **keywargs)

Test that order_prep processes good input properly.

Currently, the order preparation service should pass through all input unmodified.

This is tested by passing example input in to order_prep.consumer.consume_order() and checking that order_prep.publisher.publish_order() calls kombu.messaging.Producer.publish() with the same input.

Table Of Contents

Previous topic

Internals

This Page