Esempio n. 1
0
def create_object_graph(name,
                        debug=False,
                        testing=False,
                        import_name=None,
                        root_path=None,
                        loader=load_from_environ,
                        registry=_registry):
    """
    Create a new object graph.

    :param name: the name of the microservice
    :param debug: is development debugging enabled?
    :param testing: is unit testing enabled?
    :param loader: the configuration loader to use
    :param registry: the registry to use (defaults to the global)
    """
    metadata = Metadata(
        name=name,
        debug=debug,
        testing=testing,
        import_name=import_name,
        root_path=root_path,
    )

    config = Configuration({
        key: get_defaults(value)
        for key, value in registry.all.items()
    })
    config.merge(loader(metadata))

    return ObjectGraph(
        metadata=metadata,
        config=config,
        registry=registry,
    )
Esempio n. 2
0
def create_object_graph(name,
                        debug=False,
                        testing=False,
                        import_name=None,
                        root_path=None,
                        loader=load_from_environ,
                        registry=_registry):
    """
    Create a new object graph.

    :param name: the name of the microservice
    :param debug: is development debugging enabled?
    :param testing: is unit testing enabled?
    :param loader: the configuration loader to use
    :param registry: the registry to use (defaults to the global)
    """
    metadata = Metadata(
        name=name,
        debug=debug,
        testing=testing,
        import_name=import_name,
        root_path=root_path,
    )

    config = Configuration(
        {key: get_defaults(value)
         for key, value in registry.all.items()})
    config.merge(loader(metadata))

    return ObjectGraph(
        metadata=metadata,
        config=config,
        registry=registry,
    )
Esempio n. 3
0
def test_defaults_not_set():
    """
    Defaults default to an empty dict.

    """
    def func(*args, **kwargs):
        pass

    assert_that(get_defaults(func), is_(equal_to(dict())))
Esempio n. 4
0
def test_defaults():
    """
    Defaults can be set and retrieved.

    """
    @defaults(foo="bar")
    def func(*args, **kwargs):
        pass

    assert_that(get_defaults(func), is_(equal_to(dict(foo="bar"))))