Skip to content
Snippets Groups Projects
Commit 76177d4b authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

LEI-106: Add test coverage for nested urls and related item lists

parent eb733d45
No related branches found
No related tags found
1 merge request!87Lsmr epic
......@@ -4247,7 +4247,7 @@ SAS/LSMR/src/lsmr/lsmrapp/__init__.py -text
SAS/LSMR/src/lsmr/lsmrapp/admin.py -text
SAS/LSMR/src/lsmr/lsmrapp/apps.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/0001_initial.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20190429_1219.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20190513_1711.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/0003_populate.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/CMakeLists.txt -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/__init__.py -text
......
# Generated by Django 2.0.6 on 2019-04-29 12:19
# Generated by Django 2.0.6 on 2019-05-13 17:11
import django.contrib.postgres.fields
import django.contrib.postgres.fields.jsonb
......@@ -592,7 +592,7 @@ class Migration(migrations.Migration):
('specifications_doc', django.contrib.postgres.fields.jsonb.JSONField(help_text='Specifications for this task.')),
('copies', models.ForeignKey(help_text='Source reference, if we are a copy (NULLable).', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='copied_from', to='lsmrapp.TaskDraft')),
('copy_reason', models.ForeignKey(help_text='Reason why source was copied (NULLable).', on_delete=django.db.models.deletion.PROTECT, to='lsmrapp.CopyReasonChoice')),
('scheduling_unit_draft', models.ForeignKey(help_text='Scheduling Unit draft to which this task draft belongs.', on_delete=django.db.models.deletion.CASCADE, to='lsmrapp.SchedulingUnitDraft')),
('scheduling_unit_draft', models.ForeignKey(help_text='Scheduling Unit draft to which this task draft belongs.', on_delete=django.db.models.deletion.CASCADE, related_name='task_drafts', to='lsmrapp.SchedulingUnitDraft')),
],
options={
'abstract': False,
......@@ -672,7 +672,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='taskrelationblueprint',
name='draft',
field=models.ForeignKey(help_text='Task Relation Draft which this work request instantiates.', on_delete=django.db.models.deletion.CASCADE, to='lsmrapp.TaskRelationDraft'),
field=models.ForeignKey(help_text='Task Relation Draft which this work request instantiates.', on_delete=django.db.models.deletion.CASCADE, related_name='related_task_relation_blueprint', to='lsmrapp.TaskRelationDraft'),
),
migrations.AddField(
model_name='taskrelationblueprint',
......@@ -777,7 +777,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='subtask',
name='task_blueprint',
field=models.ForeignKey(help_text='Task Blueprint to which this Subtask belongs.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='lsmrapp.TaskBlueprint'),
field=models.ForeignKey(help_text='Task Blueprint to which this Subtask belongs.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='subtasks', to='lsmrapp.TaskBlueprint'),
),
migrations.AddField(
model_name='subtask',
......
......@@ -6,7 +6,7 @@ from ..populate import *
class Migration(migrations.Migration):
dependencies = [
('lsmrapp', '0002_auto_20190429_1219'),
('lsmrapp', '0002_auto_20190513_1711'),
]
operations = [ migrations.RunPython(populate_choices) ]
......@@ -199,7 +199,7 @@ class Cycle(NamedCommon):
class Project(NamedCommon):
# cycle is protected since we have to manually decide to clean up projects with a cycle or keep them without cycle
# cycle is protected since we hav<e to manually decide to clean up projects with a cycle or keep them without cycle
cycle = ForeignKey('Cycle', related_name='projects', on_delete=PROTECT, null=True, help_text='Cycle(s) to which this project belongs (NULLable).')
priority = IntegerField(default=0, help_text='Priority of this project w.r.t. other projects. Projects can interrupt observations of lower-priority projects.') # todo: define a value for the default priority
can_trigger = BooleanField(default=False, help_text='True if this project is allowed to supply observation requests on the fly, possibly interrupting currently running observations (responsive telescope).')
......
......@@ -154,7 +154,7 @@ class TaskRelationDraftViewSet(viewsets.ModelViewSet):
def get_queryset(self):
if 'task_draft_pk' in self.kwargs:
task_draft = get_object_or_404(models.TaskDraft, pk=self.kwargs['task_draft_pk'])
return task_draft.produced_by.all() + task_draft.consumed_by.all()
return task_draft.produced_by.all() | task_draft.consumed_by.all()
else:
return models.TaskRelationDraft.objects.all()
......@@ -167,7 +167,7 @@ class TaskRelationBlueprintViewSet(viewsets.ModelViewSet):
def get_queryset(self):
if 'task_blueprint_pk' in self.kwargs:
task_blueprint = get_object_or_404(models.TaskBlueprint, pk=self.kwargs['task_blueprint_pk'])
return task_blueprint.produced_by.all() + task_blueprint.consumed_by.all()
return task_blueprint.produced_by.all() | task_blueprint.consumed_by.all()
elif 'task_relation_draft_pk' in self.kwargs:
task_relation_draft = get_object_or_404(models.TaskRelationDraft, pk=self.kwargs['task_relation_draft_pk'])
return task_relation_draft.related_task_relation_blueprint.all()
......
......@@ -24,7 +24,7 @@ import rest_framework.test
from lsmr.lsmrapp.populate import populate_choices
from lsmr.lsmrapp import models
from django.db.utils import IntegrityError
from t_lsmrapp_specification_django import assertDataWithUrls, TaskBlueprintTest, TaskRelationBlueprintTest
import t_lsmrapp_specification_django # import assertDataWithUrls, TaskBlueprintTest, TaskRelationBlueprintTest
from datetime import datetime # use this to create timezone-aware datetime objects: from django.utils import timezone
from django.contrib.auth.models import User
......@@ -302,7 +302,7 @@ class SubtaskOutputTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/subtask_output/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_SubtaskOutput_view_returns_correct_entry(self):
# setup
......@@ -314,8 +314,8 @@ class SubtaskOutputTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/subtask_output/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
def test_SubtaskOutput_prevents_missing_subtask(self):
......@@ -352,7 +352,7 @@ class SubtaskInputTest(rest_framework.test.APITransactionTestCase):
sct = SubtaskConnectorTest()
sct.setUp(populate=False)
trbt = TaskRelationBlueprintTest()
trbt = t_lsmrapp_specification_django.TaskRelationBlueprintTest()
trbt.setUp(populate=False)
# test data
......@@ -410,7 +410,7 @@ class SubtaskInputTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/subtask_input/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_SubtaskInput_view_returns_correct_entry(self):
# setup
......@@ -422,8 +422,8 @@ class SubtaskInputTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/subtask_input/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
def test_SubtaskInput_prevents_missing_subtask(self):
......@@ -451,7 +451,7 @@ class SubtaskInputTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/subtask_input/%s' % si.id, format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data, self.test_data_1)
class SubtaskTest(rest_framework.test.APITransactionTestCase):
......@@ -469,7 +469,7 @@ class SubtaskTest(rest_framework.test.APITransactionTestCase):
except:
print("why is this happening!? Continuing anyway...")
wrbt = TaskBlueprintTest()
wrbt = t_lsmrapp_specification_django.TaskBlueprintTest()
wrbt.setUp(populate=False)
# test data
......@@ -536,7 +536,7 @@ class SubtaskTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/subtask/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_Subtask_view_returns_correct_entry(self):
......@@ -549,8 +549,8 @@ class SubtaskTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/subtask/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
def test_Subtask_prevents_missing_template(self):
......@@ -562,6 +562,35 @@ class SubtaskTest(rest_framework.test.APITransactionTestCase):
with self.assertRaises(IntegrityError):
models.Subtask.objects.create(**test_data)
def test_nested_Subtask_are_filtered_according_to_TaskBlueprint(self):
tbt = t_lsmrapp_specification_django.TaskBlueprintTest()
tbt.setUp(populate=False)
# setup
task_blueprint_1 = models.TaskBlueprint.objects.create(**tbt.test_data_1)
task_blueprint_2 = models.TaskBlueprint.objects.create(**tbt.test_data_2)
test_data_1 = dict(self.test_data_1)
test_data_1['task_blueprint'] = task_blueprint_1
subtask_1 = models.Subtask.objects.create(**test_data_1)
test_data_2 = dict(self.test_data_2)
test_data_2['task_blueprint'] = task_blueprint_2
subtask_2 = models.Subtask.objects.create(**test_data_2)
# assert
response = client.get('/task_blueprint/%s/subtask/' % task_blueprint_2.id, format='json', follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data['results']), 1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], test_data_2)
response = client.get(
'/task_blueprint/%s/subtask/%s/' % (task_blueprint_2.id, subtask_2.id), format='json', follow=True)
self.assertEqual(response.status_code, 200)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data, test_data_2)
response = client.get( '/task_blueprint/%s/subtask/%s/' % (task_blueprint_2.id, subtask_1.id), format='json', follow=True)
self.assertEqual(response.status_code, 404)
class DataproductTest(rest_framework.test.APITransactionTestCase):
......@@ -641,7 +670,7 @@ class DataproductTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/dataproduct/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_Dataproduct_view_returns_correct_entry(self):
......@@ -654,8 +683,8 @@ class DataproductTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/dataproduct/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
def test_Dataproduct_prevents_missing_specifications_template(self):
......@@ -734,7 +763,7 @@ class SubtaskConnectorTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/subtask_connector/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_SubtaskConnector_view_returns_correct_entry(self):
# setup
......@@ -746,8 +775,8 @@ class SubtaskConnectorTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/subtask_connector/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
def test_SubtaskConnector_allows_setting_dataformats(self):
# Other then through the API view, we cannot assign ManyToMany on creation, but have to set it later
......@@ -762,7 +791,7 @@ class SubtaskConnectorTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/subtask_connector/%s' % tior.id, format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data, self.test_data_2)
class AntennaSetTest(rest_framework.test.APITransactionTestCase):
......@@ -829,7 +858,7 @@ class AntennaSetTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/antenna_set/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_AntennaSet_view_returns_correct_entry(self):
# setup
......@@ -841,8 +870,8 @@ class AntennaSetTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/antenna_set/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
class DataproductTransformTest(rest_framework.test.APITransactionTestCase):
......@@ -908,7 +937,7 @@ class DataproductTransformTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/dataproduct_transform/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_DataproductTransform_view_returns_correct_entry(self):
# setup
......@@ -920,8 +949,8 @@ class DataproductTransformTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/dataproduct_transform/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
class FilesystemTest(rest_framework.test.APITransactionTestCase):
......@@ -977,7 +1006,7 @@ class FilesystemTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/filesystem/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_Filesystem_view_returns_correct_entry(self):
# setup
......@@ -989,8 +1018,8 @@ class FilesystemTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/filesystem/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
class ClusterTest(rest_framework.test.APITransactionTestCase):
......@@ -1043,7 +1072,7 @@ class ClusterTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/cluster/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_Cluster_view_returns_correct_entry(self):
# setup
......@@ -1055,8 +1084,8 @@ class ClusterTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/cluster/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
class DataproductArchiveInfoTest(rest_framework.test.APITransactionTestCase):
......@@ -1125,7 +1154,7 @@ class DataproductArchiveInfoTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/dataproduct_archive_info/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_DataproductArchiveInfo_view_returns_correct_entry(self):
# setup
......@@ -1137,8 +1166,8 @@ class DataproductArchiveInfoTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/dataproduct_archive_info/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
class DataproductHashTest(rest_framework.test.APITransactionTestCase):
......@@ -1205,7 +1234,7 @@ class DataproductHashTest(rest_framework.test.APITransactionTestCase):
# assert
response = client.get('/dataproduct_hash/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response.data['results'][0], self.test_data_1)
def test_GET_DataproductHash_view_returns_correct_entry(self):
# setup
......@@ -1217,7 +1246,7 @@ class DataproductHashTest(rest_framework.test.APITransactionTestCase):
response2 = client.get('/dataproduct_hash/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
assertDataWithUrls(self, response1.data, self.test_data_1)
assertDataWithUrls(self, response2.data, self.test_data_2)
t_lsmrapp_specification_django.assertDataWithUrls(self, response1.data, self.test_data_1)
t_lsmrapp_specification_django.assertDataWithUrls(self, response2.data, self.test_data_2)
This diff is collapsed.
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