|
| 1 | +<?php |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +namespace Keboola\Test\Backend\Synapse; |
| 6 | + |
| 7 | +use Keboola\Csv\CsvFile; |
| 8 | +use Keboola\StorageApi\Client; |
| 9 | +use Keboola\StorageApi\ClientException; |
| 10 | +use Keboola\StorageApi\Exception; |
| 11 | +use Keboola\StorageApi\Workspaces; |
| 12 | +use Keboola\Test\Backend\Workspaces\Backend\WorkspaceBackendFactory; |
| 13 | +use Keboola\Test\Backend\Workspaces\WorkspacesTestCase; |
| 14 | +use Keboola\Test\Backend\CommonPart1\ImportExportCommonTest as CommonImportExportTest; |
| 15 | + |
| 16 | +class ImportExportCommonTest extends CommonImportExportTest |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @dataProvider tableImportData |
| 20 | + * @param $importFileName |
| 21 | + */ |
| 22 | + public function testTableImportExport(CsvFile $importFile, $expectationsFileName, $colNames, $format = 'rfc', $createTableOptions = array()) |
| 23 | + { |
| 24 | + $expectationsFile = __DIR__ . '/../../_data/' . $expectationsFileName; |
| 25 | + $tableId = $this->_client->createTable($this->getTestBucketId(self::STAGE_IN), 'languages-2', $importFile, $createTableOptions); |
| 26 | + |
| 27 | + $result = $this->_client->writeTable($tableId, $importFile); |
| 28 | + $table = $this->_client->getTable($tableId); |
| 29 | + |
| 30 | + $this->assertEmpty($result['warnings']); |
| 31 | + $this->assertEquals($colNames, array_values($result['importedColumns']), 'columns'); |
| 32 | + $this->assertEmpty($result['transaction']); |
| 33 | + $this->assertNotEmpty($table['dataSizeBytes']); |
| 34 | + $this->assertNotEmpty($result['totalDataSizeBytes']); |
| 35 | + |
| 36 | + // @TODO not implemented yet |
| 37 | +// // compare data |
| 38 | +// $this->assertLinesEqualsSorted(file_get_contents($expectationsFile), $this->_client->getTableDataPreview($tableId, array( |
| 39 | +// 'format' => $format, |
| 40 | +// )), 'imported data comparsion'); |
| 41 | +// |
| 42 | +// // incremental |
| 43 | +// $result = $this->_client->writeTable($tableId, $importFile, array( |
| 44 | +// 'incremental' => true, |
| 45 | +// )); |
| 46 | +// $this->assertNotEmpty($result['totalDataSizeBytes']); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @dataProvider tableImportData |
| 51 | + * @param $importFileName |
| 52 | + */ |
| 53 | + public function testTableAsyncImportExport(CsvFile $importFile, $expectationsFileName, $colNames, $format = 'rfc', $createTableOptions = array()) |
| 54 | + { |
| 55 | + $expectationsFile = __DIR__ . '/../../_data/' . $expectationsFileName; |
| 56 | + $tableId = $this->_client->createTable($this->getTestBucketId(self::STAGE_IN), 'languages-3', $importFile, $createTableOptions); |
| 57 | + |
| 58 | + $result = $this->_client->writeTableAsync($tableId, $importFile); |
| 59 | + $table = $this->_client->getTable($tableId); |
| 60 | + |
| 61 | + $this->assertEmpty($result['warnings']); |
| 62 | + $this->assertEquals($colNames, array_values($result['importedColumns']), 'columns'); |
| 63 | + $this->assertEmpty($result['transaction']); |
| 64 | + $this->assertNotEmpty($table['dataSizeBytes']); |
| 65 | + $this->assertNotEmpty($result['totalDataSizeBytes']); |
| 66 | + |
| 67 | + // @TODO not implemented yet |
| 68 | +// // compare data |
| 69 | +// $this->assertLinesEqualsSorted(file_get_contents($expectationsFile), $this->_client->getTableDataPreview($tableId, array( |
| 70 | +// 'format' => $format, |
| 71 | +// )), 'imported data comparsion'); |
| 72 | +// |
| 73 | +// // incremental |
| 74 | +// |
| 75 | +// $result = $this->_client->writeTableAsync($tableId, $importFile, array( |
| 76 | +// 'incremental' => true, |
| 77 | +// )); |
| 78 | +// $this->assertNotEmpty($result['totalDataSizeBytes']); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @dataProvider incrementalImportPkDedupeData |
| 83 | + * @param $createFile |
| 84 | + * @param $primaryKey |
| 85 | + * @param $expectationFileAfterCreate |
| 86 | + * @param $incrementFile |
| 87 | + * @param $expectationFinal |
| 88 | + */ |
| 89 | + public function testIncrementalImportPkDedupe($createFile, $primaryKey, $expectationFileAfterCreate, $incrementFile, $expectationFinal) |
| 90 | + { |
| 91 | + |
| 92 | + $tableId = $this->_client->createTableAsync($this->getTestBucketId(self::STAGE_IN), 'pk', $createFile, [ |
| 93 | + 'primaryKey' => $primaryKey, |
| 94 | + ]); |
| 95 | + |
| 96 | + // @TODO not implemented yet |
| 97 | +// $this->assertLinesEqualsSorted(file_get_contents($expectationFileAfterCreate), $this->_client->getTableDataPreview($tableId)); |
| 98 | + |
| 99 | + $this->_client->writeTableAsync($tableId, $incrementFile, [ |
| 100 | + 'incremental' => true, |
| 101 | + ]); |
| 102 | + |
| 103 | + // @TODO not implemented yet |
| 104 | +// $this->assertLinesEqualsSorted(file_get_contents($expectationFinal), $this->_client->getTableDataPreview($tableId)); |
| 105 | + } |
| 106 | + |
| 107 | + public function testTableImportCreateMissingColumns() |
| 108 | + { |
| 109 | + $this->markTestSkipped('Adding missing columns for Synapse backend is not supported yet'); |
| 110 | + } |
| 111 | + |
| 112 | + public function testTableImportFromString() |
| 113 | + { |
| 114 | + $tableId = $this->_client->createTable($this->getTestBucketId(self::STAGE_IN), 'languages', new \Keboola\Csv\CsvFile(__DIR__ . '/../../_data/languages-headers.csv')); |
| 115 | + |
| 116 | + $lines = '"id","name"'; |
| 117 | + $lines .= "\n" . '"first","second"' . "\n"; |
| 118 | + $this->_client->apiPost("storage/tables/$tableId/import", array( |
| 119 | + 'dataString' => $lines, |
| 120 | + )); |
| 121 | + |
| 122 | + // @TODO not implemented yet |
| 123 | +// $this->assertEquals($lines, $this->_client->getTableDataPreview($tableId, array( |
| 124 | +// 'format' => 'rfc', |
| 125 | +// ))); |
| 126 | + } |
| 127 | + |
| 128 | + public function testTableInvalidAsyncImport() |
| 129 | + { |
| 130 | + $this->markTestSkipped('Adding missing table columns for Synapse backend is not supported yet'); |
| 131 | + } |
| 132 | + |
| 133 | + public function testTableAsyncExportRepeatedly() |
| 134 | + { |
| 135 | + $this->markTestSkipped('Exporting table table for Synapse backend is not supported yet'); |
| 136 | + } |
| 137 | +} |
0 commit comments