Skip to content

Commit

Permalink
Data warehouse export tests and bug fix (#1063)
Browse files Browse the repository at this point in the history
* Update docblock
* Fix dry run behavior
* Add data warehouse export tests
  • Loading branch information
jtpalmer authored Sep 23, 2019
1 parent da425f1 commit 4f6653f
Show file tree
Hide file tree
Showing 17 changed files with 853 additions and 10 deletions.
6 changes: 4 additions & 2 deletions classes/DataWarehouse/Export/BatchProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ private function processSubmittedRequest(array $request)
$dataSet = $this->getDataSet($request, $user);
$format = $this->dryRun ? 'null' : $request['export_file_format'];
$dataFile = $this->fileManager->writeDataSetToFile($dataSet, $format);
$this->fileManager->createZipFile($dataFile, $request);
if (!$this->dryRun) {
$this->fileManager->createZipFile($dataFile, $request);
}

// Delete file that was added to zip archive.
if (!unlink($dataFile)) {
if (!$this->dryRun && !unlink($dataFile)) {
$this->logger->err(sprintf(
'Failed to delete temporary data file "%s"',
$dataFile
Expand Down
1 change: 1 addition & 0 deletions classes/DataWarehouse/Export/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public function writeDataSetToFile(BatchDataset $dataSet, $format)
*
* @param string $dataFile Path to file that will be put in the zip file.
* @param array $request Batch export request data.
* @return string Zip file path.
* @throws \Exception If creating the zip file fails.
*/
public function createZipFile($dataFile, array $request)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
[
1
],
[
2
],
[
3
],
[
10
],
[
100
],
[
12345
],
[
4294967296
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
[
{
"id": 1,
"user_id": 1,
"realm": "jobs",
"start_date": "2018-01-01",
"end_date": "2018-02-28",
"export_file_format": "CSV",
"requested_datetime": "2019-01-01 00:00:00",
"export_succeeded": null,
"export_created_datetime": null,
"downloaded_datetime": null,
"export_expires_datetime": null,
"export_expired": 0,
"last_modified": "2019-01-01 00:00:00"
}
],
[
{
"id": 2,
"user_id": 1,
"realm": "jobs",
"start_date": "2001-01-01",
"end_date": "2001-01-02",
"export_file_format": "JSON",
"requested_datetime": "2019-01-01 00:00:01",
"export_succeeded": null,
"export_created_datetime": null,
"downloaded_datetime": null,
"export_expires_datetime": null,
"export_expired": 0,
"last_modified": "2019-01-01 00:00:01"
}
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
heading1,heading2,heading3
0,1,2
a,b,c
17 changes: 17 additions & 0 deletions tests/artifacts/xdmod/component/export/file_manager/output/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
[
"heading1",
"heading2",
"heading3"
],
[
0,
1,
2
],
[
"a",
"b",
"c"
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"Single record with one element": [
[
[
"a"
]
],
"a\n"
],
"Single record with two elements": [
[
[
"a",
"b"
]
],
"a,b\n"
],
"Two records with two elements each": [
[
[
"a",
"b"
],
[
"c",
"d"
]
],
"a,b\nc,d\n"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"CSV File Writer": [
"csv",
"\\DataWarehouse\\Export\\FileWriter\\CsvFileWriter"
],
"JSON File Writer": [
"json",
"\\DataWarehouse\\Export\\FileWriter\\JsonFileWriter"
],
"NULL File Writer": [
"null",
"\\DataWarehouse\\Export\\FileWriter\\NullFileWriter"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"Single record with one element": [
[
[
"a"
]
],
"[[\"a\"]]"
],
"Single record with two elements": [
[
[
"a",
"b"
]
],
"[[\"a\",\"b\"]]"
],
"Two records with two elements each": [
[
[
"a",
"b"
],
[
"c",
"d"
]
],
"[[\"a\",\"b\"],[\"c\",\"d\"]]"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Single record with one element": [
[
[
"a"
]
]
],
"Single record with two elements": [
[
[
"a",
"b"
]
]
],
"Two records with two elements each": [
[
[
"a",
"b"
],
[
"c",
"d"
]
]
]
}
Loading

0 comments on commit 4f6653f

Please sign in to comment.