Пример #1
0
def test_post_data(mock_call_exchange):

    GIVEN("a market handler and some orders")
    market_handler = ExternalAPIMarketHandler(mediator=MockMediator(),
                                              environment="Dev",
                                              headers={},
                                              market_id=123456)
    orders = get_test_orders()

    WHEN("we post the orders")
    market_handler.post_order(orders=orders)
    THEN("the exchange was called with the correct request")
    args, kwargs = mock_call_exchange.call_args
    request = make_dict(kwargs.get("request"))
    expected_request = get_expected_request()
    assert args == ()
    assert request.get("params").get("instructions") == expected_request.get(
        "params").get("instructions")
Пример #2
0
def test_order_response(mock_notify, mock_open_url):
    GIVEN("a market handler and some orders")
    market_handler = ExternalAPIMarketHandler(mediator=MockMediator(),
                                              environment="Dev",
                                              headers={},
                                              market_id=123456)
    orders = get_test_orders()
    mock_open_url.return_value = get_test_orders_post_response()
    WHEN("we post the orders")
    response = market_handler.post_order(orders=orders)
    THEN("the notify method was called with the correct parameters")
    args, kwargs = mock_notify.call_args
    assert args == ()
    data = kwargs.get("data")
    assert data.get("orders") == orders
    assert kwargs.get("event") == "orders posted"

    response = data.get("response")
    assert isinstance(response, list)
    assert len(response) == 3
    for order in response:
        assert order.get("status") == "SUCCESS"