Commit 8ad4116b authored by Joern jkuensem's avatar Joern jkuensem

Task LEI-30: Adapt django ORM tests to scheduling model changes

parent 4e1823bb
......@@ -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_20190410_1621.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20190412_1719.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-10 16:21
# Generated by Django 2.0.6 on 2019-04-12 17:19
import django.contrib.postgres.fields
import django.contrib.postgres.fields.jsonb
......@@ -103,6 +103,7 @@ class Migration(migrations.Migration):
('specifications_doc', django.contrib.postgres.fields.jsonb.JSONField()),
('do_cancel', models.DateTimeField()),
('expected_size', models.BigIntegerField()),
('size', models.BigIntegerField()),
('feedback_doc', django.contrib.postgres.fields.jsonb.JSONField()),
],
options={
......@@ -125,7 +126,7 @@ class Migration(migrations.Migration):
},
),
migrations.CreateModel(
name='DataProductFeedbackTemplate',
name='DataproductFeedbackTemplate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=30), blank=True, size=8)),
......@@ -154,7 +155,7 @@ class Migration(migrations.Migration):
},
),
migrations.CreateModel(
name='DataproductSpecificationTemplate',
name='DataproductSpecificationsTemplate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=30), blank=True, size=8)),
......@@ -170,7 +171,7 @@ class Migration(migrations.Migration):
},
),
migrations.CreateModel(
name='DataProductTransform',
name='DataproductTransform',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=30), blank=True, size=8)),
......@@ -192,7 +193,7 @@ class Migration(migrations.Migration):
},
),
migrations.CreateModel(
name='DefaultDataproductSpecificationTemplate',
name='DefaultDataproductSpecificationsTemplate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tags', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=30), blank=True, size=8)),
......@@ -890,9 +891,9 @@ class Migration(migrations.Migration):
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lsmrapp.GeneratorTemplate'),
),
migrations.AddField(
model_name='defaultdataproductspecificationtemplate',
model_name='defaultdataproductspecificationstemplate',
name='template',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lsmrapp.DataproductSpecificationTemplate'),
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lsmrapp.DataproductSpecificationsTemplate'),
),
migrations.AddField(
model_name='dataproducttransform',
......@@ -927,7 +928,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='dataproduct',
name='feedback_template',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lsmrapp.DataProductFeedbackTemplate'),
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lsmrapp.DataproductFeedbackTemplate'),
),
migrations.AddField(
model_name='dataproduct',
......@@ -937,7 +938,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='dataproduct',
name='specifications_template',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lsmrapp.DataproductSpecificationTemplate'),
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lsmrapp.DataproductSpecificationsTemplate'),
),
migrations.AddField(
model_name='antennaset',
......@@ -993,8 +994,8 @@ class Migration(migrations.Migration):
index=django.contrib.postgres.indexes.GinIndex(fields=['tags'], name='lsmrapp_def_tags_2b9ef8_gin'),
),
migrations.AddIndex(
model_name='defaultdataproductspecificationtemplate',
index=django.contrib.postgres.indexes.GinIndex(fields=['tags'], name='lsmrapp_def_tags_fd9476_gin'),
model_name='defaultdataproductspecificationstemplate',
index=django.contrib.postgres.indexes.GinIndex(fields=['tags'], name='lsmrapp_def_tags_0a7453_gin'),
),
migrations.AddIndex(
model_name='dataproducttransform',
......
......@@ -6,7 +6,7 @@ from ..populate import *
class Migration(migrations.Migration):
dependencies = [
('lsmrapp', '0002_auto_20190410_1621'),
('lsmrapp', '0002_auto_20190412_1719'),
]
operations = [ migrations.RunPython(populate_choices) ]
......@@ -98,22 +98,26 @@ class DefaultSubtaskTemplate(BasicCommon):
template = ForeignKey('SubtaskTemplate', on_delete=PROTECT)
class DataproductSpecificationTemplate(Template):
class DataproductSpecificationsTemplate(Template):
pass
class DefaultDataproductSpecificationTemplate(BasicCommon):
class DefaultDataproductSpecificationsTemplate(BasicCommon):
name = CharField(max_length=30, unique=True)
template = ForeignKey('DataproductSpecificationTemplate', on_delete=PROTECT)
template = ForeignKey('DataproductSpecificationsTemplate', on_delete=PROTECT)
class SubtaskInputSelectionTemplate(Template):
pass
# todo: so we need to specify a default?
class DataproductFeedbackTemplate(Template):
pass
# todo: do we need to specify a default?
#
# Instance Objects
......@@ -165,12 +169,12 @@ class Dataproduct(BasicCommon):
deleted_since = DateTimeField(null=True)
pinned_since = DateTimeField(null=True)
specifications_doc = JSONField()
specifications_template = ForeignKey('DataproductSpecificationTemplate', null=False, on_delete=CASCADE)
specifications_template = ForeignKey('DataproductSpecificationsTemplate', null=False, on_delete=CASCADE)
producer = ForeignKey('SubtaskOutput', on_delete=PROTECT)
do_cancel = DateTimeField() # BooleanField() <- after consulting JDM, we opt for datetimefield for consistency
expected_size = BigIntegerField()
size = BigIntegerField
feedback_doc =JSONField()
size = BigIntegerField()
feedback_doc = JSONField()
feedback_template = ForeignKey('DataproductFeedbackTemplate', on_delete=PROTECT)
......
......@@ -16,7 +16,7 @@ class Migration(migrations.Migration):
"""
from .models.specification import RoleChoice, DatatypeChoice, DataformatChoice, CopyReasonChoice
from .models.scheduling import SubtaskStateChoice, SubtaskTypeChoice, StationTypeChoice
from .models.scheduling import SubtaskStateChoice, SubtaskTypeChoice, StationTypeChoice, Algorithm, ScheduleMethod
def populate_choices(apps, schema_editor):
'''
......@@ -25,6 +25,6 @@ def populate_choices(apps, schema_editor):
:return: None
'''
for choice_class in [RoleChoice, DatatypeChoice, DataformatChoice, CopyReasonChoice,
SubtaskStateChoice, SubtaskTypeChoice, StationTypeChoice]:
SubtaskStateChoice, SubtaskTypeChoice, StationTypeChoice, Algorithm, ScheduleMethod]:
choice_class.objects.bulk_create([choice_class(value=x.value) for x in choice_class.Choices])
......@@ -30,6 +30,18 @@ class StationTypeChoiceSerializer(serializers.ModelSerializer):
fields = '__all__'
class AlgorithmSerializer(serializers.ModelSerializer):
class Meta:
model = models.Algorithm
fields = '__all__'
class ScheduleMethodSerializer(serializers.ModelSerializer):
class Meta:
model = models.ScheduleMethod
fields = '__all__'
class SubtaskTemplateSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.SubtaskTemplate
......@@ -42,15 +54,27 @@ class DefaultSubtaskTemplateSerializer(serializers.HyperlinkedModelSerializer):
fields = '__all__'
class DataproductSpecificationTemplateSerializer(serializers.HyperlinkedModelSerializer):
class DataproductSpecificationsTemplateSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.DataproductSpecificationsTemplate
fields = '__all__'
class DefaultDataproductSpecificationsTemplateSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.DefaultDataproductSpecificationsTemplate
fields = '__all__'
class SubtaskInputSelectionTemplateSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.DataproductSpecificationTemplate
model = models.SubtaskInputSelectionTemplate
fields = '__all__'
class DefaultDataproductSpecificationTemplateSerializer(serializers.HyperlinkedModelSerializer):
class DataproductFeedbackTemplateSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.DefaultDataproductSpecificationTemplate
model = models.SubtaskInputSelectionTemplate
fields = '__all__'
......
......@@ -27,6 +27,16 @@ class StationTypeChoiceViewSet(viewsets.ModelViewSet):
serializer_class = serializers.StationTypeChoiceSerializer
class AlgorithmViewSet(viewsets.ModelViewSet):
queryset = models.Algorithm.objects.all()
serializer_class = serializers.AlgorithmSerializer
class ScheduleMethodViewSet(viewsets.ModelViewSet):
queryset = models.ScheduleMethod.objects.all()
serializer_class = serializers.ScheduleMethodSerializer
class SubtaskTemplateViewSet(viewsets.ModelViewSet):
queryset = models.SubtaskTemplate.objects.all()
serializer_class = serializers.SubtaskTemplateSerializer
......@@ -37,14 +47,24 @@ class DefaultSubtaskTemplateViewSet(viewsets.ModelViewSet):
serializer_class = serializers.DefaultSubtaskTemplateSerializer
class DataproductSpecificationTemplateViewSet(viewsets.ModelViewSet):
queryset = models.DataproductSpecificationTemplate.objects.all()
serializer_class = serializers.DataproductSpecificationTemplateSerializer
class DataproductSpecificationsTemplateViewSet(viewsets.ModelViewSet):
queryset = models.DataproductSpecificationsTemplate.objects.all()
serializer_class = serializers.DataproductSpecificationsTemplateSerializer
class DefaultDataproductSpecificationsTemplateViewSet(viewsets.ModelViewSet):
queryset = models.DefaultDataproductSpecificationsTemplate.objects.all()
serializer_class = serializers.DefaultDataproductSpecificationsTemplateSerializer
class SubtaskInputSelectionTemplateViewSet(viewsets.ModelViewSet):
queryset = models.SubtaskInputSelectionTemplate.objects.all()
serializer_class = serializers.SubtaskInputSelectionTemplateSerializer
class DefaultDataproductSpecificationTemplateViewSet(viewsets.ModelViewSet):
queryset = models.DefaultDataproductSpecificationTemplate.objects.all()
serializer_class = serializers.DefaultDataproductSpecificationTemplateSerializer
class DataproductFeedbackTemplateViewSet(viewsets.ModelViewSet):
queryset = models.DataproductFeedbackTemplate.objects.all()
serializer_class = serializers.DataproductFeedbackTemplateSerializer
class SubtaskViewSet(viewsets.ModelViewSet):
......
......@@ -78,13 +78,17 @@ router.register(r'work_request_relation_blueprint', viewsets.WorkRequestRelation
router.register(r'subtask_state_choice', viewsets.SubtaskStateChoiceViewSet)
router.register(r'subtask_type_choice', viewsets.SubtaskTypeChoiceViewSet)
router.register(r'station_type_choice', viewsets.StationTypeChoiceViewSet)
router.register(r'algorithm', viewsets.AlgorithmViewSet)
router.register(r'schedule_method', viewsets.ScheduleMethodViewSet)
# templates
router.register(r'subtask_connector', viewsets.SubtaskConnectorViewSet)
router.register(r'subtask_template', viewsets.SubtaskTemplateViewSet)
router.register(r'dataproduct_specification_template', viewsets.DataproductSpecificationTemplateViewSet)
router.register(r'dataproduct_specifications_template', viewsets.DataproductSpecificationsTemplateViewSet)
router.register(r'default_subtask_template', viewsets.DefaultSubtaskTemplateViewSet)
router.register(r'default_dataproduct_specification_template', viewsets.DefaultDataproductSpecificationTemplateViewSet)
router.register(r'default_dataproduct_specifications_template', viewsets.DefaultDataproductSpecificationsTemplateViewSet)
router.register(r'subtask_input_selection_template', viewsets.SubtaskInputSelectionTemplateViewSet)
router.register(r'dataproduct_feedback_template', viewsets.DataproductFeedbackTemplateViewSet)
# instances
router.register(r'subtask', viewsets.SubtaskViewSet)
......
......@@ -120,7 +120,7 @@ class SubtaskTemplateTestCase(unittest.TestCase):
DELETE_and_assert_gone(self, url)
class DataproductSpecificationTemplateTestCase(unittest.TestCase):
class DataproductSpecificationsTemplateTestCase(unittest.TestCase):
def setUp(self):
self.auth = HTTPBasicAuth(username=ldap_credentials.user, password=ldap_credentials.password)
......@@ -217,8 +217,8 @@ class DefaultTemplates(unittest.TestCase):
def test_default_dataproduct_specification_template_POST(self):
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_specification_template/',
DataproductSpecificationTemplateTestCase.test_data_1, 201,
DataproductSpecificationTemplateTestCase.test_data_1)
DataproductSpecificationsTemplateTestCase.test_data_1, 201,
DataproductSpecificationsTemplateTestCase.test_data_1)
url = r_dict['url']
test_data_1 = dict(self.test_data_1)
......@@ -246,8 +246,8 @@ class DefaultTemplates(unittest.TestCase):
# POST with dependency
template_url = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_specification_template/',
DataproductSpecificationTemplateTestCase.test_data_1, 201,
DataproductSpecificationTemplateTestCase.test_data_1)['url']
DataproductSpecificationsTemplateTestCase.test_data_1, 201,
DataproductSpecificationsTemplateTestCase.test_data_1)['url']
test_data = dict(self.test_data_2)
test_data['template'] = template_url
POST_and_assert_expected_response(self, BASE_URL + '/default_dataproduct_specification_template/', test_data, 201, test_data)
......@@ -257,7 +257,7 @@ class DefaultTemplates(unittest.TestCase):
response = requests.delete(template_url, auth=self.auth)
self.assertEqual(500, response.status_code)
self.assertTrue("ProtectedError" in str(response.content))
GET_and_assert_expected_response(self, template_url, 200, DataproductSpecificationTemplateTestCase.test_data_1)
GET_and_assert_expected_response(self, template_url, 200, DataproductSpecificationsTemplateTestCase.test_data_1)
......@@ -459,7 +459,7 @@ class DataproductTestCase(unittest.TestCase):
# related items
dsttc = DataproductSpecificationTemplateTestCase()
dsttc = DataproductSpecificationsTemplateTestCase()
dsttc.setUp()
self.specification_template_url = POST_and_assert_expected_response(self,
......
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