Пример #1
0
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
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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
Пример #6
0
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
Пример #7
0
    def testGetSession(self):

        session = Session(self.data['session'])
        self.assertEqual(self.request.get_session().to_response(),
                         session.to_response())
Пример #8
0
 def setUp(self):
     with open('../json/intent_request.json') as f:
         self.data = f.read()
     self.session = Session(json.loads(self.data)['session'])