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)
Beispiel #3
0
    def get_edit_row(self, cached_row: List[DbCellValue]) -> EditRow:

        edit_cells = []
        for cell in self.new_cells:
            db_cell_value = DbCellValue(None, True, None, self.row_id) if cell is None else cell.as_db_cell_value
            edit_cells.append(EditCell(db_cell_value, True, self.row_id))

        return EditRow(self.row_id, edit_cells, EditRowState.DIRTY_INSERT)
Beispiel #4
0
    def test_get_edit_row(self):
        cached_row = [DbCellValue('True', False, True, 1)]

        edit_row = self._row_delete.get_edit_row(cached_row)

        self.assertEqual(edit_row.id, self._row_id)
        self.assertEqual(edit_row.state, EditRowState.DIRTY_DELETE)

        self.assertTrue(edit_row.cells[0].display_value == 'True')
Beispiel #5
0
    def _construct_rows(result_set, start_index: int, end_index: int):

        rows_list: List[List[DbCellValue]] = []
        row_id = start_index

        # operate only on results within the specified range
        for row_id in range(start_index, end_index):
            db_cell_value_row: List[DbCellValue] = [
                DbCellValue(cell, cell is None, cell, row_id)
                for cell in ResultSetSubset._get_row(result_set, row_id)
            ]
            # Add our row to the overall row list
            rows_list.append(db_cell_value_row)
        return rows_list
 def get_row(self, row_id: int) -> List[DbCellValue]:
     row = self.rows[row_id]
     return [
         DbCellValue(cell_value, cell_value is None, cell_value, row_id)
         for cell_value in list(row)
     ]
Beispiel #7
0
 def as_db_cell_value(self):
     return DbCellValue(self.value_as_string, self.value is None,
                        self.value, None)