def test_parse_sql(self, mocker): connect_mock = mocker.patch( 'giraffez.export.TeradataBulkExport._connect') columns = Columns([ ("col1", VARCHAR_NN, 50, 0, 0), ("col2", VARCHAR_N, 50, 0, 0), ("col3", VARCHAR_N, 50, 0, 0), ]) export = giraffez.BulkExport() export.export = mocker.MagicMock() export.export.columns.return_value = columns export.query = """select col1 as ‘c1’, col2 as “c2”from db1.info a\n join db2.info b\n on a.id = b.id""" export._close() assert '\n' not in export.query assert '‘' not in export.query assert '’' not in export.query assert '“' not in export.query assert '”' not in export.query
def test_cencoder_unpack(benchmark): columns = Columns([ ("col1", VARCHAR_NN, 50, 0, 0), ("col2", DECIMAL_NN, 8, 16, 2), ("col3", CHAR_NN, 50, 0, 0), ("col4", DATE_NN, 4, 0, 0), ("col5", VARCHAR_NN, 50, 0, 0), ("col6", DECIMAL_NN, 8, 18, 0), ("col7", DECIMAL_NN, 8, 18, 0), ("col8", INTEGER_NN, 4, 0, 0), ("col9", INTEGER_NN, 4, 0, 0), ("col10", VARCHAR_NN, 50, 0, 0), ]) encoder = python_to_teradata(columns) row = encoder([ "testing", "100000.02", "testing", "2015-01-01", "testing", "100000000001", "10000000002", 1000, 1001, "testing" ]) row = struct.pack('h', len(row)) + row result = benchmark(unpack_rows, columns, row, n=1)
def test_bulkload_results(self, mocker): bulkload_connect_mock = mocker.patch( 'giraffez.load.TeradataBulkLoad._connect') table = "db1.info" columns = Columns([ ("col1", VARCHAR_NN, 50, 0, 0), ("col2", VARCHAR_N, 50, 0, 0), ("col3", VARCHAR_N, 50, 0, 0), ]) rows = [ ["value1", "value2", "value3"], ["value1", "value2", "value3"], ["value1", "value2", "value3"], ] load = giraffez.BulkLoad() load.mload = mocker.MagicMock() load.mload.status.return_value = 0 load.mload.put_row.return_value = 0 load.mload.exists.return_value = False load.mload.checkpoint.return_value = 0 load.mload.get_event.side_effect = [ b'\x00\x00', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80', b'\x00\x00\x00\x00', b'\x00\x00', ] load.table = table for row in rows: load.put(row) exit_code = load.finish() load._close() bulkload_connect_mock.assert_called_with('db1', 'user123', 'pass456', None, None) assert load.mload.initiate.called == True assert load.mload.put_row.call_count == 3 assert load.mload.end_acquisition.called == True assert load.mload.apply_rows.called == True assert load.mload.close.called == True
def test_mload_results(self, mocker): mload_connect_mock = mocker.patch('giraffez.MLoad._connect') table = "db1.info" columns = Columns([ ("col1", VARCHAR_NN, 50, 0, 0), ("col2", VARCHAR_N, 50, 0, 0), ("col3", VARCHAR_N, 50, 0, 0), ]) rows = [ ["value1", "value2", "value3"], ["value1", "value2", "value3"], ["value1", "value2", "value3"], ] mload = giraffez.MLoad() mload.load = mocker.MagicMock() mload.load.status.return_value = 0 mload.load.put_row.return_value = 0 mload.load.checkpoint.return_value = 0 mload.load.get_event.side_effect = [ b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80', b'\x00\x00\x00\x00', b'\x00\x00', ] mload.cmd = mocker.Mock() mload.cmd.get_columns = mocker.Mock(return_value=columns) mload.table = table for row in rows: mload.load_row(row) exit_code = mload.finish() mload.close() mload_connect_mock.assert_called_with('db1', 'user123', 'pass456') assert mload.load.initiate.called == True assert mload.load.put_row.call_count == 3 assert mload.load.end_acquisition.called == True assert mload.load.apply_rows.called == True assert mload.load.close.called == True assert mload.cmd.close.called == True
def test_export_results(self, mocker): connect_mock = mocker.patch( 'giraffez.export.TeradataBulkExport._connect') query = "select * from db1.info" columns = Columns([ ("col1", VARCHAR_NN, 50, 0, 0), ("col2", VARCHAR_N, 50, 0, 0), ("col3", VARCHAR_N, 50, 0, 0), ]) rows = [ ["value1", "value2", "value3"], ["value1", "value2", "value3"], ["value1", "value2", "value3"], ] expected_results = ["|".join(row) for row in rows] export = giraffez.BulkExport() export.export = mocker.MagicMock() export.export.status.return_value = 0 export.export.get_buffer.side_effect = [expected_results] export.export.columns.return_value = columns export.query = query export._initiate() results = list(export.to_list()) export._close() # This ensures that the config was proper mocked connect_mock.assert_called_with('db1', 'user123', 'pass456', None, None) assert results == expected_results assert isinstance(export.columns, giraffez.types.Columns) == True assert export.export.columns.called == True assert len(export.columns) == 3 #assert export.export.get_buffer.call_count == 2 assert export.export.close.called == True