def test_destination_station_is_same_with_departure_station(self): mock_event = MagicMock() mock_event.source.user_id = mock_event.source.group_id = user_id = group = "123" mock_event.message.text = "新竹" qs_1 = THSR_QuestionState(group=group, user=user_id, departure_station="新竹") self.app.session.add(qs_1) with self.app.app_context(): result = ask_question_states(mock_event) self.assertEqual(result.text, "輸入的目的站與起程站皆是新竹,請重新輸入有效目的站")
def test_message_choosing_departure_station(self): mock_event = MagicMock() mock_event.source.user_id = mock_event.source.group_id = user_id = group = "123" mock_event.message.text = "新竹" qs_1 = THSR_QuestionState(group=group, user=user_id) self.app.session.add(qs_1) with self.app.app_context(): result = ask_question_states(mock_event) self.assertEqual(result.text, "請輸入目的站")
def test_multiple_question_states_exists(self): mock_event = MagicMock() mock_event.source.user_id = mock_event.source.group_id = user_id = group = "123" # Create two questions states qs_1 = THSR_QuestionState(group=group, user=user_id) self.app.session.add(qs_1) qs_2 = THSR_QuestionState(group=group, user=user_id) self.app.session.add(qs_2) with self.app.app_context(): result = ask_question_states(mock_event) # Should return None and expire all question states self.assertIsNone(result) q = self.app.session.query(THSR_QuestionState).all() self.assertEqual(len(q), 2) for i in q: self.assertEqual(i.expired, True)
def test_message_choosing_datetime(self): correct_items_in_result = ['0803', '07:02', '07:30', '0603', '07:27', '07:51', '0805', '07:47', '08:15', '1505', '08:12', '08:42'] event = PostbackEvent() mock_source = MagicMock() mock_source.user_id = mock_source.group_id = user_id = group = "123" event.source = mock_source mock_postback = MagicMock() mock_postback.params = {"datetime": "2018-06-05T07:00"} event.postback = mock_postback qs_1 = THSR_QuestionState(group=group, user=user_id, departure_station="新竹", destination_station="臺中") self.app.session.add(qs_1) with self.app.app_context(): result = ask_question_states(event) for item in correct_items_in_result: self.assertIn(item, result.template.text)
def test_message_choosing_datetime(self): correct_items_in_result = ['0051', '莒光', '07:19', '11:16', '0103', '自強', '07:40', '11:32', '0105', '自強', '08:14', '12:10', '0507', '莒光', '08:53', '14:15'] event = PostbackEvent() mock_source = MagicMock() mock_source.user_id = mock_source.group_id = user_id = group = "123" event.source = mock_source mock_postback = MagicMock() mock_postback.params = {"datetime": "2018-06-02T07:00"} event.postback = mock_postback qs_1 = TRA_QuestionState(group=group, user=user_id, departure_station="新竹", destination_station="高雄") self.app.session.add(qs_1) with self.app.app_context(): result = ask_question_states(event) for item in correct_items_in_result: self.assertIn(item, result.template.text)