示例#1
0
    def test_read_bool(self):
        test_file_offset = 0
        test_row_id = 1
        test_columns_info = []

        col = DbColumn()
        col.data_type = datatypes.DATATYPE_BOOL
        col.provider = PG_PROVIDER_NAME
        test_columns_info.append(col)

        res = self._bool_reader.read_row(test_file_offset, test_row_id,
                                         test_columns_info)
        self.assertEqual(self._bool_test_value, res[0].raw_object)

        test_file_offset += 5
        test_row_id += 1
        res = self._bool_reader.read_row(test_file_offset, test_row_id,
                                         test_columns_info)
        self.assertEqual(None, res[0].raw_object)

        test_file_offset += 4
        test_row_id += 1
        res = self._bool_reader.read_row(test_file_offset, test_row_id,
                                         test_columns_info)
        self.assertEqual(self._bool_test_value, res[0].raw_object)
示例#2
0
    def test_read_daterange(self):
        test_file_offset = 0
        test_row_id = 1
        test_columns_info = []

        col = DbColumn()
        col.data_type = datatypes.DATATYPE_DATERANGE
        col.provider = PG_PROVIDER_NAME
        test_columns_info.append(col)

        res = self._daterange_reader.read_row(test_file_offset, test_row_id, test_columns_info)
        self.assertEqual(str(self._daterange_test_value), str(res[0].raw_object))
示例#3
0
    def test_read_float2(self):
        test_file_offset = 0
        test_row_id = 1
        test_columns_info = []

        col = DbColumn()
        col.data_type = datatypes.DATATYPE_REAL
        col.provider = PG_PROVIDER_NAME
        test_columns_info.append(col)

        res = self._float_reader2.read_row(test_file_offset, test_row_id, test_columns_info)
        self.assertEqual(self._float_test_value2, res[0].raw_object)
示例#4
0
    def test_read_bytea(self):
        test_file_offset = 0
        test_row_id = 1
        test_columns_info = []

        col = DbColumn()
        col.data_type = datatypes.DATATYPE_BYTEA
        col.provider = PG_PROVIDER_NAME
        test_columns_info.append(col)

        res = self._bytea_reader.read_row(test_file_offset, test_row_id, test_columns_info)
        expected = self._bytea_test_value.tobytes()
        actual = str(res[0].raw_object)
        self.assertEqual(str(expected), actual)
示例#5
0
    def test_read_json(self):
        """Test json/jsonb string is returned as is"""
        test_file_offset = 0
        test_row_id = 1

        for datatype in [datatypes.DATATYPE_JSON, datatypes.DATATYPE_JSONB]:
            col = DbColumn()
            col.data_type = datatype
            col.provider = PG_PROVIDER_NAME
            test_columns_info = [col]
            reader = ServiceBufferFileStreamReader(self._dict_file_stream)

            res = reader.read_row(test_file_offset, test_row_id, test_columns_info)

            self.assertEqual(1, len(res))
            self.assertEqual(json.dumps(self._dict_test_value), res[0].raw_object)
示例#6
0
    def test_read_multiple_cols(self):
        test_file_offset = 0
        test_row_id = 1
        test_columns_info = []

        real_column1 = DbColumn()
        real_column1.data_type = datatypes.DATATYPE_REAL
        real_column1.provider = PG_PROVIDER_NAME
        integer_column = DbColumn()
        integer_column.data_type = datatypes.DATATYPE_INTEGER
        integer_column.provider = PG_PROVIDER_NAME
        text_column = DbColumn()
        text_column.data_type = datatypes.DATATYPE_TEXT
        text_column.provider = PG_PROVIDER_NAME
        real_column2 = DbColumn()
        real_column2.data_type = datatypes.DATATYPE_REAL
        real_column2.provider = PG_PROVIDER_NAME

        test_columns_info.append(real_column1)
        test_columns_info.append(integer_column)
        test_columns_info.append(text_column)
        test_columns_info.append(real_column2)

        res = self._multiple_cols_reader.read_row(test_file_offset, test_row_id, test_columns_info)
        self.assertEqual(self._float_test_value1, res[0].raw_object)
        self.assertEqual(self._int_test_value, res[1].raw_object)
        self.assertEqual(self._str_test_value, res[2].raw_object)
        self.assertEqual(self._float_test_value2, res[3].raw_object)