def test_validate_previous_plugin_inst(self):
     """
     Test whether custom validate_previous_plugin_inst method validates that an integer
     id is provided for previous instance. Then checks that the id exists in the DB and
     that the user can run plugins within the corresponding feed.
     """
     owner = User.objects.get(username=self.username)
     plugin = Plugin.objects.get(name=self.plugin_fs_name)
     (pl_inst, tf) = PluginInstance.objects.get_or_create(
         plugin=plugin,
         owner=owner,
         compute_resource=plugin.compute_resource)
     data = {
         'title': 'PipelineInst1',
         'previous_plugin_inst_id': pl_inst.id
     }
     pipeline_inst_serializer = PipelineInstanceSerializer(data=data)
     pipeline_inst_serializer.context['request'] = mock.Mock()
     pipeline_inst_serializer.context['request'].user = owner
     with self.assertRaises(serializers.ValidationError):
         pipeline_inst_serializer.validate_previous_plugin_inst(None)
     with self.assertRaises(serializers.ValidationError):
         pipeline_inst_serializer.validate_previous_plugin_inst(pl_inst.id +
                                                                1)
     # create another user
     another_user = User.objects.create_user(username='******', password='******')
     with self.assertRaises(serializers.ValidationError):
         pipeline_inst_serializer.context['request'].user = another_user
         pipeline_inst_serializer.validate_previous_plugin_inst(pl_inst.id)
 def test_parse_parameters(self):
     """
     Test whether custom parse_parameters method properly parses the pipeline instance
     parameters in the request data dictionary.
     """
     plugin = Plugin.objects.get(meta__name=self.plugin_ds_name)
     pipeline_inst_serializer = PipelineInstanceSerializer()
     pipeline_inst_serializer.context['request'] = mock.Mock()
     # parameters name in the request have the form
     # < plugin.id > _ < piping.id > _ < previous_piping.id > _ < param.name >
     param_name = "%s_%s_%s_%s" % (plugin.id, self.pips[1].id, self.pips[0].id, 'dummy_Int')
     pipeline_inst_serializer.context['request'].data = {param_name: 1122}
     parsed_params_dict = pipeline_inst_serializer.parse_parameters()
     self.assertEqual(parsed_params_dict, {self.pips[1].id: {'dummy_Int': 1122}})
 def test_parse_parameters(self):
     """
     Test whether custom parse_parameters method properly parses the pipeline instance
     parameters in the request data dictionary.
     """
     plugin = Plugin.objects.get(name=self.plugin_ds_name)
     pipeline_inst_serializer = PipelineInstanceSerializer()
     pipeline_inst_serializer.context['request'] = mock.Mock()
     # parameters name in the request have the form
     # < plugin.id > _ < piping.id > _ < previous_piping.id > _ < param.name >
     param_name = "%s_%s_%s_%s" % (plugin.id, self.pips[1].id, self.pips[0].id, 'dummy_Int')
     pipeline_inst_serializer.context['request'].data = {param_name: 1122}
     parsed_params_dict = pipeline_inst_serializer.parse_parameters()
     self.assertEqual(parsed_params_dict, {self.pips[1].id: {'dummy_Int': 1122}})
 def test_create(self):
     """
     Test whether overriden 'create' method successfully creates a new pipeline
     instance after deleting 'previous_plugin_inst_id' from serializer data as it's
     not a model field.
     """
     owner = User.objects.get(username=self.username)
     plugin = Plugin.objects.get(name=self.plugin_fs_name)
     (pl_inst, tf) = PluginInstance.objects.get_or_create(
         plugin=plugin,
         owner=owner,
         compute_resource=plugin.compute_resource)
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     data = {
         'title': 'PipelineInst1',
         'previous_plugin_inst_id': pl_inst.id
     }
     pipeline_inst_serializer = PipelineInstanceSerializer(data=data)
     pipeline_inst_serializer.is_valid(raise_exception=True)
     pipeline_inst_serializer.validated_data['pipeline'] = pipeline
     pipeline_inst_serializer.validated_data['owner'] = owner
     pipeline_inst = pipeline_inst_serializer.create(
         pipeline_inst_serializer.validated_data)
     self.assertNotIn('previous_plugin_inst_id',
                      pipeline_inst_serializer.validated_data)
     self.assertIsInstance(pipeline_inst, PipelineInstance)
 def test_create(self):
     """
     Test whether overriden 'create' method successfully creates a new pipeline
     instance after deleting 'previous_plugin_inst_id' from serializer data as it's
     not a model field.
     """
     owner = User.objects.get(username=self.username)
     plugin = Plugin.objects.get(name=self.plugin_fs_name)
     (pl_inst, tf) = PluginInstance.objects.get_or_create(plugin=plugin, owner=owner,
                                         compute_resource=plugin.compute_resource)
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     data = {'title': 'PipelineInst1', 'previous_plugin_inst_id': pl_inst.id}
     pipeline_inst_serializer = PipelineInstanceSerializer(data=data)
     pipeline_inst_serializer.is_valid(raise_exception=True)
     pipeline_inst_serializer.validated_data['pipeline'] = pipeline
     pipeline_inst = pipeline_inst_serializer.create(pipeline_inst_serializer.validated_data)
     self.assertNotIn('previous_plugin_inst_id', pipeline_inst_serializer.validated_data)
     self.assertIsInstance(pipeline_inst, PipelineInstance)
 def test_validate_previous_plugin_inst(self):
     """
     Test whether custom validate_previous_plugin_inst method validates that an integer
     id is provided for previous instance. Then checks that the id exists in the DB and
     that the user can run plugins within the corresponding feed.
     """
     owner = User.objects.get(username=self.username)
     plugin = Plugin.objects.get(name=self.plugin_fs_name)
     (pl_inst, tf) = PluginInstance.objects.get_or_create(plugin=plugin, owner=owner,
                                         compute_resource=plugin.compute_resource)
     data = {'title': 'PipelineInst1', 'previous_plugin_inst_id': pl_inst.id}
     pipeline_inst_serializer = PipelineInstanceSerializer(data=data)
     pipeline_inst_serializer.context['request'] = mock.Mock()
     pipeline_inst_serializer.context['request'].user = owner
     with self.assertRaises(serializers.ValidationError):
         pipeline_inst_serializer.validate_previous_plugin_inst(None)
     with self.assertRaises(serializers.ValidationError):
         pipeline_inst_serializer.validate_previous_plugin_inst(pl_inst.id+1)
     # create another user
     another_user = User.objects.create_user(username='******', password='******')
     with self.assertRaises(serializers.ValidationError):
         pipeline_inst_serializer.context['request'].user = another_user
         pipeline_inst_serializer.validate_previous_plugin_inst(pl_inst.id)