Beispiel #1
0
def test_getattrd():
    assert A.B.C.d == "foo"
    assert getattrd(A, "B.C.d") == "foo"
    assert getattrd(A, "B") == B
    assert getattrd(A, "B", default=42) == B
    assert getattrd(A, "Q", default=42) == 42
    with pytest.raises(AttributeError):
        assert getattrd(A, "Q")
Beispiel #2
0
def test_getattrd():
    assert A.B.C.d == "foo"
    assert getattrd(A, "B.C.d") == "foo"
    assert getattrd(A, "B") == B
    assert getattrd(A, "B", default=42) == B
    assert getattrd(A, "Q", default=42) == 42
    with pytest.raises(AttributeError):
        assert getattrd(A, "Q")
Beispiel #3
0
    def load_config(self):
        """
        Used to dynamically load variables from the Flask application config
        into the blueprint. To tell this blueprint to pull configuration from
        the app, just set key-value pairs in the ``from_config`` dict. Keys
        are the name of the local variable to set on the blueprint object,
        and values are the variable name in the Flask application config.
        For example:

            blueprint.from_config["session.client_id"] = "GITHUB_OAUTH_CLIENT_ID"

        """
        for local_var, config_var in self.from_config.items():
            value = flask.current_app.config.get(config_var)
            if value:
                if "." in local_var:
                    # this is a dotpath -- needs special handling
                    body, tail = local_var.rsplit(".", 1)
                    obj = getattrd(self, body)
                    setattr(obj, tail, value)
                else:
                    # just use a normal setattr call
                    setattr(self, local_var, value)
Beispiel #4
0
    def load_config(self):
        """
        Used to dynamically load variables from the Flask application config
        into the blueprint. To tell this blueprint to pull configuration from
        the app, just set key-value pairs in the ``from_config`` dict. Keys
        are the name of the local variable to set on the blueprint object,
        and values are the variable name in the Flask application config.
        For example:

            blueprint.from_config["session.client_id"] = "GITHUB_OAUTH_CLIENT_ID"

        """
        for local_var, config_var in self.from_config.items():
            value = flask.current_app.config.get(config_var)
            if value:
                if "." in local_var:
                    # this is a dotpath -- needs special handling
                    body, tail = local_var.rsplit(".", 1)
                    obj = getattrd(self, body)
                    setattr(obj, tail, value)
                else:
                    # just use a normal setattr call
                    setattr(self, local_var, value)