def test_get_tree_raises_value_error_if_no_root_found(self):
     """
     Test whether custom get_tree method raises ValueError if the passed tree list
     represents a tree with no root node.
     """
     pipeline = Pipeline.objects.get(name=self.pipeline_name)
     pipeline_serializer = PipelineSerializer(pipeline)
     plugin_ds1 = Plugin.objects.get(name=self.plugin_ds_name)
     (plugin_ds2, tf) = Plugin.objects.get_or_create(name="mri_analyze", type="ds",
                                             compute_resource=self.compute_resource)
     tree_list = [{"plugin_id": plugin_ds1.id, "previous_index": 0},
             {"plugin_id": plugin_ds2.id, "previous_index": 0},
             {"plugin_id": plugin_ds1.id, "previous_index": 1}]
     with self.assertRaises(ValueError):
         pipeline_serializer.get_tree(tree_list)
Пример #2
0
    def test_get_tree_raises_value_error_if_it_finds_invalid_previous_index(
            self):
        """
        Test whether custom get_tree method raises TypeError if the passed tree list
        has a node with None as previous index for a node that is not the root.
        """
        pipeline = Pipeline.objects.get(name=self.pipeline_name)
        pipeline_serializer = PipelineSerializer(pipeline)
        plugin_ds1 = Plugin.objects.get(name=self.plugin_ds_name)
        (plugin_ds2, tf) = Plugin.objects.get_or_create(
            name="mri_analyze",
            type="ds",
            compute_resource=self.compute_resource)

        tree_list = [{
            "plugin_id": plugin_ds1.id,
            "plugin_parameter_defaults": [],
            "previous_index": None
        }, {
            "plugin_id": plugin_ds2.id,
            "plugin_parameter_defaults": [],
            "previous_index": 0
        }, {
            "plugin_id": plugin_ds1.id,
            "plugin_parameter_defaults": [],
            "previous_index": None
        }]
        with self.assertRaises(ValueError):
            pipeline_serializer.get_tree(tree_list)

        tree_list = [{
            "plugin_id": plugin_ds1.id,
            "plugin_parameter_defaults": [],
            "previous_index": None
        }, {
            "plugin_id": plugin_ds2.id,
            "plugin_parameter_defaults": [],
            "previous_index": 3
        }, {
            "plugin_id": plugin_ds1.id,
            "plugin_parameter_defaults": [],
            "previous_index": 1
        }]
        with self.assertRaises(ValueError):
            pipeline_serializer.get_tree(tree_list)
Пример #3
0
    def test_get_tree_raises_value_error_if_no_root_found(self):
        """
        Test whether custom get_tree method raises ValueError if the passed tree list
        represents a tree with no root node.
        """
        pipeline = Pipeline.objects.get(name=self.pipeline_name)
        pipeline_serializer = PipelineSerializer(pipeline)
        plugin_ds1 = Plugin.objects.get(meta__name=self.plugin_ds_name)

        (pl_meta, tf) = PluginMeta.objects.get_or_create(name='mri_analyze', type='ds')
        (plugin_ds2, tf) = Plugin.objects.get_or_create(meta=pl_meta, version='0.1')
        plugin_ds2.compute_resources.set([self.compute_resource])
        plugin_ds2.save()

        tree_list = [{"plugin_id": plugin_ds1.id, "previous_index": 0},
                {"plugin_id": plugin_ds2.id, "previous_index": 0},
                {"plugin_id": plugin_ds1.id, "previous_index": 1}]
        with self.assertRaises(ValueError):
            pipeline_serializer.get_tree(tree_list)
    def test_get_tree_raises_value_error_if_it_finds_invalid_previous_index(self):
        """
        Test whether custom get_tree method raises TypeError if the passed tree list
        has a node with None as previous index for a node that is not the root.
        """
        pipeline = Pipeline.objects.get(name=self.pipeline_name)
        pipeline_serializer = PipelineSerializer(pipeline)
        plugin_ds1 = Plugin.objects.get(name=self.plugin_ds_name)
        (plugin_ds2, tf) = Plugin.objects.get_or_create(name="mri_analyze", type="ds",
                                                compute_resource=self.compute_resource)

        tree_list = [{"plugin_id": plugin_ds1.id, "previous_index": None},
                {"plugin_id": plugin_ds2.id, "previous_index": 0},
                {"plugin_id": plugin_ds1.id, "previous_index": None}]
        with self.assertRaises(ValueError):
            pipeline_serializer.get_tree(tree_list)

        tree_list = [{"plugin_id": plugin_ds1.id, "previous_index": None},
                {"plugin_id": plugin_ds2.id, "previous_index": 3},
                {"plugin_id": plugin_ds1.id, "previous_index": 1}]
        with self.assertRaises(ValueError):
            pipeline_serializer.get_tree(tree_list)
Пример #5
0
    def test_get_tree(self):
        """
        Test whether custom get_tree method creates a proper dictionary tree from
        a tree list.
        """
        pipeline = Pipeline.objects.get(name=self.pipeline_name)
        pipeline_serializer = PipelineSerializer(pipeline)
        plugin_ds1 = Plugin.objects.get(name=self.plugin_ds_name)
        (plugin_ds2, tf) = Plugin.objects.get_or_create(
            name="mri_analyze",
            type="ds",
            compute_resource=self.compute_resource)
        tree_list = [{
            "plugin_id": plugin_ds1.id,
            "plugin_parameter_defaults": [],
            "previous_index": None
        }, {
            "plugin_id": plugin_ds2.id,
            "plugin_parameter_defaults": [],
            "previous_index": 0
        }, {
            "plugin_id": plugin_ds1.id,
            "plugin_parameter_defaults": [],
            "previous_index": 1
        }]

        tree = [{
            "plugin_id": plugin_ds1.id,
            "plugin_parameter_defaults": [],
            "child_indices": [1]
        }, {
            "plugin_id": plugin_ds2.id,
            "plugin_parameter_defaults": [],
            "child_indices": [2]
        }, {
            "plugin_id": plugin_ds1.id,
            "plugin_parameter_defaults": [],
            "child_indices": []
        }]
        expected_tree_dict = {'root_index': 0, 'tree': tree}

        tree_dict = pipeline_serializer.get_tree(tree_list)
        self.assertEqual(tree_dict, expected_tree_dict)
    def test_get_tree(self):
        """
        Test whether custom get_tree method creates a proper dictionary tree from
        a tree list.
        """
        pipeline = Pipeline.objects.get(name=self.pipeline_name)
        pipeline_serializer = PipelineSerializer(pipeline)
        plugin_ds1 = Plugin.objects.get(name=self.plugin_ds_name)
        (plugin_ds2, tf) = Plugin.objects.get_or_create(name="mri_analyze", type="ds",
                                                compute_resource=self.compute_resource)

        tree_list = [{"plugin_id": plugin_ds1.id, "previous_index": None},
                {"plugin_id": plugin_ds2.id, "previous_index": 0},
                {"plugin_id": plugin_ds1.id, "previous_index": 1}]

        tree = [{"plugin_id": plugin_ds1.id, "child_indices": [1]},
                {"plugin_id": plugin_ds2.id, "child_indices": [2]},
                {"plugin_id": plugin_ds1.id, "child_indices": []}]
        expected_tree_dict = {'root_index': 0, 'tree': tree}

        tree_dict = pipeline_serializer.get_tree(tree_list)
        self.assertEqual(tree_dict, expected_tree_dict)