From 6926758b134fc668b41b6304e2f7759bce31ff1c Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Tue, 11 Feb 2020 16:51:56 +0100 Subject: [PATCH] TMSS-142: test with valid and invalid json specs against DUPPLO UC1 correlator schema from populated database --- SAS/TMSS/test/t_subtask_validation.py | 132 ++++---------------------- 1 file changed, 20 insertions(+), 112 deletions(-) diff --git a/SAS/TMSS/test/t_subtask_validation.py b/SAS/TMSS/test/t_subtask_validation.py index 78b0f7c6ede..3bf0768f871 100755 --- a/SAS/TMSS/test/t_subtask_validation.py +++ b/SAS/TMSS/test/t_subtask_validation.py @@ -105,118 +105,9 @@ class SubtaskValidationTest(unittest.TestCase): self.assertTrue('invalid json' in str(context.exception).lower()) def test_validate_correlator_schema(self): - # initial correlator_schema for Dupplo UC1 - subtask_template = self.create_subtask_template(''' - { - "$id": "http://example.com/example.json", - "type": "object", - "$schema": "http://json-schema.org/draft-06/schema#", - "definitions": { - "pointing": { - "type": "object", - "additionalProperties": false, - "properties": { - "direction_type": { - "type": "string", - "title": "Reference frame", - "description": "", - "default": "J2000", - "enum": [ - "J2000", - "SUN", - "MOON", - "MERCURY", - "VENUS", - "MARS", - "JUPITER", - "SATURN", - "URANUS", - "NEPTUNE", - "PLUTO" - ] - }, - "angle1": { - "type": "number", - "title": "Angle 1", - "description": "First angle (f.e. RA)", - "default": 0 - }, - "angle2": { - "type": "number", - "title": "Angle 2", - "description": "Second angle (f.e. DEC)", - "default": 0 - } - } - } - }, - "additionalProperties": false, - "properties": { - "duration": { - "type": "number", - "title": "Duration (seconds)", - "description": "Duration of this observation", - "default": 60, - "minimum": 1 - }, - "calibrator": { - "type": "object", - "additionalProperties": false, - "properties": { - "enabled": { - "type": "boolean", - "title": "Calibrator", - "description": "Replace targets by calibrators", - "default": false - }, - "autoselect": { - "type": "boolean", - "title": "Auto-select", - "description": "Auto-select calibrator based on elevation", - "default": false - }, - "pointing": { - "title": "Digital pointing", - "$ref": "#/definitions/pointing" - } - } - }, - "channels_per_subband": { - "type": "integer", - "title": "Channels/subband", - "description": "Number of frequency bands per subband", - "default": 64, - "minimum": 8, - "enum": [ - 8, - 16, - 32, - 64, - 128, - 256, - 512, - 1024 - ] - }, - "integration_time": { - "type": "number", - "title": "Integration time (seconds)", - "description": "Desired integration period", - "default": 1, - "minimum": 0.1 - }, - "storage_cluster": { - "type": "string", - "title": "Storage cluster", - "description": "Cluster to write output to", - "default": "CEP4", - "enum": [ - "CEP4", - "DragNet" - ] - } - } -}''') + # fetch correlator_schema for Dupplo UC1 which should be in the initially populated database + subtask_template = models.SubtaskTemplate.objects.get(name='correlator schema') + self.assertIsNotNone(subtask_template) specifications_doc = '''{ "duration": 10, "calibrator": { "pointing": {} } @@ -226,6 +117,23 @@ class SubtaskValidationTest(unittest.TestCase): subtask = models.Subtask.objects.create(**subtask_data) self.assertIsNotNone(subtask) + def test_validate_correlator_schema_with_invalid_specification(self): + # fetch correlator_schema for Dupplo UC1 which should be in the initially populated database + subtask_template = models.SubtaskTemplate.objects.get(name='correlator schema') + self.assertIsNotNone(subtask_template) + + # test with invalid json + with self.assertRaises(SpecificationException) as context: + subtask_data = Subtask_test_data(subtask_template, "bogus spec") + models.Subtask.objects.create(**subtask_data) + self.assertTrue('invalid json' in str(context.exception).lower()) + + # test with valid json, but not according to schema + with self.assertRaises(SpecificationException) as context: + specifications_doc = '''{ "duration": -10 }''' + subtask_data = Subtask_test_data(subtask_template, specifications_doc) + models.Subtask.objects.create(**subtask_data) + self.assertTrue('-10' in str(context.exception).lower()) if __name__ == "__main__": -- GitLab