class SessionTest(unittest.TestCase): ''' Session单元测试 ''' def setUp(self): with open('../json/intent_request.json') as f: self.data = f.read() self.session = Session(json.loads(self.data)['session']) def test_set_data(self): self.session.set_data('status', '1') ret = { 'attributes':{ 'status': '1' } } self.assertEquals(self.session.to_response(), ret) def test_get_data(self): self.session.set_data(0, '1') print('result = ' + self.session.get_data(0)) # self.assertEquals(self.session.get_data('0'), '1') # self.assertEquals(self.session.getData('status'), '2') pass
def __init__(self, data): ''' :param data: 请求数据 ''' self.data = json.loads(data) self.requestType = self.data['request']['type'] self.session = Session(self.data['session']) self.nlu = None if self.requestType == 'IntentRequest': self.nlu = Nlu(self.data['request']['intents']) self.deviceData = None self.arrUserProfile = None
def __init__(self, request_data): """ :param request_data: 请求数据 """ super(Request, self).__init__() if isinstance(request_data, str): request_data = json.loads(request_data) self.data = request_data self.request_type = self.data['request']['type'] self.session = Session(self.data['session']) self.nlu = None if self.request_type == 'IntentRequest': self.nlu = Nlu(self.data['request']['intents']) self.device_data = None self.arr_user_profile = None
def __init__(self, data): """ :param data: 请求数据 """ super(Request, self).__init__() if not isinstance(data, dict): self.data = json.loads(data) else: self.data = data self.request_type = self.data['request']['type'] self.session = Session(self.data['session']) self.nlu = None if self.request_type == 'IntentRequest': self.nlu = Nlu(self.data['request']['intents']) self.deviceData = None self.arrUserProfile = None
def __init__(self, data): ''' :param data: 请求数据 ''' super(Request, self).__init__() if isinstance(data, dict): self.data = data elif isinstance(data, str): self.data = json.loads(data) self.requestType = self.data['request']['type'] self.session = Session(self.data['session']) self.nlu = None if self.requestType == 'IntentRequest': self.nlu = Nlu(self.data['request']['intents']) self.deviceData = None self.arrUserProfile = None
class SessionTest(unittest.TestCase): def setUp(self): with open('../json/intent_request.json', encoding='utf-8') as f: self.data = f.read() self.session = Session(json.loads(self.data)['session']) def test_set_data(self): self.session.set_data('status', '1') ret = {'attributes': {'status': '1'}} self.assertEqual(self.session.to_response(), ret) def test_get_data(self): self.session.set_data('status', '1') self.assertEqual(self.session.get_data('status'), '1') # self.assertEquals(self.session.getData('status'), '2') pass
def testGetSession(self): session = Session(self.data['session']) self.assertEqual(self.request.get_session().to_response(), session.to_response())
def setUp(self): with open('../json/intent_request.json') as f: self.data = f.read() self.session = Session(json.loads(self.data)['session'])