Commit 20addb86 authored by Jorrit Schaap's avatar Jorrit Schaap

TMSS-153: fixed tests

parent 584bd049
......@@ -164,7 +164,7 @@ class SubtaskViewSetJSONeditorOnline(LOFARViewSet):
queryset = models.Subtask.objects.all()
serializer_class = serializers.SubtaskSerializerJSONeditorOnline
def get_view_name(self): # override name because DRF auto-naming does not produce something usable here
def get_view_name(self): # override name because DRF auto-naming dot_tmssapp_scheduling_djangoes not produce something usable here
name = "Subtask"
if self.suffix:
name += ' ' + self.suffix
......
......@@ -53,7 +53,7 @@ class SubtaskValidationTest(unittest.TestCase):
def test_validate_simple_string_schema_with_valid_specification(self):
subtask_template = self.create_subtask_template('{"type": "string"}')
specifications_doc = '"a random string"'
subtask_data = Subtask_test_data(subtask_template, specifications_doc)
subtask_data = Subtask_test_data(subtask_template=subtask_template, specifications_doc=specifications_doc)
subtask = models.Subtask.objects.create(**subtask_data)
self.assertIsNotNone(subtask)
......@@ -61,7 +61,7 @@ class SubtaskValidationTest(unittest.TestCase):
def test_validate_simple_string_schema_with_invalid_specification(self):
subtask_template = self.create_subtask_template('{"type": "string"}')
specifications_doc = '42'
subtask_data = Subtask_test_data(subtask_template, specifications_doc)
subtask_data = Subtask_test_data(subtask_template=subtask_template, specifications_doc=specifications_doc)
with self.assertRaises(SpecificationException):
models.Subtask.objects.create(**subtask_data)
......@@ -70,7 +70,7 @@ class SubtaskValidationTest(unittest.TestCase):
def test_validate_simple_string_schema_when_updating_valid_to_invalid_specification(self):
subtask_template = self.create_subtask_template('{"type": "string"}')
valid_spec = '"a random string"'
subtask_data = Subtask_test_data(subtask_template, valid_spec)
subtask_data = Subtask_test_data(subtask_template=subtask_template, specifications_doc=valid_spec)
subtask = models.Subtask.objects.create(**subtask_data)
self.assertIsNotNone(subtask)
......@@ -89,7 +89,7 @@ class SubtaskValidationTest(unittest.TestCase):
def test_validate_simple_string_schema_with_valid_specification(self):
subtask_template = self.create_subtask_template('{"type": "string"}')
specifications_doc = '"a random string"'
subtask_data = Subtask_test_data(subtask_template, specifications_doc)
subtask_data = Subtask_test_data(subtask_template=subtask_template, specifications_doc=specifications_doc)
subtask = models.Subtask.objects.create(**subtask_data)
self.assertIsNotNone(subtask)
......@@ -97,7 +97,7 @@ class SubtaskValidationTest(unittest.TestCase):
def test_validate_flawed_json_schema(self):
subtask_template = self.create_subtask_template('{ this is not a json object }')
specifications_doc = '"a random string"'
subtask_data = Subtask_test_data(subtask_template, specifications_doc)
subtask_data = Subtask_test_data(subtask_template=subtask_template, specifications_doc=specifications_doc)
with self.assertRaises(SpecificationException) as context:
models.Subtask.objects.create(**subtask_data)
......@@ -106,7 +106,7 @@ class SubtaskValidationTest(unittest.TestCase):
def test_validate_flawed_json_specification(self):
subtask_template = self.create_subtask_template('{"type": "string"}')
specifications_doc = '{ this is not a json object }'
subtask_data = Subtask_test_data(subtask_template, specifications_doc)
subtask_data = Subtask_test_data(subtask_template=subtask_template, specifications_doc=specifications_doc)
with self.assertRaises(SpecificationException) as context:
models.Subtask.objects.create(**subtask_data)
......@@ -114,32 +114,30 @@ class SubtaskValidationTest(unittest.TestCase):
def test_validate_correlator_schema_with_valid_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')
subtask_template = models.SubtaskTemplate.objects.get(name='observationcontrol schema')
self.assertIsNotNone(subtask_template)
specifications_doc = '''{ "duration": 10,
"calibrator": { "pointing": {} }
}'''
subtask_data = Subtask_test_data(subtask_template, specifications_doc)
specifications_doc = get_default_json_object_for_schema(subtask_template.schema)
subtask_data = Subtask_test_data(subtask_template=subtask_template, specifications_doc=specifications_doc)
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')
subtask_template = models.SubtaskTemplate.objects.get(name='observationcontrol schema')
self.assertIsNotNone(subtask_template)
# test with invalid json
with self.assertRaises(SpecificationException) as context:
subtask_data = Subtask_test_data(subtask_template, "bogus spec")
subtask_data = Subtask_test_data(subtask_template=subtask_template, specifications_doc="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)
subtask_data = Subtask_test_data(subtask_template=subtask_template, specifications_doc=specifications_doc)
models.Subtask.objects.create(**subtask_data)
self.assertTrue('-10' in str(context.exception).lower())
......@@ -170,17 +168,16 @@ class SubtaskValidationTest(unittest.TestCase):
def test_validate_correlator_schema_with_valid_specification_via_rest(self):
# fetch correlator_schema for Dupplo UC1 which should be in the initially populated database
response = requests.get(BASE_URL+"/subtask_template/", {"format": "json", "name": "correlator schema"}, auth=AUTH)
response = requests.get(BASE_URL+"/subtask_template/", {"format": "json", "name": "observationcontrol schema"}, auth=AUTH)
self.assertEqual(200, response.status_code)
json_response = response.json()
self.assertEqual(1, json_response.get('count'))
template = json_response['results'][0]
schema_url = template['url']
schema = template['schema']
specifications_doc = '''{ "duration": 10,
"calibrator": { "pointing": {} }
}'''
specifications_doc = get_default_json_object_for_schema(schema)
subtask_test_data = rest_data_creator.Subtask(specifications_template_url=schema_url, specifications_doc=specifications_doc)
# POST and GET a new item and assert correctness
......@@ -190,7 +187,7 @@ class SubtaskValidationTest(unittest.TestCase):
def test_validate_correlator_schema_with_invalid_specification_via_rest(self):
# fetch correlator_schema for Dupplo UC1 which should be in the initially populated database
response = requests.get(BASE_URL+"/subtask_template/", {"format": "json", "name": "correlator schema"}, auth=AUTH)
response = requests.get(BASE_URL+"/subtask_template/", {"format": "json", "name": "observationcontrol schema"}, auth=AUTH)
self.assertEqual(200, response.status_code)
json_response = response.json()
self.assertEqual(1, json_response.get('count'))
......
......@@ -265,11 +265,11 @@ def Dataproduct_test_data(producer: models.SubtaskOutput=None, filename: str="my
"feedback_template": models.DataproductFeedbackTemplate.objects.create(**DataproductFeedbackTemplate_test_data())}
def SubtaskConnector_test_data(output_of: models.SubtaskTemplate=None, input_of: models.SubtaskTemplate=None) -> dict:
# if output_of is None:
# output_of = models.SubtaskTemplate.objects.create(**SubtaskTemplate_test_data())
#
# if input_of is None:
# input_of = models.SubtaskTemplate.objects.create(**SubtaskTemplate_test_data())
if output_of is None:
output_of = models.SubtaskTemplate.objects.create(**SubtaskTemplate_test_data())
if input_of is None:
input_of = models.SubtaskTemplate.objects.create(**SubtaskTemplate_test_data())
return {"role": models.Role.objects.get(value='calibrator'),
"datatype": models.Datatype.objects.get(value='instrument model'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment