From a8023d9211927ff9a340eca3641657f94d289645 Mon Sep 17 00:00:00 2001 From: Vermaas <vermaas@astron.nl> Date: Fri, 26 Jul 2024 10:42:51 +0200 Subject: [PATCH] adding more unittests --- atdb/taskdatabase/models.py | 68 ------------------- .../taskdatabase/validation/tasks.html | 2 +- .../tests/test_models_processed_summary.py | 39 ++++++++++- .../tests/test_views_postprocessing_page.py | 19 ++++++ 4 files changed, 57 insertions(+), 71 deletions(-) create mode 100644 atdb/taskdatabase/tests/test_views_postprocessing_page.py diff --git a/atdb/taskdatabase/models.py b/atdb/taskdatabase/models.py index bc3c82ba..adb0cc5d 100644 --- a/atdb/taskdatabase/models.py +++ b/atdb/taskdatabase/models.py @@ -42,51 +42,6 @@ class Workflow(models.Model): return str(self.id) + ' - ' + str(self.workflow_uri) -# convert the quality information from the JSONfield into a easy parsable list for the template -def convert_quality_to_list_for_template(task): - list = [] - - try: - list.append(str(task.quality_json['uv-coverage'])) - except: - list.append("-") - - try: - list.append(str(task.quality_json['sensitivity'])) - except: - list.append("-") - - try: - list.append(str(task.quality_json['observing-conditions'])) - except: - list.append("-") - - return list - - -def convert_quality_to_shortlist_for_template(task): - list = [] - - try: - list.append(str(task.quality_json['uv-coverage'])) - list.append(str(task.quality_json['sensitivity'])) - list.append(str(task.quality_json['observing-conditions'])) - except Exception as err: - pass - - return list - -def convert_summary_to_list_for_template(task): - list = [] - - try: - summary = task.quality_json['summary'] - - except Exception as err: - pass - - return list - def associate_task_with_activity(task): if not task.activity: @@ -410,29 +365,6 @@ class Task(models.Model): except: return None - @property - def quality_as_list(self): - try: - q = convert_quality_to_list_for_template(self) - return q - except: - return None - - @property - def quality_as_shortlist(self): - try: - q = convert_quality_to_shortlist_for_template(self) - return q - except: - return None - - @property - def summary_as_list(self): - try: - q = convert_summary_to_list_for_template(self) - return q - except: - return None @property def sas_id_archived(self): diff --git a/atdb/taskdatabase/templates/taskdatabase/validation/tasks.html b/atdb/taskdatabase/templates/taskdatabase/validation/tasks.html index 85b5007c..856161ca 100644 --- a/atdb/taskdatabase/templates/taskdatabase/validation/tasks.html +++ b/atdb/taskdatabase/templates/taskdatabase/validation/tasks.html @@ -44,7 +44,7 @@ {% endif %} {% else %} - <td>-</td><td>-</td><td>-</td><td>-</td><td>-</td> + <td>-</td><td>-</td> {% endif %} diff --git a/atdb/taskdatabase/tests/test_models_processed_summary.py b/atdb/taskdatabase/tests/test_models_processed_summary.py index 2c317872..9774545c 100644 --- a/atdb/taskdatabase/tests/test_models_processed_summary.py +++ b/atdb/taskdatabase/tests/test_models_processed_summary.py @@ -37,7 +37,14 @@ class TestProcessedSummary(TestCase): self.task3 = Task.objects.create(sas_id=222, new_status=State.PROCESSED.value, workflow=self.workflow_requantisation, - outputs={"summary": [{"is_summary": True}]}) + outputs={ + "summary": [{"is_summary": True}], + "quality": { + "summary" : {"L441006_summaryCS.tar" : {"is_summary" : True} }, + "plots" : [{"basename": "L441006_CS_quick_summary.pdf"}] + } + }) + self.task3.save() # this is a summary task, but it uses a workflow with an aggregation_strategy that should not hold the task @@ -91,4 +98,32 @@ class TestProcessedSummary(TestCase): task 3 only has the new 'is_summary' test. Check if the task indeed gets seen as a summary_task """ actual = self.task3.is_summary - self.assertTrue(actual) \ No newline at end of file + self.assertTrue(actual) + + def test_has_quality_summary(self): + """ + task 3 has both the quality.summary field and summary field filled + It is the quality.summary field that is used as the real source of truth. + """ + actual = self.task3.has_summary + self.assertTrue(actual) + + def test_has_plots(self): + """ + task 3 has quality.plots field to test the has_plots function + """ + actual = self.task3.has_plots + self.assertTrue(actual) + + def test_has_no_plots(self): + """ + task 4 has no quality.plots field to test the has_plots function + """ + actual = self.task4.has_plots + self.assertFalse(actual) + def test_predecessor_status(self): + """ + test prececessor_status + """ + actual = self.task3.predecessor_status + self.assertEqual(actual, "no_predecessor") \ No newline at end of file diff --git a/atdb/taskdatabase/tests/test_views_postprocessing_page.py b/atdb/taskdatabase/tests/test_views_postprocessing_page.py new file mode 100644 index 00000000..69b603d4 --- /dev/null +++ b/atdb/taskdatabase/tests/test_views_postprocessing_page.py @@ -0,0 +1,19 @@ +from django.test import TestCase +from django.urls import reverse + +from taskdatabase.models import Task, Workflow +class PostProcessingPageViewTest(TestCase): + + + def test_url_exists_at_desired_location(self): + response = self.client.get('/atdb/postprocessing-tasks') + self.assertEqual(response.status_code, 200) + + def test_url_accessible_by_name(self): + response = self.client.get(reverse('postprocessing-tasks')) + self.assertEqual(response.status_code, 200) + + def test_uses_correct_template(self): + response = self.client.get(reverse('postprocessing-tasks')) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'taskdatabase/postprocessing.html') \ No newline at end of file -- GitLab