def setUp(self):
        self.request = SaveResultsAsCsvRequestParams()
        self.request.file_path = 'TestPath'
        self.request.include_headers = True

        self.mock_io = mock.MagicMock()

        self.row = [
            DbCellValue('Test', False, None, 0),
            DbCellValue(1023, False, None, 0),
            DbCellValue(False, False, None, 0)
        ]

        name_column = DbColumn()
        name_column.column_name = 'Name'

        id_column = DbColumn()
        id_column.column_name = 'Id'

        is_valid_column = DbColumn()
        is_valid_column.column_name = 'Valid'

        self.columns = [name_column, id_column, is_valid_column]

        self.writer = SaveAsCsvWriter(self.mock_io, self.request)
    def setUp(self):
        self.request = SaveResultsAsExcelRequestParams()
        self.request.file_path = 'TestPath'
        self.request.include_headers = True

        self.mock_io = mock.MagicMock()

        self.row = [
            DbCellValue('Test', False, None, 0),
            DbCellValue(1023, False, None, 0),
            DbCellValue(False, False, None, 0)
        ]

        name_column = DbColumn()
        name_column.column_name = 'Name'

        id_column = DbColumn()
        id_column.column_name = 'Id'

        is_valid_column = DbColumn()
        is_valid_column.column_name = 'Valid'

        self.columns = [name_column, id_column, is_valid_column]

        self.worksheet_mock = mock.MagicMock()
        self.workbook_mock = mock.MagicMock()
        self.workbook_mock.add_worksheet = mock.Mock(
            return_value=self.worksheet_mock)
        self.xlsxwriter_mock = mock.Mock(return_value=self.workbook_mock)
        self.mock_io.name = 'SomeName'

        with mock.patch('xlsxwriter.Workbook', new=self.xlsxwriter_mock):
            self.writer = SaveAsExcelWriter(self.mock_io, self.request)
Example #3
0
    def setUp(self):
        """Set up the test by creating a query with multiple batches"""
        self.statement_list = statement_list = [
            'select version;', 'select * from t1;'
        ]
        self.statement_str = ''.join(statement_list)
        self.query_uri = 'test_uri'
        self.query = Query(
            self.query_uri, self.statement_str,
            QueryExecutionSettings(ExecutionPlanOptions(),
                                   ResultSetStorageType.FILE_STORAGE),
            QueryEvents())

        self.mock_query_results = [('Id1', 'Value1'), ('Id2', 'Value2')]
        self.cursor = MockCursor(self.mock_query_results)
        self.connection = MockPGServerConnection(cur=self.cursor)

        self.columns_info = []
        db_column_id = DbColumn()
        db_column_id.data_type = 'text'
        db_column_id.column_name = 'Id'
        db_column_id.provider = PG_PROVIDER_NAME
        db_column_value = DbColumn()
        db_column_value.data_type = 'text'
        db_column_value.column_name = 'Value'
        db_column_value.provider = PG_PROVIDER_NAME
        self.columns_info = [db_column_id, db_column_value]
        self.get_columns_info_mock = mock.Mock(return_value=self.columns_info)
    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
Example #5
0
    def setUp(self):
        self._row_id = 1
        self._rows = [("Result1",), ("Result2",)]

        db_column = DbColumn()
        db_column.data_type = 'varchar'
        db_column.column_name = 'TextType'

        self._result_set = create_result_set(ResultSetStorageType.IN_MEMORY, 0, 0)
        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(cursor)

        self._result_set.columns_info = [db_column]

        self._table_metadata = None
        self._column_index = 0
        self._new_value = 'Updated'

        self._row_update = RowUpdate(self._row_id, self._result_set, self._table_metadata)
    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)
Example #7
0
    def setUp(self):
        self._row_id = 1
        self._rows = [("False",), ("True",)]

        self._result_set = create_result_set(ResultSetStorageType.IN_MEMORY, 0, 0)
        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(cursor)

        db_column = DbColumn()
        db_column.data_type = 'bool'
        db_column.column_name = 'IsValid'
        db_column.is_key = True
        db_column.column_ordinal = 0

        self._result_set.columns_info = [db_column]

        self._columns_metadata = [EditColumnMetadata(db_column, 'Default Value')]

        self._table_metadata = EditTableMetadata('public', 'TestTable', self._columns_metadata)

        self._row_delete = RowDelete(self._row_id, self._result_set, self._table_metadata)