From 77638df5d13bfc0c22eb616243a421a3f581daa6 Mon Sep 17 00:00:00 2001 From: Mason Sedlik Date: Fri, 4 Mar 2022 17:26:52 -0800 Subject: [PATCH 1/2] Fix connected_url to return ParseResult --- nats/aio/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nats/aio/client.py b/nats/aio/client.py index 7f51a5c1..fdbd4d2e 100644 --- a/nats/aio/client.py +++ b/nats/aio/client.py @@ -985,9 +985,9 @@ async def flush(self, timeout: int = 10) -> None: raise errors.TimeoutError @property - def connected_url(self) -> Optional[str]: + def connected_url(self) -> Optional[ParseResult]: if self._current_server and self.is_connected: - return str(self._current_server.uri) + return self._current_server.uri return None @property From 66feef93b0b927ab9a52ef82445fc72076fcd7b8 Mon Sep 17 00:00:00 2001 From: Waldemar Quevedo Date: Mon, 21 Mar 2022 15:38:23 -0700 Subject: [PATCH 2/2] Add test to fix connected_url type Signed-off-by: Waldemar Quevedo --- tests/test_client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 416b070b..5455f05a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -4,6 +4,7 @@ import ssl import time import unittest +import urllib from unittest import mock import pytest @@ -37,6 +38,7 @@ def test_default_connect_command(self): expected = f'CONNECT {{"echo": true, "lang": "python3", "pedantic": false, "protocol": 1, "verbose": false, "version": "{__version__}"}}\r\n' self.assertEqual(expected.encode(), got) + def test_default_connect_command_with_name(self): nc = NATS() nc.options["verbose"] = False @@ -53,8 +55,7 @@ class ClientTest(SingleServerTestCase): @async_test async def test_default_connect(self): - nc = NATS() - await nc.connect() + nc = await nats.connect() self.assertIn('server_id', nc._server_info) self.assertIn('client_id', nc._server_info) self.assertIn('max_payload', nc._server_info) @@ -62,7 +63,10 @@ async def test_default_connect(self): self.assertTrue(nc.max_payload > 0) self.assertTrue(nc.is_connected) self.assertTrue(nc.client_id > 0) + self.assertEqual(type(nc.connected_url), urllib.parse.ParseResult) await nc.close() + + self.assertEqual(nc.connected_url, None) self.assertTrue(nc.is_closed) self.assertFalse(nc.is_connected)