Пример #1
0
def test_register_topic_b():
    d = Dispatcher()
    m = MagicMock()

    @d.topic("merchant_order_request/+")
    def my_callback(arg1):
        m(arg1)

    d.dispatch("merchant_order_request/leonardo/123")
    m.assert_not_called()
Пример #2
0
def test_register_topic():
    d = Dispatcher()
    m = MagicMock()

    @d.topic("payment_requests/+")
    def my_callback(arg1):
        m(arg1)

    d.dispatch("payment_requests/leonardo")
    m.assert_called_with("leonardo")
Пример #3
0
def test_register_topic_multiple_args_pound():
    d = Dispatcher()
    m = MagicMock()

    assert d.callbacks == []

    @d.topic("payment_requests/+/subtopic/+/subtopic2/#")
    def my_callback3(*args):
        m(*args)

    d.dispatch("payment_requests/arg1/subtopic/arg2/subtopic2/arg3/arg4")
    m.assert_called_with("arg1", "arg2", "arg3", "arg4")
Пример #4
0
def test_register_topic_multiple_args_kwargs():
    d = Dispatcher()
    m = MagicMock()

    assert d.callbacks == []

    @d.topic("payment_requests/+/subtopic/+")
    def my_callback2(arg1, arg2, payload):
        m(arg1, arg2, payload)

    d.dispatch("payment_requests/arg1/subtopic/arg2", payload="my_payload")
    m.assert_called_with("arg1", "arg2", "my_payload")
Пример #5
0
 def __init__(self):
     self.d = Dispatcher(self)
Пример #6
0
def test_mqtt_to_regex():
    r = Dispatcher.mqtt_to_regex("payment_requests/+")
    assert "payment_requests/([^/]+)$" == r