def test__query_score_should_call_next_setup_message_correctly_when_step_1( self): tcb = TelegramController() tcb.in_progress_step = 1 tcb.operator = MagicMock() tcb._send_text_message = MagicMock() tcb._send_image_message = MagicMock() tcb._query_score("1") tcb.operator.get_score.assert_called_once() tcb._send_text_message.assert_called_once_with("조회중입니다", tcb.main_keyboard) self.assertEqual(tcb.in_progress, None) self.assertEqual(tcb.in_progress_step, 0) self.assertEqual(tcb.operator.get_score.call_args[0][1], (60 * 6, -1)) callback = tcb.operator.get_score.call_args[0][0] callback(None) tcb._send_text_message.assert_called_with("수익률 조회중 문제가 발생하였습니다.", tcb.main_keyboard) callback((100, 200, 0.5, 0.9, "test.jpg", 0, 0, 0, ("12-01", "12-05", "12-08"))) tcb._send_text_message.assert_called_with( "12-05 - 12-08\n자산 100 -> 200\n구간 수익률 100.0\n12-01~\n누적 수익률 0.5\n비교 수익률 0.9\n", tcb.main_keyboard, ) tcb._send_image_message.assert_called_with("test.jpg")
def test__query_state_should_call__send_text_message_with_correct_message( self): tcb = TelegramController() tcb._send_text_message = MagicMock() tcb._query_state("state") tcb._send_text_message.assert_called_with("자동 거래 시작 전입니다") tcb.operator = "mango" tcb._query_state("state") tcb._send_text_message.assert_called_with("자동 거래 운영 중입니다")
def test__query_score_should_reset_with_wrong_input_when_step_1(self): tcb = TelegramController() tcb.in_progress_step = 1 tcb.operator = MagicMock() tcb._send_text_message = MagicMock() tcb._query_score("7") wrong_message = "다시 시작해 주세요" tcb._send_text_message.assert_called_once_with(wrong_message, tcb.main_keyboard) self.assertEqual(tcb.in_progress, None) self.assertEqual(tcb.in_progress_step, 0)
def test__query_score_should_call_next_setup_message_correctly_when_step_0( self): tcb = TelegramController() tcb.in_progress_step = 0 tcb.operator = MagicMock() tcb._send_text_message = MagicMock() tcb._query_score("1") tcb._send_text_message.assert_called_once_with( tcb.score_query_list[0]["guide"], tcb.score_query_list[0]["keyboard"]) self.assertEqual(tcb.in_progress, tcb._query_score) self.assertEqual(tcb.in_progress_step, 1)
def test__stop_trading_should_reset_all_variable_related_operating(self): tcb = TelegramController() tcb.operator = MagicMock() tcb.strategy = "mango_strategy" tcb.data_provider = "mango_data_provider" tcb.trader = "mango_trader" tcb.budget = "mango_budget" tcb.operator.stop = MagicMock( return_value={ "summary": (100, 200, 0.5, 0.9, "test.jpg", 0, 0, 0, ("12-01", "12-05", "12-08")) }) tcb._send_text_message = MagicMock() tcb._stop_trading("2") tcb._send_text_message.assert_called_once_with( "자동 거래가 중지되었습니다\n12-05 - 12-08\n자산 100 -> 200\n수익률 0.5\n비교 수익률 0.9\n", tcb.main_keyboard) self.assertEqual(tcb.operator, None) self.assertEqual(tcb.strategy, None) self.assertEqual(tcb.data_provider, None) self.assertEqual(tcb.trader, None) self.assertEqual(tcb.budget, None)