Exemplo n.º 1
0
def create_app(debug=False, testing=False, model_only=False):
    config_loader = load_each(load_from_environ, )

    graph = create_object_graph(
        name=__name__.split(".")[0],
        debug=debug,
        testing=testing,
        loader=config_loader,
    )

    graph.use(
        "sessionmaker",
        "postgres",
        "pizza_store",
        "postgres_async",
        "session_manager",
        # Conventions
        "documentation_convention",
        "build_info_convention",
        "health_convention",
        "config_convention",
        "landing_convention",
    )

    if not model_only:
        graph.use("pizza_route")

    return graph.lock()
Exemplo n.º 2
0
    def loader(self):
        """
        Define the object graph config loader.

        """
        return load_each(
            load_from_dict(self.defaults),
            load_from_environ,
        )
Exemplo n.º 3
0
    def loader(self):
        """
        Define the object graph config loader.

        """
        return load_each(
            load_from_dict(self.defaults),
            load_from_environ,
        )
Exemplo n.º 4
0
def create_app(debug=False, testing=False, model_only=False):
    """
    Create the object graph for the application.

    """
    config_loader = load_each(
        load_default_config, load_from_environ, load_from_json_file,
    )
    partitioned_loader = load_config_and_secrets(
        config=config_loader, secrets=load_from_secretsmanager(),
    )

    graph = create_object_graph(
        name=__name__.split(".")[0],
        debug=debug,
        testing=testing,
        loader=partitioned_loader,
    )

    graph.use(
        "pizza_store",
        "order_store",
        "order_event_store",
        "topping_store",
        "logging",
        "postgres",
        "sessionmaker",
        "session_factory",
    )

    if not model_only:
        graph.use(
            "sns_producer",
            # Factories
            "order_event_factory",
            # conventions
            "build_info_convention",
            "config_convention",
            "discovery_convention",
            "health_convention",
            "landing_convention",
            "port_forwarding",
            "postgres_health_check",
            "swagger_convention",
            # routes
            "pizza_routes",
            "order_routes",
            "topping_routes",
            "order_event_routes",
        )

    return graph.lock()
Exemplo n.º 5
0
    def create_for_testing(cls, loader=None, **kwargs):
        mock_config = load_from_dict(sns_producer=dict(mock_sns=False, ), )

        if loader is None:
            loader = mock_config
        else:
            loader = load_each(loader, mock_config)

        return super().create_for_testing(sqs_queue_url="queue",
                                          loader=loader,
                                          envelope=None,
                                          stdin=False,
                                          **kwargs)
Exemplo n.º 6
0
def test_load_each():
    """
    Return the merged union of two loaders.

    """
    metadata = Metadata("foo")
    with configfile(dumps(dict(foo="bar"))) as configfile_:
        with envvar("FOO_SETTINGS", configfile_.name):
            with envvar("FOO_BAR", "baz"):
                loader = load_each(load_from_json_file, load_from_environ)
                config = loader(metadata)
    assert_that(config, is_(equal_to({
        "bar": "baz",
        "foo": "bar",
        "settings": configfile_.name
    })))
Exemplo n.º 7
0
def create_app(testing=False):
    config_loader = load_each(load_from_environ, )
    graph = create_object_graph(
        "bplc",
        testing=testing,
        loader=config_loader,
    )

    graph.use(
        "discord_client",
        "activity_extractor",
        "activity_transformer",
    )

    graph.lock()
    return graph
Exemplo n.º 8
0
    def create_object_graph(self, args, cache=None, loader=None):
        """
        Create (and lock) the object graph.

        """
        graph = create_object_graph(
            name=self.name,
            debug=args.debug,
            testing=args.testing,
            import_name=self.import_name,
            root_path=self.root_path,
            cache=cache,
            loader=load_each(loader, self.loader) if loader else self.loader,
        )
        self.create_object_graph_components(graph)
        graph.lock()
        return graph
Exemplo n.º 9
0
    def create_object_graph(self, args, cache=None, loader=None):
        """
        Create (and lock) the object graph.

        """
        graph = create_object_graph(
            name=self.name,
            debug=args.debug,
            testing=args.testing,
            import_name=self.import_name,
            root_path=self.root_path,
            cache=cache,
            loader=load_each(loader, self.loader) if loader else self.loader,
        )
        self.create_object_graph_components(graph)
        graph.lock()
        return graph
Exemplo n.º 10
0
    def create_for_testing(cls, loader=None, **kwargs):
        mock_config = load_from_dict(
            sns_producer=dict(
                mock_sns=False,
            ),
        )

        if loader is None:
            loader = mock_config
        else:
            loader = load_each(loader, mock_config)

        return super().create_for_testing(
            sqs_queue_url="queue",
            loader=loader,
            envelope=None,
            stdin=False,
            **kwargs
        )
Exemplo n.º 11
0
    def create_for_testing(cls, loader=None, cache=None, **kwargs):
        mock_config = load_from_dict(sns_producer=dict(mock_sns=False, ), )

        if loader is None:
            loader = mock_config
        else:
            loader = load_each(loader, mock_config)

        if cache is None:
            scope = cls.__name__
            cache = ProcessCache(scope=scope)
        # To test SQS readers we pass event here
        daemon = cls(event=kwargs.get('event', {}))
        daemon.args = Namespace(debug=False,
                                testing=True,
                                sqs_queue_url="queue",
                                loader=loader,
                                envelope=None,
                                stdin=False,
                                **kwargs)
        daemon.graph = daemon.create_object_graph(daemon.args,
                                                  cache=cache,
                                                  loader=loader)
        return daemon
Exemplo n.º 12
0
 def loader(self):
     return load_each(
         load_from_dict(self.defaults),
         load_from_environ,
         load_from_json_file,
     )