diff --git a/.gitattributes b/.gitattributes index dc6dd6fb42558630973be619dd73500eaebc2879..27dfb3738524b158d852e9d4e3d805b45e7945f5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4245,8 +4245,8 @@ 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_20180711_1300.py -text -SAS/LSMR/src/lsmr/lsmrapp/migrations/0003_auto_20180711_1300.py -text +SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20180712_0931.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 SAS/LSMR/src/lsmr/lsmrapp/models/CMakeLists.txt -text diff --git a/SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20180711_1300.py b/SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20180712_0931.py similarity index 67% rename from SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20180711_1300.py rename to SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20180712_0931.py index 3dd9d751ddf3f9f6ebe92c9f4db95dc17109f742..2ffd18001c1a51245d245878042c3cd75f2230b0 100644 --- a/SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20180711_1300.py +++ b/SAS/LSMR/src/lsmr/lsmrapp/migrations/0002_auto_20180712_0931.py @@ -1,7 +1,8 @@ -# Generated by Django 2.0.7 on 2018-07-11 13:00 +# Generated by Django 2.0.6 on 2018-07-12 09:31 import django.contrib.postgres.fields import django.contrib.postgres.fields.jsonb +import django.contrib.postgres.indexes from django.db import migrations, models import django.db.models.deletion @@ -29,8 +30,8 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=30)), ('start', models.DateTimeField()), ], @@ -56,16 +57,67 @@ class Migration(migrations.Migration): 'abstract': False, }, ), + migrations.CreateModel( + name='DefaultGeneratorTemplate', + 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)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=30, unique=True)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='DefaultRunTemplate', + 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)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=30, unique=True)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='DefaultWorkRelationSelectionTemplate', + 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)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=30, unique=True)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='DefaultWorkRequestTemplate', + 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)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=30, unique=True)), + ], + options={ + 'abstract': False, + }, + ), migrations.CreateModel( name='GeneratorTemplate', 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=30)), ('description', models.CharField(max_length=255)), - ('default_version', models.BooleanField()), ('version', models.CharField(max_length=30)), ('schema', django.contrib.postgres.fields.jsonb.JSONField()), ('create_func', models.CharField(max_length=30)), @@ -79,8 +131,8 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=30)), ('priority', models.IntegerField(default=0)), ('can_trigger', models.BooleanField(default=False)), @@ -96,14 +148,17 @@ class Migration(migrations.Migration): fields=[ ('value', models.CharField(editable=False, max_length=30, primary_key=True, serialize=False, unique=True)), ], + options={ + 'abstract': False, + }, ), migrations.CreateModel( name='Run', 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('requirements_doc', django.contrib.postgres.fields.jsonb.JSONField()), ('do_cancel', models.BooleanField()), ], @@ -116,8 +171,8 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=30)), ('requirements_doc', django.contrib.postgres.fields.jsonb.JSONField()), ('generator_param', models.CharField(max_length=200)), @@ -133,8 +188,8 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=30)), ('generator_parameters_doc', django.contrib.postgres.fields.jsonb.JSONField()), ('generator_template', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='lsmrapp.GeneratorTemplate')), @@ -149,11 +204,10 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=30)), ('description', models.CharField(max_length=255)), - ('default_version', models.BooleanField()), ('version', models.CharField(max_length=30)), ('schema', django.contrib.postgres.fields.jsonb.JSONField()), ], @@ -170,7 +224,7 @@ class Migration(migrations.Migration): ], ), migrations.CreateModel( - name='WorkIORoles', + name='WorkIORole', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('dataformat', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lsmrapp.DataformatChoice')), @@ -182,11 +236,10 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=30)), ('description', models.CharField(max_length=255)), - ('default_version', models.BooleanField()), ('version', models.CharField(max_length=30)), ('schema', django.contrib.postgres.fields.jsonb.JSONField()), ], @@ -199,8 +252,8 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('requirements_doc', django.contrib.postgres.fields.jsonb.JSONField()), ('do_cancel', models.BooleanField()), ], @@ -213,8 +266,8 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=30)), ('requirements_doc', django.contrib.postgres.fields.jsonb.JSONField()), ('copies', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='copied_from', to='lsmrapp.WorkRequestBlueprint')), @@ -229,8 +282,8 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('selection_doc', django.contrib.postgres.fields.jsonb.JSONField()), ], options={ @@ -242,16 +295,16 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=30)), ('selection_doc', django.contrib.postgres.fields.jsonb.JSONField()), ('blueprint', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lsmrapp.WorkRelationSelectionTemplate')), - ('consumer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='work_request_relation_blueprint_consumer', to='lsmrapp.WorkRequestBlueprint')), + ('consumer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='consumed_by', to='lsmrapp.WorkRequestBlueprint')), ('dataformat', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lsmrapp.DataformatChoice')), - ('input_role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='work_request_relation_blueprint_input_role', to='lsmrapp.WorkIORoles')), - ('output_role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='work_request_relation_blueprint_output_role', to='lsmrapp.WorkIORoles')), - ('producer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='work_request_relation_blueprint_producer', to='lsmrapp.WorkRequestBlueprint')), + ('input_role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='inputs_work_request_relation_blueprint', to='lsmrapp.WorkIORole')), + ('output_role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='outputs_work_request_relation_blueprint', to='lsmrapp.WorkIORole')), + ('producer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='produced_by', to='lsmrapp.WorkRequestBlueprint')), ], options={ 'abstract': False, @@ -262,11 +315,10 @@ class Migration(migrations.Migration): 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)), - ('creation', models.DateTimeField(auto_now_add=True)), - ('update', models.DateTimeField(auto_now=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=30)), ('description', models.CharField(max_length=255)), - ('default_version', models.BooleanField()), ('version', models.CharField(max_length=30)), ('schema', django.contrib.postgres.fields.jsonb.JSONField()), ('validation_code_js', models.CharField(max_length=30)), @@ -283,7 +335,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='workrequestrelation', name='consumer', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='work_request_relation_consumer', to='lsmrapp.WorkRequest'), + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='consumed_by', to='lsmrapp.WorkRequest'), ), migrations.AddField( model_name='workrequestrelation', @@ -293,17 +345,17 @@ class Migration(migrations.Migration): migrations.AddField( model_name='workrequestrelation', name='input_role', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='work_request_relation_input_role', to='lsmrapp.WorkIORoles'), + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='inputs_work_request_relation', to='lsmrapp.WorkIORole'), ), migrations.AddField( model_name='workrequestrelation', name='output_role', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='work_request_relation_output_role', to='lsmrapp.WorkIORoles'), + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='outputs_work_request_relation', to='lsmrapp.WorkIORole'), ), migrations.AddField( model_name='workrequestrelation', name='producer', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='work_request_relation_producer', to='lsmrapp.WorkRequest'), + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='produced_by', to='lsmrapp.WorkRequest'), ), migrations.AddField( model_name='workrequest', @@ -316,17 +368,17 @@ class Migration(migrations.Migration): field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='lsmrapp.WorkRequestTemplate'), ), migrations.AddField( - model_name='workioroles', + model_name='workiorole', name='inputs', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='role_input', to='lsmrapp.WorkRequestTemplate'), ), migrations.AddField( - model_name='workioroles', + model_name='workiorole', name='outputs', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='role_output', to='lsmrapp.WorkRequestTemplate'), ), migrations.AddField( - model_name='workioroles', + model_name='workiorole', name='role', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lsmrapp.RoleChoice'), ), @@ -350,4 +402,40 @@ class Migration(migrations.Migration): name='template', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='lsmrapp.RunTemplate'), ), + migrations.AddField( + model_name='defaultworkrequesttemplate', + name='template', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lsmrapp.WorkRequestTemplate'), + ), + migrations.AddField( + model_name='defaultworkrelationselectiontemplate', + name='template', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lsmrapp.WorkRelationSelectionTemplate'), + ), + migrations.AddField( + model_name='defaultruntemplate', + name='template', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lsmrapp.RunTemplate'), + ), + migrations.AddField( + model_name='defaultgeneratortemplate', + name='template', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lsmrapp.GeneratorTemplate'), + ), + migrations.AddIndex( + model_name='defaultworkrequesttemplate', + index=django.contrib.postgres.indexes.GinIndex(fields=['tags'], name='lsmrapp_def_tags_2e8945_gin'), + ), + migrations.AddIndex( + model_name='defaultworkrelationselectiontemplate', + index=django.contrib.postgres.indexes.GinIndex(fields=['tags'], name='lsmrapp_def_tags_eef600_gin'), + ), + migrations.AddIndex( + model_name='defaultruntemplate', + index=django.contrib.postgres.indexes.GinIndex(fields=['tags'], name='lsmrapp_def_tags_8d5d48_gin'), + ), + migrations.AddIndex( + model_name='defaultgeneratortemplate', + index=django.contrib.postgres.indexes.GinIndex(fields=['tags'], name='lsmrapp_def_tags_2b9ef8_gin'), + ), ] diff --git a/SAS/LSMR/src/lsmr/lsmrapp/migrations/0003_auto_20180711_1300.py b/SAS/LSMR/src/lsmr/lsmrapp/migrations/0003_populate.py similarity index 66% rename from SAS/LSMR/src/lsmr/lsmrapp/migrations/0003_auto_20180711_1300.py rename to SAS/LSMR/src/lsmr/lsmrapp/migrations/0003_populate.py index 2d3f33ebba51cae9c42bb8de370efadaaec6caae..f3b9c594eddb4f5d354b3d1733933f9a303d2d80 100644 --- a/SAS/LSMR/src/lsmr/lsmrapp/migrations/0003_auto_20180711_1300.py +++ b/SAS/LSMR/src/lsmr/lsmrapp/migrations/0003_populate.py @@ -1,5 +1,3 @@ -# Generated by Django 2.0.7 on 2018-07-11 13:00 - from django.db import migrations from ..populate import * @@ -7,7 +5,8 @@ from ..populate import * class Migration(migrations.Migration): dependencies = [ - ('lsmrapp', '0002_auto_20180711_1300'), + ('lsmrapp', '0002_auto_20180712_0931'), ] operations = [ migrations.RunPython(populate_choices) ] + diff --git a/SAS/LSMR/src/lsmr/lsmrapp/models/specification.py b/SAS/LSMR/src/lsmr/lsmrapp/models/specification.py index 933b8c8dc5d4b0da16d03b96b68524a5bd186f6f..b326b5fa5b7e0449f4dcd44bbb15f736aa218bf5 100644 --- a/SAS/LSMR/src/lsmr/lsmrapp/models/specification.py +++ b/SAS/LSMR/src/lsmr/lsmrapp/models/specification.py @@ -2,7 +2,7 @@ This file contains the database models """ -from django.db.models import Model, CharField, DateTimeField, BooleanField, ForeignKey, CASCADE, IntegerField, SET_NULL +from django.db.models import Model, CharField, DateTimeField, BooleanField, ForeignKey, CASCADE, IntegerField, SET_NULL, PROTECT from django.contrib.postgres.fields import ArrayField, JSONField from django.contrib.postgres.indexes import GinIndex from enum import Enum @@ -18,8 +18,8 @@ class BasicCommon(Model): # todo: we cannot use foreign keys in the array here, so we have to keep the Tags table up to date by trigger or so. # todo: we could switch to a manytomany field instead? tags = ArrayField(CharField(max_length=30), size=8, blank=True) - creation = DateTimeField(auto_now_add=True) - update = DateTimeField(auto_now=True) + created_at = DateTimeField(auto_now_add=True) + updated_at = DateTimeField(auto_now=True) class Meta: abstract = True @@ -82,7 +82,7 @@ class AbstractChoice(Model): class RoleChoice(AbstractChoice): - """Defines the model and predefined list of possible RoleChoice's for WorkIORoles. + """Defines the model and predefined list of possible RoleChoice's for WorkIORole. The items in the Choises class below are automagically populated into the database via a data migration.""" class Choices(Enum): CORRELATOR = "correlator" @@ -94,7 +94,7 @@ class RoleChoice(AbstractChoice): class DatatypeChoice(AbstractChoice): - """Defines the model and predefined list of possible DatatypeChoice's for WorkIORoles. + """Defines the model and predefined list of possible DatatypeChoice's for WorkIORole. The items in the Choises class below are automagically populated into the database via a data migration.""" class Choices(Enum): VISIBILITIES = "visibilities" @@ -120,7 +120,7 @@ class CopyReasonChoice(AbstractChoice): # concrete models -class WorkIORoles(Model): +class WorkIORole(Model): role = ForeignKey('RoleChoice', null=False, on_delete=CASCADE) datatype = ForeignKey('DatatypeChoice', null=False, on_delete=CASCADE) dataformat = ForeignKey('DataformatChoice', null=False, on_delete=CASCADE) # todo: <--- this needs to be an array of dataformats! @@ -136,13 +136,14 @@ class WorkIORoles(Model): class Template(SystemDefinedCommon): name = CharField(max_length=30) # todo: check if this should go in SystemDefinedCommon or BasicCommon description = CharField(max_length=255) # todo: check if this should go in SystemDefinedCommon or BasicCommon - default_version = BooleanField() version = CharField(max_length=30) schema = JSONField() + def __str__(self): + return self.name + class Meta: abstract = True - #unique_together = ("name", "default_version") # todo: We only want this for default_version=True, find a way to do so # concrete models @@ -151,24 +152,42 @@ class GeneratorTemplate(Template): create_func = CharField(max_length=30) +class DefaultGeneratorTemplate(BasicCommon): + name = CharField(max_length=30, unique=True) + template = ForeignKey("GeneratorTemplate", on_delete=PROTECT) + + class RunTemplate(Template): pass +class DefaultRunTemplate(BasicCommon): + name = CharField(max_length=30, unique=True) + template = ForeignKey("RunTemplate", on_delete=PROTECT) + + class WorkRequestTemplate(Template): validation_code_js = CharField(max_length=30) +class DefaultWorkRequestTemplate(BasicCommon): + name = CharField(max_length=30, unique=True) + template = ForeignKey("WorkRequestTemplate", on_delete=PROTECT) + + class WorkRelationSelectionTemplate(Template): pass + +class DefaultWorkRelationSelectionTemplate(BasicCommon): + name = CharField(max_length=30, unique=True) + template = ForeignKey("WorkRelationSelectionTemplate", on_delete=PROTECT) + + # # Instance Objects # -# todo: the blue stuff -# run / work request / work request relation -> SystemDefinedCommon -# others -> UserDefinedCommon class Cycle(UserDefinedCommon): start = DateTimeField() @@ -218,19 +237,19 @@ class WorkRequest(SystemDefinedCommon): class WorkRequestRelationBlueprint(UserDefinedCommon): selection_doc = JSONField() dataformat = ForeignKey('DataformatChoice', null=False, on_delete=CASCADE) - producer = ForeignKey(WorkRequestBlueprint, related_name='work_request_relation_blueprint_producer', on_delete=CASCADE) - consumer = ForeignKey(WorkRequestBlueprint, related_name='work_request_relation_blueprint_consumer', on_delete=CASCADE) - input_role = ForeignKey(WorkIORoles, related_name='work_request_relation_blueprint_input_role', on_delete=CASCADE) - output_role = ForeignKey(WorkIORoles, related_name='work_request_relation_blueprint_output_role', on_delete=CASCADE) + producer = ForeignKey(WorkRequestBlueprint, related_name='produced_by', on_delete=CASCADE) + consumer = ForeignKey(WorkRequestBlueprint, related_name='consumed_by', on_delete=CASCADE) + input_role = ForeignKey(WorkIORole, related_name='inputs_work_request_relation_blueprint', on_delete=CASCADE) + output_role = ForeignKey(WorkIORole, related_name='outputs_work_request_relation_blueprint', on_delete=CASCADE) blueprint = ForeignKey(WorkRelationSelectionTemplate, on_delete=CASCADE) # todo: This differs from the diagram, where there is a One(Blueprint)-to-Many(Template) reference, but I expect that the diagram is not correct class WorkRequestRelation(SystemDefinedCommon): selection_doc = JSONField() dataformat = ForeignKey('DataformatChoice', null=False, on_delete=CASCADE) - producer = ForeignKey(WorkRequest, related_name='work_request_relation_producer', on_delete=CASCADE) - consumer = ForeignKey(WorkRequest, related_name='work_request_relation_consumer', on_delete=CASCADE) - input_role = ForeignKey(WorkIORoles, related_name='work_request_relation_input_role', on_delete=CASCADE) - output_role = ForeignKey(WorkIORoles, related_name='work_request_relation_output_role', on_delete=CASCADE) + producer = ForeignKey(WorkRequest, related_name='produced_by', on_delete=CASCADE) + consumer = ForeignKey(WorkRequest, related_name='consumed_by', on_delete=CASCADE) + input_role = ForeignKey(WorkIORole, related_name='inputs_work_request_relation', on_delete=CASCADE) + output_role = ForeignKey(WorkIORole, related_name='outputs_work_request_relation', on_delete=CASCADE) blueprint = ForeignKey(WorkRequestRelationBlueprint, on_delete=CASCADE) diff --git a/SAS/LSMR/src/lsmr/lsmrapp/serializers/specification.py b/SAS/LSMR/src/lsmr/lsmrapp/serializers/specification.py index 121d18ba60ed3f73db6fc627da4e004bcd2a2ec3..d2c016f7366a179f26813690bf5b31fe0b6486fe 100644 --- a/SAS/LSMR/src/lsmr/lsmrapp/serializers/specification.py +++ b/SAS/LSMR/src/lsmr/lsmrapp/serializers/specification.py @@ -18,24 +18,48 @@ class GeneratorTemplateSerializer(serializers.HyperlinkedModelSerializer): fields = '__all__' +class DefaultGeneratorTemplateSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = models.DefaultGeneratorTemplate + fields = '__all__' + + class RunTemplateSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = models.RunTemplate fields = '__all__' +class DefaultRunTemplateSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = models.DefaultRunTemplate + fields = '__all__' + + class WorkRequestTemplateSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = models.WorkRequestTemplate fields = '__all__' +class DefaultWorkRequestTemplateSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = models.DefaultWorkRequestTemplate + fields = '__all__' + + class WorkRelationSelectionTemplateSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = models.WorkRelationSelectionTemplate fields = '__all__' +class DefaultWorkRelationSelectionTemplateSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = models.DefaultWorkRelationSelectionTemplate + fields = '__all__' + + class RoleChoiceSerializer(serializers.ModelSerializer): class Meta: model = models.RoleChoice @@ -60,9 +84,9 @@ class CopyReasonChoiceSerializer(serializers.ModelSerializer): fields = '__all__' -class WorkIORolesSerializer(serializers.HyperlinkedModelSerializer): +class WorkIORoleSerializer(serializers.HyperlinkedModelSerializer): class Meta: - model = models.WorkIORoles + model = models.WorkIORole fields = '__all__' diff --git a/SAS/LSMR/src/lsmr/lsmrapp/viewsets/specification.py b/SAS/LSMR/src/lsmr/lsmrapp/viewsets/specification.py index 2099ea0618757783c4db8f02542015755d7f74da..ef0c7390e15fe4533b21ebe5fb226e735fca1cbf 100644 --- a/SAS/LSMR/src/lsmr/lsmrapp/viewsets/specification.py +++ b/SAS/LSMR/src/lsmr/lsmrapp/viewsets/specification.py @@ -16,21 +16,41 @@ class GeneratorTemplateViewSet(viewsets.ModelViewSet): serializer_class = serializers.GeneratorTemplateSerializer +class DefaultGeneratorTemplateViewSet(viewsets.ModelViewSet): + queryset = models.DefaultGeneratorTemplate.objects.all() + serializer_class = serializers.DefaultGeneratorTemplateSerializer + + class RunTemplateViewSet(viewsets.ModelViewSet): queryset = models.RunTemplate.objects.all() serializer_class = serializers.RunTemplateSerializer +class DefaultRunTemplateViewSet(viewsets.ModelViewSet): + queryset = models.DefaultRunTemplate.objects.all() + serializer_class = serializers.DefaultRunTemplateSerializer + + class WorkRequestTemplateViewSet(viewsets.ModelViewSet): queryset = models.WorkRequestTemplate.objects.all() serializer_class = serializers.WorkRequestTemplateSerializer +class DefaultWorkRequestTemplateViewSet(viewsets.ModelViewSet): + queryset = models.DefaultWorkRequestTemplate.objects.all() + serializer_class = serializers.DefaultWorkRequestTemplateSerializer + + class WorkRelationSelectionTemplateViewSet(viewsets.ModelViewSet): queryset = models.WorkRelationSelectionTemplate.objects.all() serializer_class = serializers.WorkRelationSelectionTemplateSerializer +class DefaultWorkRelationSelectionTemplateViewSet(viewsets.ModelViewSet): + queryset = models.DefaultWorkRelationSelectionTemplate.objects.all() + serializer_class = serializers.DefaultWorkRelationSelectionTemplateSerializer + + class RoleChoiceViewSet(viewsets.ModelViewSet): queryset = models.RoleChoice.objects.all() serializer_class = serializers.RoleChoiceSerializer @@ -51,9 +71,9 @@ class CopyReasonChoiceViewSet(viewsets.ModelViewSet): serializer_class = serializers.CopyReasonChoiceSerializer -class WorkIORolesViewSet(viewsets.ModelViewSet): - queryset = models.WorkIORoles.objects.all() - serializer_class = serializers.WorkIORolesSerializer +class WorkIORoleViewSet(viewsets.ModelViewSet): + queryset = models.WorkIORole.objects.all() + serializer_class = serializers.WorkIORoleSerializer class CycleViewSet(viewsets.ModelViewSet): diff --git a/SAS/LSMR/src/lsmr/urls.py b/SAS/LSMR/src/lsmr/urls.py index 61b5d5c81e9755255ef97d56bc2927987eb2580e..e435cb9b6e129a8084ae38e080c75b8b5577ea0d 100644 --- a/SAS/LSMR/src/lsmr/urls.py +++ b/SAS/LSMR/src/lsmr/urls.py @@ -47,7 +47,11 @@ router.register(r'role_choice', viewsets.RoleChoiceViewSet) router.register(r'datatype_choice', viewsets.DatatypeChoiceViewSet) router.register(r'dataformat_choice', viewsets.DataformatChoiceViewSet) router.register(r'copy_reason_choice', viewsets.CopyReasonChoiceViewSet) -router.register(r'work_io_roles', viewsets.WorkIORolesViewSet) +router.register(r'work_io_role', viewsets.WorkIORoleViewSet) +router.register(r'default_generator_template', viewsets.DefaultGeneratorTemplateViewSet) +router.register(r'default_run_template', viewsets.DefaultRunTemplateViewSet) +router.register(r'default_work_request_template', viewsets.DefaultWorkRequestTemplateViewSet) +router.register(r'default_work_relation_selection_template', viewsets.DefaultWorkRelationSelectionTemplateViewSet) # instances router.register(r'cycle', viewsets.CycleViewSet) diff --git a/SAS/LSMR/test/t_functional.py b/SAS/LSMR/test/t_functional.py index a0c5806d4d0a9751a4300038bd8311fcc735e737..20da82d6cf436d2ebdf6b5107a35134d16816e2d 100755 --- a/SAS/LSMR/test/t_functional.py +++ b/SAS/LSMR/test/t_functional.py @@ -53,7 +53,7 @@ def _call_API_and_assert_expected_response(self, url, call, data, expected_code, else: raise ValueError("The provided call '%s' is not a valid API method choice" % call) - if response.status_code is not expected_code: + if response.status_code != expected_code: print("[%s] - %s %s: %s" % (self.id(), call, url, response.content)) self.assertEqual(response.status_code, expected_code) r_dict = json.loads(response.content.decode('utf-8')) @@ -102,12 +102,12 @@ def DELETE_and_assert_gone(self, url): :return: url for new item """ response = requests.delete(url) - if response.status_code is not 204: + if response.status_code != 204: print("[%s] - %s %s: %s" % (self.id(), 'DELETE', url, response.content)) self.assertEqual(response.status_code, 204) response = requests.get(url) - if response.status_code is not 404: + if response.status_code != 404: print("[%s] - %s %s: %s" % (self.id(), 'GET', url, response.content)) self.assertEqual(response.status_code, 404) @@ -124,7 +124,6 @@ class GeneratorTemplateTestCase(unittest.TestCase): test_data_1 = {"name": "observation", "description": 'My one observation', - "default_version": False, "version": 'v0.314159265359', "schema": {"mykey": "my value"}, "create_func": 'Funky', @@ -132,7 +131,6 @@ class GeneratorTemplateTestCase(unittest.TestCase): test_data_2 = {"name": "observation", "description": 'My other observation', - "default_version": False, "version": 'v3.14159265359', "schema": {"mykey": "my other value"}, "create_func": 'Trousers', @@ -199,14 +197,12 @@ class RunTemplateTestCase(unittest.TestCase): test_data_1 = {"name": "observation", "description": 'My one observation', - "default_version": False, "version": 'v0.314159265359', "schema": {"mykey": "my value"}, "tags": ["LSMR", "TESTING"]} test_data_2 = {"name": "observation", "description": 'My other observation', - "default_version": False, "version": 'v3.14159265359', "schema": {"mykey": "my other value"}, "tags": []} @@ -272,7 +268,6 @@ class WorkRequestTemplateTestCase(unittest.TestCase): test_data_1 = {"name": "observation", "description": 'My one observation', - "default_version": False, "version": 'v0.314159265359', "schema": {"mykey": "my value"}, "tags": ["LSMR", "TESTING"], @@ -280,7 +275,6 @@ class WorkRequestTemplateTestCase(unittest.TestCase): test_data_2 = {"name": "observation", "description": 'My one observation', - "default_version": False, "version": 'v3.14159265359', "schema": {"mykey": "my other value"}, "tags": [], @@ -348,14 +342,12 @@ class WorkRelationSelectionTemplateTestCase(unittest.TestCase): # test data test_data_1 = {"name": "observation", "description": 'My one observation', - "default_version": False, "version": 'v0.314159265359', "schema": {"mykey": "my value"}, "tags": ["LSMR", "TESTING"]} test_data_2 = {"name": "observation", "description": 'My other observation', - "default_version": False, "version": 'v3.14159265359', "schema": {"mykey": "my other value"}, "tags": []} @@ -417,7 +409,7 @@ class WorkRelationSelectionTemplateTestCase(unittest.TestCase): DELETE_and_assert_gone(self, url) -class WorkIORolesTestCase(unittest.TestCase): +class WorkIORoleTestCase(unittest.TestCase): # test data test_data_1 = {"role": BASE_URL + '/role_choice/correlator/', @@ -438,53 +430,53 @@ class WorkIORolesTestCase(unittest.TestCase): "dataformat": BASE_URL + '/dataformat_choice/MeasurementSet/' } - def test_work_io_roles_list_apiformat(self): - r = requests.get(BASE_URL + '/work_io_roles/?format=api') + def test_work_io_role_list_apiformat(self): + r = requests.get(BASE_URL + '/work_io_role/?format=api') self.assertEqual(r.status_code, 200) - self.assertTrue("Work Io Roles List" in r.content.decode('utf8')) + self.assertTrue("Work Io Role List" in r.content.decode('utf8')) - def test_work_io_roles_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/work_io_roles/1234321/', 404, {}) + def test_work_io_role_GET_nonexistant_raises_error(self): + GET_and_assert_expected_response(self, BASE_URL + '/work_io_role/1234321/', 404, {}) - def test_work_io_roles_POST_and_GET(self): + def test_work_io_role_POST_and_GET(self): # POST and GET a new item and assert correctness - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', self.test_data_1, 201, self.test_data_1) + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', self.test_data_1, 201, self.test_data_1) url = r_dict['url'] GET_and_assert_expected_response(self, url, 200, self.test_data_1) - def test_work_io_roles_POST_invalid_role_raises_error(self): + def test_work_io_role_POST_invalid_role_raises_error(self): # POST a new item with invalid choice test_data_invalid_role = dict(self.test_data_1) test_data_invalid_role['role'] = BASE_URL + '/role_choice/forbidden/' - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid_role, 400, {}) + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', test_data_invalid_role, 400, {}) self.assertTrue('Invalid hyperlink' in str(r_dict['role'])) - def test_work_io_roles_POST_invalid_datatype_raises_error(self): + def test_work_io_role_POST_invalid_datatype_raises_error(self): # POST a new item with invalid choice test_data_invalid = dict(self.test_data_1) test_data_invalid['datatype'] = BASE_URL + '/datatype_choice/forbidden/' - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid, 400, {}) + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', test_data_invalid, 400, {}) self.assertTrue('Invalid hyperlink' in str(r_dict['datatype'])) - def test_work_io_roles_POST_invalid_dataformat_raises_error(self): + def test_work_io_role_POST_invalid_dataformat_raises_error(self): # POST a new item with invalid choice test_data_invalid = dict(self.test_data_1) test_data_invalid['dataformat'] = BASE_URL + '/dataformat_choice/forbidden/' - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid, 400, {}) + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', test_data_invalid, 400, {}) self.assertTrue('Invalid hyperlink' in str(r_dict['dataformat'])) - def test_work_io_roles_POST_nonexistant_inputs_raises_error(self): + def test_work_io_role_POST_nonexistant_inputs_raises_error(self): # POST a new item with wrong reference test_data_invalid = dict(self.test_data_1) test_data_invalid['inputs'] = BASE_URL + "/work_request_template/6353748/" - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid, 400, {}) + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', test_data_invalid, 400, {}) self.assertTrue('Invalid hyperlink' in str(r_dict['inputs'])) - def test_work_io_roles_POST_existing_inputs_works(self): + def test_work_io_role_POST_existing_inputs_works(self): # First POST a new item to reference r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_request_template/', WorkRequestTemplateTestCase.test_data_1, 201, WorkRequestTemplateTestCase.test_data_1,) @@ -493,17 +485,17 @@ class WorkIORolesTestCase(unittest.TestCase): # POST a new item with correct reference test_data_valid = dict(self.test_data_1) test_data_valid['inputs'] = url - POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_valid, 201, test_data_valid) + POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', test_data_valid, 201, test_data_valid) - def test_work_io_roles_POST_nonexistant_outputs_raises_error(self): + def test_work_io_role_POST_nonexistant_outputs_raises_error(self): # POST a new item with wrong reference test_data_invalid = dict(self.test_data_1) test_data_invalid['outputs'] = BASE_URL + "/work_request_template/6353748/" - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid, 400, {}) + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', test_data_invalid, 400, {}) self.assertTrue('Invalid hyperlink' in str(r_dict['outputs'])) - def test_work_io_roles_POST_existing_outputs_works(self): + def test_work_io_role_POST_existing_outputs_works(self): # First POST a new item to reference r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_request_template/', WorkRequestTemplateTestCase.test_data_1, 201, WorkRequestTemplateTestCase.test_data_1) @@ -512,14 +504,14 @@ class WorkIORolesTestCase(unittest.TestCase): # POST a new item with correct reference test_data_valid = dict(self.test_data_1) test_data_valid['outputs'] = url - POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_valid, 201, test_data_valid) + POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', test_data_valid, 201, test_data_valid) - def test_work_io_roles_PUT_nonexistant_raises_error(self): - PUT_and_assert_expected_response(self, BASE_URL + '/work_io_roles/9876789876/', self.test_data_1, 404, {}) + def test_work_io_role_PUT_nonexistant_raises_error(self): + PUT_and_assert_expected_response(self, BASE_URL + '/work_io_role/9876789876/', self.test_data_1, 404, {}) - def test_work_io_roles_PUT(self): + def test_work_io_role_PUT(self): # POST new item, verify - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', self.test_data_1, 201, self.test_data_1) + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', self.test_data_1, 201, self.test_data_1) url = r_dict['url'] GET_and_assert_expected_response(self, url, 200, self.test_data_1) @@ -527,9 +519,9 @@ class WorkIORolesTestCase(unittest.TestCase): PUT_and_assert_expected_response(self, url, self.test_data_2, 200, self.test_data_2) GET_and_assert_expected_response(self, url, 200, self.test_data_2) - def test_work_io_roles_PATCH(self): + def test_work_io_role_PATCH(self): # POST new item, verify - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', self.test_data_1, 201, self.test_data_1) + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', self.test_data_1, 201, self.test_data_1) url = r_dict['url'] GET_and_assert_expected_response(self, url, 200, self.test_data_1) @@ -539,9 +531,9 @@ class WorkIORolesTestCase(unittest.TestCase): expected_data.update(self.test_patch) GET_and_assert_expected_response(self, url, 200, expected_data) - def test_work_io_roles_DELETE(self): + def test_work_io_role_DELETE(self): # POST new item, verify - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', self.test_data_1, 201, self.test_data_1) + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_role/', self.test_data_1, 201, self.test_data_1) url = r_dict['url'] GET_and_assert_expected_response(self, url, 200, self.test_data_1) @@ -549,6 +541,54 @@ class WorkIORolesTestCase(unittest.TestCase): DELETE_and_assert_gone(self, url) +class DefaultTemplates(unittest.TestCase): + + test_data_1 = {"name": "unique_name", + "template": None, + "tags": []} + + def test_default_generator_template_POST(self): + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/generator_template/', + GeneratorTemplateTestCase.test_data_1, 201, + GeneratorTemplateTestCase.test_data_1) + url = r_dict['url'] + + test_data_1 = dict(self.test_data_1) + test_data_1['template'] = url + POST_and_assert_expected_response(self, BASE_URL + '/default_generator_template/', test_data_1, 201, test_data_1) + + def test_default_run_template_POST(self): + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/run_template/', + RunTemplateTestCase.test_data_1, 201, + RunTemplateTestCase.test_data_1) + url = r_dict['url'] + + test_data_1 = dict(self.test_data_1) + test_data_1['template'] = url + POST_and_assert_expected_response(self, BASE_URL + '/default_run_template/', test_data_1, 201, test_data_1) + + def test_default_work_request_template_POST(self): + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_request_template/', + WorkRequestTemplateTestCase.test_data_1, 201, + WorkRequestTemplateTestCase.test_data_1) + url = r_dict['url'] + + test_data_1 = dict(self.test_data_1) + test_data_1['template'] = url + POST_and_assert_expected_response(self, BASE_URL + '/default_work_request_template/', test_data_1, 201, test_data_1) + + + def test_default_work_relation_selection_template_POST(self): + r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/', + WorkRelationSelectionTemplateTestCase.test_data_1, 201, + WorkRelationSelectionTemplateTestCase.test_data_1) + url = r_dict['url'] + + test_data_1 = dict(self.test_data_1) + test_data_1['template'] = url + POST_and_assert_expected_response(self, BASE_URL + '/default_work_relation_selection_template/', test_data_1, 201, test_data_1) + + if __name__ == "__main__": unittest.main() diff --git a/SAS/LSMR/test/t_lsmrapp_models.py b/SAS/LSMR/test/t_lsmrapp_models.py index f29f619c98dccafa089db3d905633e8c478f1a10..86eccbcce49396542a0d1894b4d0f316adc55110 100755 --- a/SAS/LSMR/test/t_lsmrapp_models.py +++ b/SAS/LSMR/test/t_lsmrapp_models.py @@ -37,7 +37,6 @@ class GeneratorTemplateTest(rest_framework.test.APITransactionTestCase): # test data test_data_1 = {"name": "observation", "description": 'My one observation', - "default_version": False, "version": 'v0.314159265359', "schema": {"mykey": "my value"}, "create_func": 'Funky', @@ -45,7 +44,6 @@ class GeneratorTemplateTest(rest_framework.test.APITransactionTestCase): test_data_2 = {"name": "observation", "description": 'My other observation', - "default_version": False, "version": 'v3.14159265359', "schema": {"mykey": "my other value"}, "create_func": 'Trousers', @@ -64,8 +62,8 @@ class GeneratorTemplateTest(rest_framework.test.APITransactionTestCase): after = timezone.now() # assert - self.assertLess(before, entry.creation) - self.assertGreater(after, entry.creation) + self.assertLess(before, entry.created_at) + self.assertGreater(after, entry.created_at) def test_GeneratorTemplate_update_timestamp_gets_changed_correctly(self): @@ -77,8 +75,8 @@ class GeneratorTemplateTest(rest_framework.test.APITransactionTestCase): after = timezone.now() # assert - self.assertLess(before, entry.update) - self.assertGreater(after, entry.update) + self.assertLess(before, entry.updated_at) + self.assertGreater(after, entry.updated_at) def test_GET_GeneratorTemplate_list_view_shows_entry(self): @@ -130,14 +128,12 @@ class RunTemplateTest(rest_framework.test.APITransactionTestCase): # test data test_data_1 = {"name": "observation", "description": 'My one observation', - "default_version": False, "version": 'v0.314159265359', "schema": {"mykey": "my value"}, "tags": ["LSMR", "TESTING"]} test_data_2 = {"name": "observation", "description": 'My other observation', - "default_version": False, "version": 'v3.14159265359', "schema": {"mykey": "my other value"}, "tags": []} @@ -155,8 +151,8 @@ class RunTemplateTest(rest_framework.test.APITransactionTestCase): after = timezone.now() # assert - self.assertLess(before, entry.creation) - self.assertGreater(after, entry.creation) + self.assertLess(before, entry.created_at) + self.assertGreater(after, entry.created_at) def test_RunTemplate_update_timestamp_gets_changed_correctly(self): @@ -168,8 +164,8 @@ class RunTemplateTest(rest_framework.test.APITransactionTestCase): after = timezone.now() # assert - self.assertLess(before, entry.update) - self.assertGreater(after, entry.update) + self.assertLess(before, entry.updated_at) + self.assertGreater(after, entry.updated_at) def test_GET_RunTemplate_list_view_shows_entry(self): @@ -209,7 +205,6 @@ class WorkRequestTemplateTest(rest_framework.test.APITransactionTestCase): #"outputs": "", "name": "observation", "description": 'My one observation', - "default_version": False, "version": 'v0.314159265359', "schema": {"mykey": "my value"}, "tags": ["LSMR", "TESTING"]} @@ -219,7 +214,6 @@ class WorkRequestTemplateTest(rest_framework.test.APITransactionTestCase): #"outputs": "", "name": "observation", "description": 'My other observation', - "default_version": False, "version": 'v3.14159265359', "schema": {"mykey": "my other value"}, "tags": []} @@ -237,8 +231,8 @@ class WorkRequestTemplateTest(rest_framework.test.APITransactionTestCase): after = timezone.now() # assert - self.assertLess(before, entry.creation) - self.assertGreater(after, entry.creation) + self.assertLess(before, entry.created_at) + self.assertGreater(after, entry.created_at) def test_WorkRequestTemplate_update_timestamp_gets_changed_correctly(self): @@ -250,8 +244,8 @@ class WorkRequestTemplateTest(rest_framework.test.APITransactionTestCase): after = timezone.now() # assert - self.assertLess(before, entry.update) - self.assertGreater(after, entry.update) + self.assertLess(before, entry.updated_at) + self.assertGreater(after, entry.updated_at) def test_GET_WorkRequestTemplate_list_view_shows_entry(self): @@ -289,14 +283,12 @@ class WorkRelationSelectionTemplateTest(rest_framework.test.APITransactionTestCa # test data test_data_1 = {"name": "observation", "description": 'My one observation', - "default_version": False, "version": 'v0.314159265359', "schema": {"mykey": "my value"}, "tags": ["LSMR", "TESTING"]} test_data_2 = {"name": "observation", "description": 'My other observation', - "default_version": False, "version": 'v3.14159265359', "schema": {"mykey": "my other value"}, "tags": []} @@ -314,8 +306,8 @@ class WorkRelationSelectionTemplateTest(rest_framework.test.APITransactionTestCa after = timezone.now() # assert - self.assertLess(before, entry.creation) - self.assertGreater(after, entry.creation) + self.assertLess(before, entry.created_at) + self.assertGreater(after, entry.created_at) def test_WorkRelationSelectionTemplate_update_timestamp_gets_changed_correctly(self): @@ -327,8 +319,8 @@ class WorkRelationSelectionTemplateTest(rest_framework.test.APITransactionTestCa after = timezone.now() # assert - self.assertLess(before, entry.update) - self.assertGreater(after, entry.update) + self.assertLess(before, entry.updated_at) + self.assertGreater(after, entry.updated_at) def test_GET_WorkRelationSelectionTemplate_list_view_shows_entry(self): @@ -358,7 +350,7 @@ class WorkRelationSelectionTemplateTest(rest_framework.test.APITransactionTestCa self.assertIn(item, response2.data.items()) -class WorkIORolesTest(rest_framework.test.APITransactionTestCase): +class WorkIORoleTest(rest_framework.test.APITransactionTestCase): reset_sequences = True @@ -389,63 +381,35 @@ class WorkIORolesTest(rest_framework.test.APITransactionTestCase): else: self.assertEqual(v, data[k]) - def test_GET_WorkIORoles_list_view_shows_entry(self): + def test_GET_WorkIORole_list_view_shows_entry(self): # setup - models.WorkIORoles.objects.create(**self.test_data_1) + models.WorkIORole.objects.create(**self.test_data_1) # assert - response = client.get('/work_io_roles/', format='json', follow=True) + response = client.get('/work_io_role/', format='json', follow=True) self.assertEqual(response.status_code, 200) self.assertDataWithUrls(response.data[0], self.test_data_1) - def test_GET_WorkIORoles_view_returns_correct_entry(self): + def test_GET_WorkIORole_view_returns_correct_entry(self): # setup - id1 = models.WorkIORoles.objects.create(**self.test_data_1).id - id2 = models.WorkIORoles.objects.create(**self.test_data_2).id + id1 = models.WorkIORole.objects.create(**self.test_data_1).id + id2 = models.WorkIORole.objects.create(**self.test_data_2).id # assert - response1 = client.get('/work_io_roles/%s/' % id1, format='json', follow=True) - response2 = client.get('/work_io_roles/%s/' % id2, format='json', follow=True) + response1 = client.get('/work_io_role/%s/' % id1, format='json', follow=True) + response2 = client.get('/work_io_role/%s/' % id2, format='json', follow=True) self.assertEqual(response1.status_code, 200) self.assertEqual(response2.status_code, 200) self.assertDataWithUrls(response1.data, self.test_data_1) self.assertDataWithUrls(response2.data, self.test_data_2) - @unittest.skip("Database does not enforce choices currently") - def test_WorkIORoles_prevents_invalid_role(self): - # setup - test_data_invalidrole = dict(self.test_data_1) - test_data_invalidrole['role'] = 'forbidden' - - with self.assertRaises(TypeError): - models.WorkIORoles.objects.create(**test_data_invalidrole) - - - @unittest.skip("Database does not enforce choices currently") - def test_WorkIORoles_prevents_invalid_datatype(self): - # setup - test_data_invalidrole = dict(self.test_data_1) - test_data_invalidrole['datatype'] = 'forbidden' - - with self.assertRaises(TypeError): - models.WorkIORoles.objects.create(**test_data_invalidrole) - - @unittest.skip("Database does not enforce choices currently") - def test_WorkIORoles_prevents_invalid_dataformat(self): - # setup - test_data_invalidrole = dict(self.test_data_1) - test_data_invalidrole['dataformat'] = ['HDF5', 'forbidden'] - - with self.assertRaises(TypeError): - models.WorkIORoles.objects.create(**test_data_invalidrole) - - # todo: def test_WorkIORoles_prevents_missing_inputs(self): + # todo: def test_WorkIORole_prevents_missing_inputs(self): - # todo: def test_WorkIORoles_prevents_missing_outputs(self): + # todo: def test_WorkIORole_prevents_missing_outputs(self): - # todo: def test_WorkIORoles_allows_existing_inputs_and_outputs(self): + # todo: def test_WorkIORole_allows_existing_inputs_and_outputs(self): # todo: Tags? -> Decide how to deal with them first.