From 183dee4086e0e05d7189745b92f27644d821ce7f Mon Sep 17 00:00:00 2001 From: Flosckow <66554425+Flosckow@users.noreply.github.com> Date: Sat, 14 Sep 2024 02:16:01 +0700 Subject: [PATCH] Fix: this commit resolve #1765 (#1789) * Fix: this commit resolve #1765 * tests: refactor test --------- Co-authored-by: Daniil Dumchenko Co-authored-by: Nikita Pastukhov --- faststream/utils/path.py | 2 +- tests/brokers/nats/test_router.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/faststream/utils/path.py b/faststream/utils/path.py index 639a54ee06..c3c059bf71 100644 --- a/faststream/utils/path.py +++ b/faststream/utils/path.py @@ -11,7 +11,7 @@ def compile_path( replace_symbol: str, patch_regex: Callable[[str], str] = lambda x: x, ) -> Tuple[Optional[Pattern[str]], str]: - path_regex = "^.*" + path_regex = "^.*?" original_path = "" idx = 0 diff --git a/tests/brokers/nats/test_router.py b/tests/brokers/nats/test_router.py index d882fd881f..24b3fd772e 100644 --- a/tests/brokers/nats/test_router.py +++ b/tests/brokers/nats/test_router.py @@ -42,6 +42,30 @@ async def h( assert event.is_set() mock.assert_called_once_with(name="john", id=2) + async def test_path_as_first_with_prefix( + self, + event, + mock, + router: NatsRouter, + pub_broker, + ): + router.prefix = "root." + + @router.subscriber("{name}.nested") + async def h(name: str = Path()): + event.set() + mock(name=name) + + pub_broker._is_apply_types = True + pub_broker.include_router(router) + + await pub_broker.start() + + await pub_broker.publish("", "root.john.nested", rpc=True) + + assert event.is_set() + mock.assert_called_once_with(name="john") + async def test_router_path_with_prefix( self, event,