def test__update_order_result_should_NOT_start_timer_when_no_request_remains( self): dummy_result = [ { "data": { "order_status": "Completed", "order_id": "mango", "state": "done", "transaction_date": "1572497603668315", "order_price": 500, "order_qty": 0.007, }, }, { "data": { "order_status": "Completed", "order_id": "apple", "state": "cancel", "transaction_date": "1572498603668315", "order_price": 1500, "order_qty": 0.54321, }, }, ] dummy_request_mango = { "order_id": "mango_order", "request": { "id": "mango_id" }, "callback": MagicMock(), "result": { "id": "mango_result", "state": "done", "type": "buy" }, } dummy_request_apple = { "order_id": "apple_order", "request": { "id": "apple_id" }, "callback": MagicMock(), "result": { "id": "apple_result", "state": "done", "type": "buy" }, } trader = BithumbTrader() trader._call_callback = MagicMock() trader._query_order = MagicMock(side_effect=dummy_result) trader._stop_timer = MagicMock() trader._start_timer = MagicMock() trader.order_map["mango"] = dummy_request_mango trader.order_map["apple"] = dummy_request_apple trader._update_order_result(None) self.assertEqual( trader._query_order.call_args_list, [call("mango_order"), call("apple_order")], ) self.assertEqual(len(trader.order_map), 0) trader._stop_timer.assert_called_once() trader._start_timer.assert_not_called()
def test__update_order_result_should_call__call_callback_and_keep_waiting_request( self): dummy_result = [ { "data": { "order_status": "Completed", "order_id": "mango", "state": "done", "transaction_date": "1572497603668315", "order_price": 500, "order_qty": 0.007, "contract": [{ "transaction_date": "1572497603668315", }], }, }, { "data": { "order_status": "Waiting", "order_id": "banana", "state": "cancel", "transaction_date": "1572498603668315", "order_price": 1500, "order_qty": 0.54321, "contract": [{ "transaction_date": "1572498603668315", }], }, }, { "data": { "order_status": "Completed", "order_id": "apple", "state": "cancel", "transaction_date": "1572498603668315", "order_price": 1500, "order_qty": 0.54321, "contract": [{ "transaction_date": "1572498603668315", }], }, }, ] dummy_request_mango = { "order_id": "mango_order", "request": { "id": "mango_id" }, "callback": MagicMock(), "result": { "state": "done", "type": "buy" }, } dummy_request_banana = { "order_id": "banana_order", "request": { "id": "banana_id" }, "callback": MagicMock(), "result": { "state": "done", "type": "sell" }, } dummy_request_apple = { "order_id": "apple_order", "request": { "id": "apple_id" }, "callback": MagicMock(), "result": { "state": "done", "type": "buy" }, } trader = BithumbTrader() trader._call_callback = MagicMock() trader._query_order = MagicMock(side_effect=dummy_result) trader._stop_timer = MagicMock() trader._start_timer = MagicMock() trader.order_map["mango"] = dummy_request_mango trader.order_map["banana"] = dummy_request_banana trader.order_map["apple"] = dummy_request_apple trader._update_order_result(None) self.assertEqual( trader._query_order.call_args_list, [call("mango_order"), call("banana_order"), call("apple_order")], ) trader._call_callback.assert_called() mango_result = trader._call_callback.call_args_list[0][0][1] self.assertEqual(mango_result["date_time"], "2019-10-31T13:53:23") self.assertEqual(mango_result["price"], 500) self.assertEqual(mango_result["type"], "buy") self.assertEqual(mango_result["state"], "done") self.assertEqual(mango_result["amount"], 0.007) self.assertEqual(trader._call_callback.call_args_list[0][0][0], dummy_request_mango["callback"]) apple_result = trader._call_callback.call_args_list[1][0][1] self.assertEqual(apple_result["date_time"], "2019-10-31T14:10:03") self.assertEqual(apple_result["price"], 1500) self.assertEqual(mango_result["type"], "buy") self.assertEqual(mango_result["state"], "done") self.assertEqual(apple_result["amount"], 0.54321) self.assertEqual(trader._call_callback.call_args_list[1][0][0], dummy_request_apple["callback"]) self.assertEqual(len(trader.order_map), 1) self.assertEqual(trader.order_map["banana"]["request"]["id"], "banana_id") trader._stop_timer.assert_called_once() trader._start_timer.assert_called_once()