@@ -301,6 +301,85 @@ async def test_path_remaining():
301
301
)
302
302
303
303
304
+ # @pytest.mark.asyncio
305
+ # async def test_url_router_nesting_by_include(root_urlconf):
306
+ # """
307
+ # Tests that nested URLRouters is constructed by include function.
308
+ # """
309
+ # import sys
310
+ # from django.urls import include
311
+
312
+ # test_app = MockApplication(return_value=1)
313
+
314
+ # # mocking the universe module following the directory structure;
315
+ # # ├── universe
316
+ # # │ └── routings.py
317
+ # # └── routings.py (parent)
318
+ # #
319
+ # #
320
+ # # in routings.py
321
+ # # ======================
322
+ # # ...
323
+ # # urlpatterns = [
324
+ # # re_path(r"book/(?P<book>[\w\-]+)/page/(?P<page>\d+)/$", test_app),
325
+ # # re_path(r"test/(\d+)/$", test_app),
326
+ # # ]
327
+ # # ======================
328
+ # module_routings = type(sys)("routings")
329
+ # module_routings.urlpatterns = [
330
+ # re_path(r"book/(?P<book>[\w\-]+)/page/(?P<page>\d+)/$", test_app),
331
+ # re_path(r"test/(\d+)/$", test_app),
332
+ # path("home/", test_app, name='home'),
333
+ # ]
334
+ # module = type(sys)("universe")
335
+ # module.routings = module_routings
336
+ # sys.modules["src"] = type(sys)("routings")
337
+ # sys.modules["src.universe"] = module
338
+ # sys.modules["src.universe.routings"] = module.routings
339
+
340
+ # # parent routings.py
341
+ # outer_router = URLRouter(
342
+ # [
343
+ # path("universe/", include("src.universe.routings"), name="universe"),
344
+ # ]
345
+ # )
346
+ # assert (
347
+ # await outer_router(
348
+ # {
349
+ # "type": "http",
350
+ # "path": "/universe/book/channels-guide/page/10/",
351
+ # },
352
+ # None,
353
+ # None,
354
+ # )
355
+ # == 1
356
+ # )
357
+
358
+ # assert (
359
+ # await outer_router(
360
+ # {
361
+ # "type": "http",
362
+ # "path": "/universe/test/10/",
363
+ # },
364
+ # None,
365
+ # None,
366
+ # )
367
+ # == 1
368
+ # )
369
+
370
+ # assert (
371
+ # await outer_router(
372
+ # {
373
+ # "type": "http",
374
+ # "path": reverse('universe:home'),
375
+ # },
376
+ # None,
377
+ # None,
378
+ # )
379
+ # == 1
380
+ # )
381
+
382
+
304
383
@pytest .mark .asyncio
305
384
async def test_url_router_nesting_by_include (root_urlconf ):
306
385
"""
@@ -341,8 +420,33 @@ async def test_url_router_nesting_by_include(root_urlconf):
341
420
outer_router = URLRouter (
342
421
[
343
422
path ("universe/" , include ("universe.routings" ), name = "universe" ),
423
+ path ("moon/" , test_app , name = "moon" ),
424
+ re_path (r"mars/(\d+)/$" , test_app , name = "mars" ),
344
425
]
345
426
)
427
+ assert (
428
+ await outer_router (
429
+ {
430
+ "type" : "http" ,
431
+ "path" : "/moon/" ,
432
+ },
433
+ None ,
434
+ None ,
435
+ )
436
+ == 1
437
+ )
438
+ assert (
439
+ await outer_router (
440
+ {
441
+ "type" : "http" ,
442
+ "path" : "/mars/5/" ,
443
+ },
444
+ None ,
445
+ None ,
446
+ )
447
+ == 1
448
+ )
449
+
346
450
assert (
347
451
await outer_router (
348
452
{
@@ -421,8 +525,32 @@ async def test_url_router_deep_nesting_by_include(root_urlconf):
421
525
outer_router = URLRouter (
422
526
[
423
527
path ("universe/" , include ("universe.routings" ), name = "universe" ),
528
+ path ("moon/" , test_app , name = "moon" ),
529
+ re_path (r"mars/(\d+)/$" , test_app , name = "mars" ),
424
530
]
425
531
)
532
+ assert (
533
+ await outer_router (
534
+ {
535
+ "type" : "http" ,
536
+ "path" : "/moon/" ,
537
+ },
538
+ None ,
539
+ None ,
540
+ )
541
+ == 1
542
+ )
543
+ assert (
544
+ await outer_router (
545
+ {
546
+ "type" : "http" ,
547
+ "path" : "/mars/5/" ,
548
+ },
549
+ None ,
550
+ None ,
551
+ )
552
+ == 1
553
+ )
426
554
assert (
427
555
await outer_router (
428
556
{
0 commit comments