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

add unittests

parent 04ccd8e2
No related branches found
No related tags found
1 merge request!334updates after demo to SDCO
Pipeline #69000 passed
......@@ -304,17 +304,18 @@ class Task(models.Model):
return None
@property
def path_to_lta(self):
def sasid_path_to_lta(self):
"""
check if any task belonging to this sas_id already has a 'path_to_lta' setting
"""
try:
for task in Task.objects.filter(sas_id=self.sas_id):
if task.archive['path_to_lta']:
try:
try:
if task.archive['path_to_lta']:
return task.archive['path_to_lta']
except:
pass
except:
# if 'path_to_lta' is not found, or 'archive' is empty, continue to the next task
pass
except:
return None
......
from django.test import TestCase
from taskdatabase.models import Task, Workflow
class TaskModelTestCase(TestCase):
def setUp(self):
# Create tasks for testing
# the first 2 have no valid path set
self.task1 = Task.objects.create(sas_id=12345,archive={})
self.task2 = Task.objects.create(sas_id=12345,archive={'path_to_lta': None})
# this task has a valid path_to_lta set
self.task3 = Task.objects.create(sas_id=12345,archive={'path_to_lta': '/sample/path'})
# this sasid has no path_to_lta set at all
self.task4 = Task.objects.create(sas_id=66666,archive={})
self.task5 = Task.objects.create(sas_id=66666,archive={})
def test_path_to_lta_with_path(self):
# if only one of the tasks has a path_to_lta, then the other tasks should also return that path
for task in Task.objects.filter(sas_id=12345):
result = task.sasid_path_to_lta
self.assertEqual(result, '/sample/path')
def test_path_to_lta_without_path(self):
# if one of the tasks has 'path_to_lta' set, then return None
for task in Task.objects.filter(sas_id=66666):
result = task.sasid_path_to_lta
self.assertEqual(result, None)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment