class IntentRequestTest(unittest.TestCase): def setUp(self): with open('../json/intent_request.json') as f: self.data = f.read() self.data = json.loads(self.data) self.request = Request(self.data) def testGetData(self): ''' 测试getData方法 :return: ''' self.assertEqual(self.request.get_data(), self.data) def testGetNlu(self): ''' 测试getNlu方法 :return: ''' nlu = Nlu(self.data['request']['intents']) self.assertEqual(self.request.get_nlu().to_directive(), nlu.to_directive()) def testGetAudioPlayerContext(self): ''' 测试getAudioPlayerContext方法 :return: ''' pass def testGetType(self): ''' 测试getType方法 :return: ''' self.assertEqual(self.request.get_type(), 'IntentRequest') def testGetUserId(self): ''' 测试getUserId方法 :return: ''' self.assertEqual(self.request.get_user_id(), 'userId') def testGetQuery(self): ''' 测试getQuery方法 :return: ''' self.assertEqual(self.request.get_query(), '所得税查询') def testIsLaunchRequest(self): ''' 测试isLaunchRequest方法 :return: ''' self.assertFalse(self.request.is_launch_request()) def testIsSessionEndRequest(self): ''' 测试isSessionEndRequest方法 :return: ''' self.assertFalse(self.request.is_session_end_request()) def testIsSessionEndedRequest(self): ''' 测试isSessionEndedRequest方法 :return: ''' self.assertFalse(self.request.is_session_ended_request()) def testGetBotId(self): ''' 测试getBotId方法 :return: ''' self.assertEquals(self.request.get_bot_id(), 'botId') def testIsDialogStateCompleted(self): ''' 测试isDialogStateCompleted方法 :return: ''' self.assertFalse(self.request.is_dialog_state_completed()) pass
class LaunchRequsetTest(unittest.TestCase): def setUp(self): with open('../json/launch.json') as f: self.data = f.read() self.data = json.loads(self.data) self.request = Request(self.data) def testGetData(self): ''' 测试getData方法 :return: ''' self.assertEqual(self.request.get_data(), self.data) def testGetSession(self): session = Session(self.data['session']) self.assertEqual(self.request.get_session().to_response(), session.to_response()) def testGetDeviceId(self): ''' 测试getDeviceId方法 :return: ''' self.assertEqual(self.request.get_device_id(), 'deviceId') def testGetUserInfo(self): ''' 测试getUserInfo方法 :return: ''' userInfo = { "account": { "baidu": { "baiduUid": "baiduUid" } }, "location": { "geo": { "bd09ll": { "longitude": 12.12, "latitude": 34.12 }, "wgs84": { "longitude": 12.12, "latitude": 34.12 }, "bd09mc": { "longitude": 111112.12, "latitude": 322224.12 } } } } self.assertEqual(self.request.get_user_info(), userInfo) def testGetBaiduUid(self): ''' 测试getBaiduUid方法 :return: ''' self.assertEqual(self.request.get_baidu_uid(), 'baiduUid') def testGetType(self): ''' 测试getType方法 :return: ''' self.assertEquals(self.request.get_type(), 'LaunchRequest') def testGetUserId(self): ''' 测试getUserId方法 :return: ''' self.assertEqual(self.request.get_user_id(), 'userId') def testGetCuid(self): ''' 测试getCuid方法 :return: ''' self.assertEqual(self.request.get_cu_id(), 'cuid') def testGetAccessToken(self): ''' :return: ''' self.assertEqual(self.request.get_access_token(), 'access_token') pass
class IntentRequestTest(unittest.TestCase): def setUp(self): with open('../json/intent_request1.json', encoding='utf-8') as f: self.data = f.read() self.data = json.loads(self.data) self.request = Request(self.data) def testGetData(self): ''' 测试getData方法 :return: ''' self.assertEqual(self.request.get_data(), self.data) def testGetNlu(self): ''' 测试getNlu方法 :return: ''' nlu = Nlu(self.data['request']['intents']) self.assertEqual(self.request.get_nlu().to_directive(), nlu.to_directive()) def testGetAudioPlayerContext(self): ''' 测试getAudioPlayerContext方法 :return: ''' pass def testGetType(self): ''' 测试getType方法 :return: ''' self.assertEqual(self.request.get_type(), 'IntentRequest') def testGetUserId(self): ''' 测试getUserId方法 :return: ''' self.assertEqual(self.request.get_user_id(), 'userId') def testGetQuery(self): ''' 测试getQuery方法 :return: ''' self.assertEqual(self.request.get_query(), '所得税查询') def testIsLaunchRequest(self): ''' 测试isLaunchRequest方法 :return: ''' self.assertFalse(self.request.is_launch_request()) def testIsSessionEndRequest(self): ''' 测试isSessionEndRequest方法 :return: ''' self.assertFalse(self.request.is_session_end_request()) def testIsSessionEndedRequest(self): ''' 测试isSessionEndedRequest方法 :return: ''' self.assertFalse(self.request.is_session_ended_request()) def testGetBotId(self): ''' 测试getBotId方法 :return: ''' self.assertEqual(self.request.get_bot_id(), 'botId') def testIsDialogStateCompleted(self): ''' 测试isDialogStateCompleted方法 :return: ''' self.assertFalse(self.request.is_dialog_state_completed()) def testGetSupportedInterface(self): print(self.request.get_supported_interfaces()) print(self.is_support_interface('VideoPlayer')) def testIsSupportVideoPlayer(self): result = self.is_support_interface('VideoPlayer') self.assertTrue(result, '不支持VideoPlayer') def testIsSupportDisplay(self): """ 判断设备是否支持Display :return: """ result = self.is_support_interface('Display') self.assertTrue(result, '不支持Display') def testsSupportAudioPlayer(self): """ 检测AudioPlayer对象是否存在 :return: """ result = self.is_support_interface('AudioPlayer') self.assertTrue(result, '不支持AudioPlayer') def is_support_interface(self, support_func): """ 校验是否支持 :param support_func: :return: """ supported_interfaces = self.request.get_supported_interfaces() if supported_interfaces and isinstance(supported_interfaces, dict): return Utils.checkKeyInDict(supported_interfaces, support_func) else: return False