def test_get_account_info_should_return_correct_info(self): dummy_respone = [ { "currency": "KRW", "balance": 123456789 }, { "currency": "APPLE", "balance": 500, "avg_buy_price": 23456 }, ] trader = BithumbTrader() trader.balance = 123456789 trader.asset = (23456, 500) trader.market = "APPLE" trader.worker = MagicMock() trader.get_trade_tick = MagicMock(return_value={ "status": "0000", "data": [{ "price": 777 }] }) result = trader.get_account_info() self.assertEqual(result["balance"], 123456789) self.assertEqual(result["asset"], {"APPLE": (23456, 500)}) self.assertEqual(result["quote"], {"APPLE": 777}) self.assertEqual("date_time" in result, True) trader.get_trade_tick.assert_called_once_with()
def test_start_timer_should_start_Timer(self, mock_timer): trader = BithumbTrader() trader.worker = MagicMock() trader._start_timer() mock_timer.assert_called_once_with(trader.RESULT_CHECKING_INTERVAL, ANY) callback = mock_timer.call_args[0][1] callback() trader.worker.post_task.assert_called_once_with( {"runnable": trader._update_order_result})
def test_send_request_should_call_worker_post_task_correctly(self): trader = BithumbTrader() trader.worker = MagicMock() trader.send_request(["mango", "orange"], "banana") trader.worker.post_task.assert_called() called_arg = trader.worker.post_task.call_args_list[0][0][0] self.assertEqual(called_arg["runnable"], trader._execute_order) self.assertEqual(called_arg["request"], "mango") self.assertEqual(called_arg["callback"], "banana") called_arg = trader.worker.post_task.call_args_list[1][0][0] self.assertEqual(called_arg["runnable"], trader._execute_order) self.assertEqual(called_arg["request"], "orange") self.assertEqual(called_arg["callback"], "banana")