예제 #1
0
    def test_read_graph_happy_path(self):
        workflow = Workflow.objects.create()
        tab1 = workflow.tabs.create(position=0, slug="tab-1")
        tab2 = workflow.tabs.create(position=1, slug="tab-2")

        ModuleVersion.create_or_replace_from_spec(
            {
                "id_name": "simple",
                "name": "Simple",
                "category": "Add data",
                "parameters": [{"id_name": "str", "type": "string"}],
            }
        )

        ModuleVersion.create_or_replace_from_spec(
            {
                "id_name": "tabby",
                "name": "Tabby",
                "category": "Add data",
                "parameters": [{"id_name": "tab", "type": "tab"}],
            }
        )

        wfm1 = tab1.wf_modules.create(
            order=0, slug="step-1", module_id_name="simple", params={"str": "A"}
        )
        wfm2 = tab1.wf_modules.create(
            order=1, slug="step-2", module_id_name="tabby", params={"tab": "tab-2"}
        )
        wfm3 = tab2.wf_modules.create(
            order=0, slug="step-3", module_id_name="simple", params={"str": "B"}
        )

        graph = DependencyGraph.load_from_workflow(workflow)
        self.assertEqual(
            graph.tabs,
            [
                DependencyGraph.Tab("tab-1", [wfm1.id, wfm2.id]),
                DependencyGraph.Tab("tab-2", [wfm3.id]),
            ],
        )
        self.assertEqual(
            graph.steps,
            {
                wfm1.id: DependencyGraph.Step(set()),
                wfm2.id: DependencyGraph.Step(set(["tab-2"])),
                wfm3.id: DependencyGraph.Step(set()),
            },
        )
예제 #2
0
    def test_read_graph_happy_path(self, load_module):
        workflow = Workflow.objects.create()
        tab1 = workflow.tabs.create(position=0, slug='tab-1')
        tab2 = workflow.tabs.create(position=1, slug='tab-2')

        ModuleVersion.create_or_replace_from_spec({
            'id_name':
            'simple',
            'name':
            'Simple',
            'category':
            'Add data',
            'parameters': [{
                'id_name': 'str',
                'type': 'string'
            }]
        })

        ModuleVersion.create_or_replace_from_spec({
            'id_name':
            'tabby',
            'name':
            'Tabby',
            'category':
            'Add data',
            'parameters': [{
                'id_name': 'tab',
                'type': 'tab'
            }]
        })

        wfm1 = tab1.wf_modules.create(order=0,
                                      module_id_name='simple',
                                      params={'str': 'A'})
        wfm2 = tab1.wf_modules.create(order=1,
                                      module_id_name='tabby',
                                      params={'tab': 'tab-2'})
        wfm3 = tab2.wf_modules.create(order=0,
                                      module_id_name='simple',
                                      params={'str': 'B'})

        # DependencyGraph.load_from_workflow needs to call migrate_params() so
        # it can check for tab values. That means it needs to load the 'tabby'
        # module.
        class MockLoadedModule:
            def migrate_params(self, schema, values):
                return values

        load_module.return_value = MockLoadedModule()

        graph = DependencyGraph.load_from_workflow(workflow)
        self.assertEqual(graph.tabs, [
            DependencyGraph.Tab('tab-1', [wfm1.id, wfm2.id]),
            DependencyGraph.Tab('tab-2', [wfm3.id]),
        ])
        self.assertEqual(
            graph.steps, {
                wfm1.id: DependencyGraph.Step(set()),
                wfm2.id: DependencyGraph.Step(set(['tab-2'])),
                wfm3.id: DependencyGraph.Step(set()),
            })