Example #1
0
    def xtest_set_payload_direct_payload_case_2a(self):
        # basestring, dict, list, tuple, bool, Number + (EtreeElement, ObjectifiedElement)

        data_01 = b'abc'
        data_02 = u'def'
        data_03 = [1, 2, 3]
        data_04 = (5, 6, 7)
        data_05 = True
        data_06 = False
        data_07 = 1
        data_08 = 2.0
        data_09 = EtreeElement()
        data_10 = ObjectifiedElement()

        elems = [
            data_01, data_02, data_03, data_04, data_05, data_06, data_07,
            data_08, data_09, data_10
        ]

        response = Response()
        response.init('abc', None, DATA_FORMAT.CSV)

        for elem in elems:
            response.payload = elem
            self.assertIs(response.payload, elem)
Example #2
0
    def xtest_init_no_sio(self):
        response = Response()
        response.init('abc', None, DATA_FORMAT.CSV)

        self.assertEqual(response.cid, 'abc')
        self.assertEqual(response.data_format, DATA_FORMAT.CSV)
        self.assertEqual(response.payload, '')
Example #3
0
    def xtest_init_has_sio(self):

        MyService = deepcopy(MyBaseService)
        CySimpleIO.attach_sio(self.get_server_config(), MyService)

        response = Response()
        response.init('abc', MyService._sio, DATA_FORMAT.CSV)

        self.assertIsInstance(response.payload, SimpleIOPayload)
Example #4
0
    def xtest_set_payload_dict_no_sio_case_1b(self):

        response = Response()
        response.init('abc', None, DATA_FORMAT.CSV)

        data = {'a': 'aa', 'b': 'bb'}
        response.payload = data

        self.assertDictEqual(response.payload, data)
Example #5
0
    def xtest_setslice(self):

        MyService = deepcopy(MyBaseService)
        CySimpleIO.attach_sio(self.get_server_config(), MyService)

        response = Response()
        response.init('abc', MyService._sio, DATA_FORMAT.CSV)

        data = [{'a': 'aa', 'b': 'bb'}, {'a': 'aa2', 'b': 'bb2'}]
        response.payload[:] = data

        for idx, elem in enumerate(data):
            self.assertDictEqual(data[idx],
                                 response.payload.user_attrs_list[idx])
Example #6
0
    def xtest_set_payload_not_direct_payload_no_sio_case_2b2(self):
        class MyCustomPayloadType:
            def __repr__(self):
                return '<MyCustomPayloadType>'

        response = Response()
        response.init('abc', None, DATA_FORMAT.CSV)

        try:
            response.payload = MyCustomPayloadType()
        except Exception as e:
            self.assertEqual(
                e.args[0],
                'Cannot serialise value without SimpleIO ouput declaration (<MyCustomPayloadType>)'
            )
        else:
            self.fail('Expected for an exception to be raised')
Example #7
0
    def xtest_set_payload_dict_has_sio_case_1a(self):

        MyService = deepcopy(MyBaseService)
        CySimpleIO.attach_sio(self.get_server_config(), MyService)

        response = Response()
        response.init('abc', MyService._sio, DATA_FORMAT.XML)

        # Note that 'ddd' is optional so it can be missing
        # and that 'fff' is not in SIO so it should be ignored.
        data = {
            'aaa': '111',
            'bbb': '222',
            'ccc': '333',
            'eee': '555',
            'fff': '666',
            'qqq': 777,
            'www': 888
        }
        response.payload = data
Example #8
0
    def xtest_defaults(self):
        response = Response()

        self.assertIsNone(response.cid)
        self.assertIsNone(response.content_encoding)
        self.assertEqual(response.content_type, 'text/plain')
        self.assertFalse(response.content_type_changed)
        self.assertIsNone(response.data_format)
        self.assertDictEqual(response.headers, {})
        self.assertEqual(response.payload, '')
        self.assertEqual(response.result, ZATO_OK)
        self.assertEqual(response.result_details, '')
        self.assertEqual(response.status_code, OK)
        self.assertEqual(response.status_message, 'OK')
    def _prepare_sio_response(self, data, data_format, is_list):
        # type: (object, str, bool) -> str

        MyService = deepcopy(MyODBService)
        CySimpleIO.attach_sio(self.get_server_config(False), MyService)

        response = Response()
        response.init('abc', MyService._sio, data_format)

        if is_list:
            response.payload[:] = data
        else:
            response.payload = data

        return response.payload.getvalue()
Example #10
0
    def xtest_content_type(self):
        response = Response()
        response.content_type = 'abc'

        self.assertTrue(response.content_type_changed)
        self.assertEqual(response.content_type, 'abc')
Example #11
0
    def xtest_len(self):
        response = Response()
        response._payload = 'abcdef'

        self.assertEqual(len(response), 6)