def test_validate_plugin_id_tree_raises_validation_error_if_validate_tree_raises_value_error(
         self):
     """
     Test whether overriden validate_plugin_id_tree method raises ValidationError if
     internal call to validate_tree method raises ValueError exception.
     """
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     pipeline_serializer = PipelineSerializer(pipeline)
     plugin_ds = Plugin.objects.get(name=self.plugin_ds_name)
     tree = '[{"plugin_id": ' + str(
         plugin_ds.id) + ', "previous_index": null}]'
     tree_dict = {
         'root_index': 0,
         'tree': [{
             "plugin_id": plugin_ds.id,
             "child_indices": []
         }]
     }
     with mock.patch(
             'pipelines.serializers.PipelineSerializer.validate_tree'
     ) as validate_tree_mock:
         validate_tree_mock.side_effect = ValueError
         with self.assertRaises(serializers.ValidationError):
             pipeline_serializer.validate_plugin_id_tree(tree)
             validate_tree_mock.assert_called_with(tree_dict)
 def test_validate_plugin_id_tree_does_not_contain_empty_list(self):
     """
     Test whether overriden validate_plugin_id_tree method validates that the plugin
     tree is not an empty list.
     """
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     pipeline_serializer = PipelineSerializer(pipeline)
     tree = '[]'
     with self.assertRaises(serializers.ValidationError):
         pipeline_serializer.validate_plugin_id_tree(tree)
 def test_validate_plugin_id_tree_is_json_string(self):
     """
     Test whether overriden validate_plugin_id_tree method validates that the plugin
     tree string is a proper JSON string.
     """
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     pipeline_serializer = PipelineSerializer(pipeline)
     tree = '[{plugin_id: 8, "previous_index": null}]'
     with self.assertRaises(serializers.ValidationError):
         pipeline_serializer.validate_plugin_id_tree(tree)
 def test_validate_plugin_id_tree_does_not_contain_empty_list(self):
     """
     Test whether overriden validate_plugin_id_tree method validates that the plugin
     tree is not an empty list.
     """
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     pipeline_serializer = PipelineSerializer(pipeline)
     tree = '[]'
     with self.assertRaises(serializers.ValidationError):
         pipeline_serializer.validate_plugin_id_tree(tree)
 def test_validate_plugin_id_tree_is_json_string(self):
     """
     Test whether overriden validate_plugin_id_tree method validates that the plugin
     tree string is a proper JSON string.
     """
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     pipeline_serializer = PipelineSerializer(pipeline)
     tree = '[{plugin_id: 8, "previous_index": null}]'
     with self.assertRaises(serializers.ValidationError):
         pipeline_serializer.validate_plugin_id_tree(tree)
 def test_validate_plugin_id_tree_plugins_exist_and_not_fs(self):
     """
     Test whether overriden validate_plugin_id_tree method validates that the plugin
     tree contains existing plugins that are not of type 'fs'.
     """
     plugin_fs = Plugin.objects.get(name=self.plugin_fs_name)
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     pipeline_serializer = PipelineSerializer(pipeline)
     tree = '[{"plugin_id": ' + str(plugin_fs.id + 100) + ', "previous_index": null}]'
     with self.assertRaises(serializers.ValidationError):
         pipeline_serializer.validate_plugin_id_tree(tree)
     tree = '[{"plugin_id": ' + str(plugin_fs.id) + ', "previous_index": null}]'
     with self.assertRaises(serializers.ValidationError):
         pipeline_serializer.validate_plugin_id_tree(tree)
 def test_validate_plugin_id_tree_raises_validation_error_if_validate_tree_raises_value_error(self):
     """
     Test whether overriden validate_plugin_id_tree method raises ValidationError if
     internal call to validate_tree method raises ValueError exception.
     """
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     pipeline_serializer = PipelineSerializer(pipeline)
     plugin_ds = Plugin.objects.get(name=self.plugin_ds_name)
     tree = '[{"plugin_id": ' + str(plugin_ds.id) + ', "previous_index": null}]'
     tree_dict = {'root_index': 0, 'tree': [{"plugin_id": plugin_ds.id, "child_indices": []}]}
     with mock.patch('pipelines.serializers.PipelineSerializer.validate_tree') as validate_tree_mock:
         validate_tree_mock.side_effect = ValueError
         with self.assertRaises(serializers.ValidationError):
             pipeline_serializer.validate_plugin_id_tree(tree)
             validate_tree_mock.assert_called_with(tree_dict)
 def test_validate_plugin_id_tree_plugins_exist_and_not_fs(self):
     """
     Test whether overriden validate_plugin_id_tree method validates that the plugin
     tree contains existing plugins that are not of type 'fs'.
     """
     plugin_fs = Plugin.objects.get(name=self.plugin_fs_name)
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     pipeline_serializer = PipelineSerializer(pipeline)
     tree = '[{"plugin_id": ' + str(plugin_fs.id +
                                    100) + ', "previous_index": null}]'
     with self.assertRaises(serializers.ValidationError):
         pipeline_serializer.validate_plugin_id_tree(tree)
     tree = '[{"plugin_id": ' + str(
         plugin_fs.id) + ', "previous_index": null}]'
     with self.assertRaises(serializers.ValidationError):
         pipeline_serializer.validate_plugin_id_tree(tree)