Exemple #1
0
    def test_create_row(self):
        '''
        Validate that create row creates new row based with new row id and returns
        CreateRowResponse
        '''
        self._data_editor_session._last_row_id = 0

        calculated_column = DbColumn()
        calculated_column.is_updatable = False
        calculated_column_metadata = EditColumnMetadata(calculated_column, None)

        default_value_column = DbColumn()
        default_value_column.data_type = 'bool'
        default_value_column.is_updatable = True
        default_value_column_metadata = EditColumnMetadata(default_value_column, '0')

        columns_metadata = [calculated_column_metadata, default_value_column_metadata]

        self._data_editor_session.table_metadata = EditTableMetadata(self._schema_name, self._table_name, columns_metadata)

        result_set = self.get_result_set([(1, False)])

        result_set.columns_info = [calculated_column, default_value_column]

        self._data_editor_session._result_set = result_set

        self._data_editor_session._is_initialized = True
        response: CreateRowResponse = self._data_editor_session.create_row()

        self.assertEqual(1, response.new_row_id)
        self.assertEqual(len(columns_metadata), len(response.default_values))

        self.assertEqual('<TBD>', response.default_values[0])
        self.assertEqual('False', response.default_values[1])
    def create_db_column(self, column: Column) -> DbColumn:
        db_column = DbColumn()

        db_column.allow_db_null = column.not_null is False
        db_column.column_name = column.name
        db_column.column_ordinal = column.column_ordinal
        db_column.data_type = column.datatype
        db_column.is_key = column.is_key
        db_column.is_read_only = column.is_readonly
        db_column.is_unique = column.is_unique
        db_column.is_auto_increment = column.is_auto_increment
        db_column.is_updatable = column.is_readonly is False and column.is_auto_increment is False

        return db_column
    def setUp(self):
        self._row_id = 1
        self._rows = [("False"), ("True")]
        self._result_set = create_result_set(ResultSetStorageType.IN_MEMORY, 0,
                                             0)
        self._cursor = MockCursor(self._rows, ['IsTrue'])

        with mock.patch(
                'ossdbtoolsservice.query.in_memory_result_set.get_columns_info',
                new=mock.Mock()):
            self._result_set.read_result_to_end(self._cursor)

        db_column = DbColumn()
        db_column.data_type = 'bool'
        db_column.column_name = 'IsValid'
        db_column.is_updatable = True

        self._result_set.columns_info = [db_column]
        self._table_metadata = EditTableMetadata('public', 'TestTable', [])

        self._row_create = RowCreate(self._row_id, self._result_set,
                                     self._table_metadata)