Home / Class/ TestUrlFor Class — flask Architecture

TestUrlFor Class — flask Architecture

Architecture documentation for the TestUrlFor class in test_helpers.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  1e08bdec_29d2_c29b_db96_904133a45034["TestUrlFor"]
  3a099be0_ce36_e4ca_abd6_9bb88317cf79["MethodView"]
  1e08bdec_29d2_c29b_db96_904133a45034 -->|extends| 3a099be0_ce36_e4ca_abd6_9bb88317cf79
  d5d22f74_a243_4ea9_9dfe_aaec71d26288["test_helpers.py"]
  1e08bdec_29d2_c29b_db96_904133a45034 -->|defined in| d5d22f74_a243_4ea9_9dfe_aaec71d26288
  8604ed5f_abcf_22d1_ffe6_b2cf0b834fff["test_url_for_with_anchor()"]
  1e08bdec_29d2_c29b_db96_904133a45034 -->|method| 8604ed5f_abcf_22d1_ffe6_b2cf0b834fff
  fc25b9ac_3f71_17cc_8b71_6e6f55781a9e["test_url_for_with_scheme()"]
  1e08bdec_29d2_c29b_db96_904133a45034 -->|method| fc25b9ac_3f71_17cc_8b71_6e6f55781a9e
  f1309072_8970_db5c_cd41_5ab7d60d5768["test_url_for_with_scheme_not_external()"]
  1e08bdec_29d2_c29b_db96_904133a45034 -->|method| f1309072_8970_db5c_cd41_5ab7d60d5768
  02107695_44aa_1f59_7825_8058247fc59d["test_url_for_with_alternating_schemes()"]
  1e08bdec_29d2_c29b_db96_904133a45034 -->|method| 02107695_44aa_1f59_7825_8058247fc59d
  642e1903_0685_b7bb_46eb_1c6b0959abbb["test_url_with_method()"]
  1e08bdec_29d2_c29b_db96_904133a45034 -->|method| 642e1903_0685_b7bb_46eb_1c6b0959abbb
  a3678a4e_8dad_0f3e_34d2_743066ad6728["test_url_for_with_self()"]
  1e08bdec_29d2_c29b_db96_904133a45034 -->|method| a3678a4e_8dad_0f3e_34d2_743066ad6728

Relationship Graph

Source Code

tests/test_helpers.py lines 102–169

class TestUrlFor:
    def test_url_for_with_anchor(self, app, req_ctx):
        @app.route("/")
        def index():
            return "42"

        assert flask.url_for("index", _anchor="x y") == "/#x%20y"

    def test_url_for_with_scheme(self, app, req_ctx):
        @app.route("/")
        def index():
            return "42"

        assert (
            flask.url_for("index", _external=True, _scheme="https")
            == "https://localhost/"
        )

    def test_url_for_with_scheme_not_external(self, app, req_ctx):
        app.add_url_rule("/", endpoint="index")

        # Implicit external with scheme.
        url = flask.url_for("index", _scheme="https")
        assert url == "https://localhost/"

        # Error when external=False with scheme
        with pytest.raises(ValueError):
            flask.url_for("index", _scheme="https", _external=False)

    def test_url_for_with_alternating_schemes(self, app, req_ctx):
        @app.route("/")
        def index():
            return "42"

        assert flask.url_for("index", _external=True) == "http://localhost/"
        assert (
            flask.url_for("index", _external=True, _scheme="https")
            == "https://localhost/"
        )
        assert flask.url_for("index", _external=True) == "http://localhost/"

    def test_url_with_method(self, app, req_ctx):
        from flask.views import MethodView

        class MyView(MethodView):
            def get(self, id=None):
                if id is None:
                    return "List"
                return f"Get {id:d}"

            def post(self):
                return "Create"

        myview = MyView.as_view("myview")
        app.add_url_rule("/myview/", methods=["GET"], view_func=myview)
        app.add_url_rule("/myview/<int:id>", methods=["GET"], view_func=myview)
        app.add_url_rule("/myview/create", methods=["POST"], view_func=myview)

        assert flask.url_for("myview", _method="GET") == "/myview/"
        assert flask.url_for("myview", id=42, _method="GET") == "/myview/42"
        assert flask.url_for("myview", _method="POST") == "/myview/create"

    def test_url_for_with_self(self, app, req_ctx):
        @app.route("/<self>")
        def index(self):
            return "42"

        assert flask.url_for("index", self="2") == "/2"

Extends

Frequently Asked Questions

What is the TestUrlFor class?
TestUrlFor is a class in the flask codebase, defined in tests/test_helpers.py.
Where is TestUrlFor defined?
TestUrlFor is defined in tests/test_helpers.py at line 102.
What does TestUrlFor extend?
TestUrlFor extends MethodView.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free