Skip to content

Commit

Permalink
finish testing
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Haltmayer <[email protected]>
  • Loading branch information
Filip Haltmayer committed May 24, 2023
1 parent 3cf7092 commit 542e54b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
21 changes: 11 additions & 10 deletions pymilvus/orm/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def connect_milvus(**kwargs):
and connection_details["address"] == kwargs["address"]
and connection_details["user"] == kwargs["user"]
and connection_details["db_name"] == kwargs["db_name"]

):
gh = self._connected_alias[key]
break
Expand Down Expand Up @@ -267,9 +266,8 @@ def connect_milvus(**kwargs):
password = '' if password is None else str(password)
db_name = '' if db_name is None else str(db_name)

address, user, password, db_name = self.__parse_info(address, uri, host, port, db_name, user, password)

if set([address, uri, host, port]) != {None}:
if set([address, uri, host, port]) != {''}:
address, user, password, db_name = self.__parse_info(address, uri, host, port, db_name, user, password)
kwargs["address"] = address

elif alias in self._alias:
Expand Down Expand Up @@ -362,13 +360,14 @@ def __parse_info(
db_name: str = "",
user: str = "",
password: str = "",
) -> dict:
**kwargs) -> dict:

passed_in_address = ""
passed_in_user = ""
passed_in_password = ""
passed_in_db_name = ""

# If uri
if uri != "":
passed_in_address, passed_in_user, passed_in_password, passed_in_db_name = (
self.__parse_address_from_uri(uri)
Expand Down Expand Up @@ -429,11 +428,13 @@ def __parse_address_from_uri(self, uri: str) -> Tuple[str, str, str, str]:
user = parsed_uri.username if parsed_uri.username is not None else ""
password = parsed_uri.password if parsed_uri.password is not None else ""

if host != "" and port != "":
self.__verify_host_port(host, port)
addr = f"{host}:{port}"
else:
addr = ""
if host == "":
raise ConnectionConfigException(message="Illegal uri: URI is missing host address: {}".format(uri))
if port == "":
raise ConnectionConfigException(message="Illegal uri: URI is missing port: {}".format(uri))

self.__verify_host_port(host, port)
addr = f"{host}:{port}"

if not is_legal_address(addr):
raise ConnectionConfigException(message=illegal_uri_msg.format(uri))
Expand Down
3 changes: 2 additions & 1 deletion tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ def test_add_connection_address_invalid(self, invalid_addr):
{"uri": "http://127.0.0.1:19530"},
{"uri": "http://localhost:19530"},
{"uri": "http://example.com:80"},
{"uri": "http://example.com"},
])
def test_add_connection_uri(self, valid_uri):
alias = self.test_add_connection_uri.__name__
Expand All @@ -350,6 +349,8 @@ def test_add_connection_uri(self, valid_uri):
{"uri": "http://"},
{"uri": None},
{"uri": -1},
{"uri": "http://example.com"},
{"uri": "http://:90"},
])
def test_add_connection_uri_invalid(self, invalid_uri):
alias = self.test_add_connection_uri_invalid.__name__
Expand Down

0 comments on commit 542e54b

Please sign in to comment.