Skip to content

Commit

Permalink
Update schema rules (Helioviewer-Project#403)
Browse files Browse the repository at this point in the history
* Organize schema test data

* Allow boolean for followViewport in postMovie

* Allow backslash and parentheses in event layer

* add post screenshot test

* Add cactus test case
  • Loading branch information
dgarciabriseno authored Jul 22, 2024
1 parent 66ce884 commit c526b80
Show file tree
Hide file tree
Showing 49 changed files with 478 additions and 22 deletions.
4 changes: 2 additions & 2 deletions docroot/schema/event_layers.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"type": "array",
"items": {
"type": "string",
"pattern": "^[a-zA-Z0-9_-]+$",
"pattern": "^[\\\\()a-zA-Z0-9_-]+$",
"minLength": 1,
"maxLength": 40
"maxLength": 60
}
},
"open": {
Expand Down
7 changes: 6 additions & 1 deletion docroot/schema/post_movie.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@
{"type": "string", "enum": ["1", "0"]}
]
},
"followViewport": { "type": "number" },
"followViewport": {
"oneOf": [
{ "type": "number" },
{ "type": "boolean" }
]
},
"reqObservationDate": {
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?Z$"
Expand Down
40 changes: 21 additions & 19 deletions tests/unit_tests/validation/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,24 @@

final class SchemaValidatorTest extends TestCase
{

private static function BuildTestDataFromFolder(string $directory, bool $expectation, string $schema) {
$test_data = [];
$files = scandir($directory);
foreach ($files as $file) {
if ($file == "." || $file == "..") {
continue;
}
array_push($test_data, ["$directory/$file", $expectation, $schema]);
}
return $test_data;
}

/**
* Reads the list of test files from the test data folder
* and returns test data in the format:
* [
* ["test_file", SHOULD_PASS/SHOULD_FAIL],
* ["test_file", SHOULD_PASS/SHOULD_FAIL, schema_file],
* ...
* ]
*
Expand All @@ -31,30 +44,19 @@ final class SchemaValidatorTest extends TestCase
public static function GetTestData(): array {
$test_data = [];

$valid_files = scandir(__DIR__ . "/test_data/valid");
foreach ($valid_files as $file) {
if ($file == "." || $file == "..") {
continue;
}
array_push($test_data, ["valid/$file", SHOULD_PASS]);
}

$invalid_files = scandir(__DIR__ . "/test_data/invalid");
foreach ($invalid_files as $file) {
if ($file == "." || $file == "..") {
continue;
}
array_push($test_data, ["invalid/$file", SHOULD_FAIL]);
}
$test_data = array_merge($test_data, self::BuildTestDataFromFolder(__DIR__ . "/test_data/client_state/valid", SHOULD_PASS, 'https://api.helioviewer.org/schema/client_state.schema.json'));
$test_data = array_merge($test_data, self::BuildTestDataFromFolder(__DIR__ . "/test_data/client_state/invalid", SHOULD_FAIL, 'https://api.helioviewer.org/schema/client_state.schema.json'));
$test_data = array_merge($test_data, self::BuildTestDataFromFolder(__DIR__ . "/test_data/post_movie/valid", SHOULD_PASS, 'https://api.helioviewer.org/schema/post_movie.schema.json'));
$test_data = array_merge($test_data, self::BuildTestDataFromFolder(__DIR__ . "/test_data/post_screenshot/valid", SHOULD_PASS, 'https://api.helioviewer.org/schema/post_screenshot.schema.json'));
return $test_data;
}

/**
* @dataProvider GetTestData
*/
public function test_ValidateJsonSchema(string $json_file, bool $expected_result): void
public function test_ValidateJsonSchema(string $json_file, bool $expected_result, string $schema): void
{
$json = json_decode(file_get_contents(__DIR__ . "/test_data/" . $json_file));
$json = json_decode(file_get_contents($json_file));
if (is_null($json)) {
throw new Exception("Failed to parse $json_file as json");
}
Expand All @@ -63,7 +65,7 @@ public function test_ValidateJsonSchema(string $json_file, bool $expected_result
try {
$params = [ 'json' => $json ];
$expected = array(
'schema' => array('json' => 'https://api.helioviewer.org/schema/client_state.schema.json')
'schema' => array('json' => $schema)
);
$optional = [];

Expand Down
145 changes: 145 additions & 0 deletions tests/unit_tests/validation/test_data/client_state/valid/valid_15.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"date": 1712557812000,
"centerX": -172.3873528481749,
"centerY": -216.25766746329495,
"imageScale": 0.60511022,
"eventLayers": {
"tree_CCMC": {
"id": "CCMC",
"labels_visible": true,
"layer_available_visible": true,
"layers": [
{
"event_instances": [],
"event_type": "AR",
"frms": [
"NOAA_SWPC_Observer"
],
"open": true
},
{
"event_instances": [],
"event_type": "FL",
"frms": [
"SWPC"
],
"open": true
}
],
"markers_visible": true,
"visible": true
},
"tree_HEK": {
"id": "HEK",
"labels_visible": true,
"layer_available_visible": true,
"layers": [],
"markers_visible": true,
"visible": true
},
"tree_RHESSI": {
"id": "RHESSI",
"labels_visible": true,
"layer_available_visible": true,
"layers": [
{
"event_instances": [],
"event_type": "AR",
"frms": [
"NOAA_SWPC_Observer"
],
"open": true
},
{
"event_instances": [],
"event_type": "FL",
"frms": [
"SWPC"
],
"open": true
}
],
"markers_visible": true,
"visible": true
}
},
"imageLayers": [
{
"end": "2024-04-08 06:30:13",
"start": "2024-04-08 06:19:24",
"opacity": 35,
"visible": true,
"diffTime": 1,
"nickname": "IRIS SJI 2796",
"sourceId": 89,
"uiLabels": [
{
"name": "IRIS",
"label": ""
},
{
"name": "SJI",
"label": "Instrument"
},
{
"name": "2796",
"label": ""
}
],
"diffCount": 60,
"Instrument": "SJI",
"difference": 0,
"Measurement": "2796",
"Observatory": "IRIS",
"baseDiffTime": "2024-06-12T08:32:57.000Z",
"layeringOrder": 1
},
{
"end": "2024-06-11 06:38:14",
"start": "2012-07-05 00:09:05",
"opacity": "100",
"visible": "1",
"diffTime": 1,
"nickname": "AIA 1600",
"sourceId": 15,
"uiLabels": [
{
"name": "SDO",
"label": ""
},
{
"name": "AIA",
"label": ""
},
{
"name": "1600",
"label": ""
}
],
"diffCount": 60,
"Instrument": "AIA",
"difference": 0,
"Measurement": "1600",
"Observatory": "SDO",
"baseDiffTime": "2024-04-08T05:30:13.000Z",
"layeringOrder": 1
}
],
"celestialBodies": {
"soho": [
"soho-mercury-tree-label",
"soho-venus-tree-label",
"soho-mars-tree-label",
"soho-jupiter-tree-label",
"soho-saturn-tree-label",
"soho-uranus-tree-label",
"soho-neptune-tree-label"
],
"stereo_a": [
"stereo_a-mercury-tree-label"
],
"stereo_b": [
"stereo_b-mercury-tree-label"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"date": 1697979187000,
"imageScale": 4.84088176,
"centerX": 100.29816701545585,
"centerY": 1064.2094221854543,
"imageLayers": [
{
"uiLabels": [
{
"label": "Observatory",
"name": "SDO"
},
{
"label": "Instrument",
"name": "AIA"
},
{
"label": "Measurement",
"name": "131"
}
],
"Observatory": "SDO",
"Instrument": "AIA",
"Measurement": "131",
"visible": "1",
"opacity": 100,
"difference": 0,
"diffCount": 60,
"diffTime": 1,
"baseDiffTime": "2018-03-30T04:18:36.000Z",
"sourceId": 9,
"nickname": "AIA 131",
"layeringOrder": 1,
"start": "2010-06-02 00:05:35",
"end": "2024-07-22 15:48:07"
}
],
"eventLayers": {
"tree_HEK": {
"id": "HEK",
"layers": [
{
"event_type": "CE",
"frms": [
"CACTus_\\(Computer_Aided_CME_Tracking\\)"
],
"event_instances": [],
"open": 1
}
],
"visible": true,
"labels_visible": true,
"markers_visible": true,
"layer_available_visible": false
},
"tree_CCMC": {
"id": "CCMC",
"layers": [],
"visible": true,
"labels_visible": true,
"markers_visible": true,
"layer_available_visible": true
},
"tree_RHESSI": {
"id": "RHESSI",
"layers": [],
"visible": true,
"labels_visible": true,
"markers_visible": true,
"layer_available_visible": true
}
},
"celestialBodies": {
"soho": [
"soho-mercury-tree-label",
"soho-venus-tree-label",
"soho-mars-tree-label",
"soho-jupiter-tree-label",
"soho-saturn-tree-label",
"soho-uranus-tree-label",
"soho-neptune-tree-label"
],
"stereo_a": [],
"stereo_b": [
"stereo_b-mercury-tree-label",
"stereo_b-venus-tree-label",
"stereo_b-earth-tree-label",
"stereo_b-mars-tree-label",
"stereo_b-jupiter-tree-label",
"stereo_b-saturn-tree-label",
"stereo_b-uranus-tree-label",
"stereo_b-neptune-tree-label"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"imageScale": 6.18140735516908,
"layers": "[SDO,AIA,131,1,100,0,60,1,2018-03-30T04:18:36.000Z]",
"eventsState": {
"tree_HEK": {
"id": "HEK",
"layers": [],
"visible": true,
"labels_visible": true,
"markers_visible": true,
"layer_available_visible": false
},
"tree_CCMC": {
"id": "CCMC",
"layers": [],
"visible": true,
"labels_visible": true,
"markers_visible": true,
"layer_available_visible": true
},
"tree_RHESSI": {
"id": "RHESSI",
"layers": [],
"visible": true,
"labels_visible": true,
"markers_visible": true,
"layer_available_visible": true
}
},
"scale": true,
"scaleType": "earth",
"scaleX": -2541,
"scaleY": 266,
"format": "mp4",
"size": 0,
"movieIcons": 0,
"followViewport": 0,
"reqObservationDate": "2024-07-22T15:48:07.000Z",
"switchSources": false,
"celestialBodiesLabels": "soho-mercury,soho-venus,soho-mars,soho-jupiter,soho-saturn,soho-uranus,soho-neptune,stereo_b-mercury,stereo_b-venus,stereo_b-earth,stereo_b-mars,stereo_b-jupiter,stereo_b-saturn,stereo_b-uranus,stereo_b-neptune",
"celestialBodiesTrajectories": "",
"x1": -3813.9283381393225,
"x2": 4296.07811184251,
"y1": -776.8998873768866,
"y2": 3203.926449352001,
"startTime": "2024-07-22T03:48:07.000Z",
"endTime": "2024-07-23T03:48:07.000Z",
"frameRate": 15
}
Loading

0 comments on commit c526b80

Please sign in to comment.