@second_router_one.get("endpoint_1") def router_op(request): return "second 1" second_router_two = Router() @second_router_two.get("endpoint_2") def router_op(request): return "second 2" first_router.add_router("/second", second_router_one) first_router.add_router("/second", second_router_two) api.add_router("/first", first_router) client = NinjaClient(api) @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/endpoint", 200, "global"), ("/first/endpoint", 200, "first"), ("/first/second/endpoint_1", 200, "second 1"), ("/first/second/endpoint_2", 200, "second 2"), ], )
@r1.get("/test") def operation1(request): return request.auth @r2.get("/test") def operation2(request): return request.auth @r2_1.get("/test") def operation3(request): return request.auth r2.add_router("/child", r2_1, auth=Auth("two-child")) api.add_router("/r1", r1, auth=Auth("one")) api.add_router("/r2", r2, auth=Auth("two")) client = TestClient(api) @pytest.mark.parametrize( "route, status_code", [ ("/r1/test", 401), ("/r2/test", 401), ("/r1/test?key=one", 200), ("/r2/test?key=two", 200), ("/r1/test?key=two", 401),
@second_router_one.get("endpoint_1") def router_op2(request): return "second 1" second_router_two = Router() @second_router_two.get("endpoint_2") def router_op3(request): return "second 2" first_router.add_router("/second", second_router_one, tags=["one"]) first_router.add_router("/second", second_router_two, tags=["two"]) api.add_router("/first", first_router, tags=["global"]) client = TestClient(api) @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/endpoint", 200, "global"), ("/first/endpoint", 200, "first"), ("/first/second/endpoint_1", 200, "second 1"), ("/first/second/endpoint_2", 200, "second 2"), ], )
@api.get("/endpoint") def global_op(request): return "global" @first_router.get("/endpoint") def router_op(request): return "first" @second_router.get("/endpoint") def router_op(request): return "second" first_router.add_router("/second", second_router) api.add_router("/first", first_router) client = NinjaClient(api) @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/endpoint", 200, "global"), ("/first/endpoint", 200, "first"), ("/first/second/endpoint", 200, "second"), ], ) def test_inheritance_responses(path, expected_status, expected_response): response = client.get(path)