Skip to content
Snippets Groups Projects
Commit bafe438b authored by Nico Vermaas's avatar Nico Vermaas
Browse files

add unittests

parent 0c77a7c6
No related branches found
No related tags found
1 merge request!364add unittests
Pipeline #91055 passed
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
{% include 'taskdatabase/pagination.html' %} {% include 'taskdatabase/pagination.html' %}
</div> </div>
</div> </div>
<p class="footer"> Version 8 Aug 2024 <p class="footer"> Version 13 Aug 2024
</div> </div>
{% include 'taskdatabase/refresh.html' %} {% include 'taskdatabase/refresh.html' %}
......
from django.test import TestCase from django.test import TestCase
from django.utils import timezone from django.utils import timezone
from datetime import datetime from datetime import datetime
from taskdatabase.models import LogEntry, Task, Workflow, Job from taskdatabase.models import LogEntry, Task, Workflow, Job, Configuration
from taskdatabase.services import algorithms from taskdatabase.services import algorithms
from unittest.mock import Mock, MagicMock, patch from unittest.mock import Mock, MagicMock, patch
class TestAlgorithms(TestCase): class TestAlgorithms(TestCase):
def setUp(self): def setUp(self):
# Create a Task instance to use in the LogEntry tests
# used to test the get_size calculation, this uses a database # used to test the get_size calculation, this uses a database
self.workflow = Workflow(id=22, workflow_uri="psrfits_requantisation") self.workflow = Workflow(id=22, workflow_uri="psrfits_requantisation")
...@@ -240,6 +239,7 @@ class TestAlgorithms(TestCase): ...@@ -240,6 +239,7 @@ class TestAlgorithms(TestCase):
self.assertIn("<tr><td><b>QA uv-coverage</b></td><td>Good</td></tr>", result) self.assertIn("<tr><td><b>QA uv-coverage</b></td><td>Good</td></tr>", result)
self.assertIn("<tr><td><b>QA sensitivity</b></td><td>Moderate</td></tr>", result) self.assertIn("<tr><td><b>QA sensitivity</b></td><td>Moderate</td></tr>", result)
def test_convert_quality_to_html_complete(self): def test_convert_quality_to_html_complete(self):
# Comprehensive test with all fields filled # Comprehensive test with all fields filled
...@@ -290,6 +290,7 @@ class TestAlgorithms(TestCase): ...@@ -290,6 +290,7 @@ class TestAlgorithms(TestCase):
# assert # assert
self.assertEqual(expected_html, result) self.assertEqual(expected_html, result)
def test_construct_inspection_plots_expand_image(self): def test_construct_inspection_plots_expand_image(self):
# arrange # arrange
...@@ -300,6 +301,7 @@ class TestAlgorithms(TestCase): ...@@ -300,6 +301,7 @@ class TestAlgorithms(TestCase):
# assert # assert
self.assertEqual(expected_html, result) self.assertEqual(expected_html, result)
def test_construct_inspection_plots_sas_id(self): def test_construct_inspection_plots_sas_id(self):
# Test the rendering of inspection plots for a sas_id # Test the rendering of inspection plots for a sas_id
...@@ -319,6 +321,7 @@ class TestAlgorithms(TestCase): ...@@ -319,6 +321,7 @@ class TestAlgorithms(TestCase):
# assert # assert
self.assertEqual(expected_html, result) self.assertEqual(expected_html, result)
def test_convert_list_of_dicts_to_html(self): def test_convert_list_of_dicts_to_html(self):
# arrange # arrange
expected_html = '<tr><td><b>metric1</b></td><td>value1</td></tr><tr><td><b>metric2</b></td><td><a href="http://my_web_link">metric2</a></td></tr>' expected_html = '<tr><td><b>metric1</b></td><td>value1</td></tr><tr><td><b>metric2</b></td><td><a href="http://my_web_link">metric2</a></td></tr>'
...@@ -329,6 +332,7 @@ class TestAlgorithms(TestCase): ...@@ -329,6 +332,7 @@ class TestAlgorithms(TestCase):
# assert # assert
self.assertEqual(expected_html, result) self.assertEqual(expected_html, result)
def test_convert_json_to_nested_table(self): def test_convert_json_to_nested_table(self):
# arrange # arrange
...@@ -343,3 +347,5 @@ class TestAlgorithms(TestCase): ...@@ -343,3 +347,5 @@ class TestAlgorithms(TestCase):
# assert # assert
self.assertEqual(expected_html, result) self.assertEqual(expected_html, result)
...@@ -1775,7 +1775,7 @@ def GetSummary(request, sas_id, format): ...@@ -1775,7 +1775,7 @@ def GetSummary(request, sas_id, format):
@staff_member_required @staff_member_required
def AssociateActivities(request): def AssociateActivities(request): # pragma: no cover
# disconnect the signals to avoid unneccesary updates # disconnect the signals to avoid unneccesary updates
disconnect_signals() disconnect_signals()
...@@ -1796,7 +1796,7 @@ def AssociateActivities(request): ...@@ -1796,7 +1796,7 @@ def AssociateActivities(request):
return redirect('index') return redirect('index')
def UpdateActivitySasId(request, sas_id): def UpdateActivitySasId(request, sas_id): # pragma: no cover
# this function is called externally to avoid worker timeouts # this function is called externally to avoid worker timeouts
# http://localhost:8000/atdb/tasks/repair/update-activity/600907 # http://localhost:8000/atdb/tasks/repair/update-activity/600907
...@@ -1825,7 +1825,7 @@ def UpdateActivitySasId(request, sas_id): ...@@ -1825,7 +1825,7 @@ def UpdateActivitySasId(request, sas_id):
'total': total 'total': total
}) })
def UpdateSummaryFlag(request, task_id): def UpdateSummaryFlag(request, task_id): # pragma: no cover
# this function is called externally to avoid worker timeouts # this function is called externally to avoid worker timeouts
# http://localhost:8000/atdb/tasks/repair/update-summary-flag/12345 # http://localhost:8000/atdb/tasks/repair/update-summary-flag/12345
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment