Ejemplo n.º 1
0
    def test_must_register_two_workflows(self):
        class TestWorkflow1(BaseWorkflow):
            NAME = "TestWorkflow"
            CAPABILITY = self.CAPABILITY1

        class TestWorkflow2(BaseWorkflow):
            NAME = "TestWorkflow2"
            CAPABILITY = self.CAPABILITY2

        self.assertEquals(len(DEFAULT_REGISTRY), 2)
        self.assertEquals(get_workflow(self.CAPABILITY1), TestWorkflow1)
        self.assertEquals(get_workflow(self.CAPABILITY2), TestWorkflow2)
Ejemplo n.º 2
0
    def __init__(self, language, dependency_manager, application_framework, supported_workflows=None):

        """
        Initialize the builder.
        :type supported_workflows: list
        :param supported_workflows:
            Optional list of workflow modules that should be loaded. By default we load all the workflows bundled
            with this library. This property is primarily used for testing. But in future it could be used to
            dynamically load user defined workflows.

            If set to None, we will load the default workflow modules.
            If set to empty list, we will **not** load any modules. Pass an empty list if the workflows
            were already loaded by the time this class is instantiated.

        :raises lambda_builders.exceptions.WorkflowNotFoundError: If a workflow for given capabilities is not found
        """

        # Load defaults if necessary. We check for `None` explicitly because callers could pass an empty list
        # if they do not want to load any modules. This supports the case where workflows are already loaded and
        # don't need to be loaded again.
        self.supported_workflows = _SUPPORTED_WORKFLOWS if supported_workflows is None else supported_workflows

        for workflow_module in self.supported_workflows:
            LOG.debug("Loading workflow module '%s'", workflow_module)

            # If a module is already loaded, this call is pretty much a no-op. So it is okay to keep loading again.
            importlib.import_module(workflow_module)

        self.capability = Capability(
            language=language, dependency_manager=dependency_manager, application_framework=application_framework
        )
        self.selected_workflow_cls = get_workflow(self.capability)
        LOG.debug("Found workflow '%s' to support capabilities '%s'", self.selected_workflow_cls.NAME, self.capability)
Ejemplo n.º 3
0
    def test_must_register_one_workflow(self):

        # Just loading the classes will register them to default registry
        class TestWorkflow(BaseWorkflow):
            NAME = "TestWorkflow"
            CAPABILITY = self.CAPABILITY1

        result_cls = get_workflow(self.CAPABILITY1)
        self.assertEquals(len(DEFAULT_REGISTRY), 1)
        self.assertEquals(result_cls, TestWorkflow)
Ejemplo n.º 4
0
    def test_must_raise_if_workflow_not_found(self):

        # Don't register any workflow, and try querying

        with self.assertRaises(WorkflowNotFoundError):
            get_workflow(self.capability)
Ejemplo n.º 5
0
    def test_must_get_workflow_from_default_registry(self):
        DEFAULT_REGISTRY[self.capability] = self.workflow_data

        result = get_workflow(self.capability)
        self.assertEquals(result, self.workflow_data)
Ejemplo n.º 6
0
    def test_must_get_workflow_from_custom_registry(self):
        # register a workflow
        self.registry[self.capability] = self.workflow_data

        result = get_workflow(self.capability, registry=self.registry)
        self.assertEquals(result, self.workflow_data)