Skip to content

Commit

Permalink
Fix database cases (#26174)
Browse files Browse the repository at this point in the history
Signed-off-by: ThreadDao <yufen.zong@zilliz.com>
  • Loading branch information
ThreadDao authored Aug 9, 2023
1 parent fb5d809 commit a888606
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions tests/python_client/testcases/test_database.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from base.client_base import TestcaseBase
from base.collection_wrapper import ApiCollectionWrapper
from common.common_type import CheckTasks, CaseLabel
from common import common_func as cf
from common import common_type as ct
Expand All @@ -19,6 +18,7 @@ def teardown_method(self, method):
teardown method: drop collection and db
"""
log.info("[database_teardown_method] Start teardown database test cases ...")
self._connect()

# clear db
for db in self.database_wrap.list_database()[0]:
Expand All @@ -28,9 +28,7 @@ def teardown_method(self, method):
# drop db collections
colls, _ = self.utility_wrap.list_collections()
for coll in colls:
cw = ApiCollectionWrapper()
cw.init_collection(coll)
cw.drop()
self.utility_wrap.drop_collection(coll)

# drop db
if db != ct.default_db:
Expand Down Expand Up @@ -182,7 +180,7 @@ def test_list_db_with_invalid_timeout(self, timeout):
# list db with not existed using
self.database_wrap.list_database(timeout=timeout, check_task=CheckTasks.err_res,
check_items={ct.err_code: 1,
ct.err_msg: "rpc deadline exceeded: Retry timeout"})
ct.err_msg: "StatusCode.DEADLINE_EXCEEDED"})

@pytest.mark.parametrize("invalid_db_name", [(), [], 1, [1, "2", 3], (1,), {1: 1}])
def test_using_invalid_db(self, invalid_db_name):
Expand All @@ -206,9 +204,9 @@ def test_using_invalid_db(self, invalid_db_name):
assert collection_w.name in collections

@pytest.mark.parametrize("invalid_db_name", ["12-s", "12 s", "(mn)", "中文", "%$#"])
def test_using_invalid_db_2(self, host, port, invalid_db_name):
def test_using_invalid_db_2(self, invalid_db_name):
# connect with default alias using
self.connection_wrap.connect(host=host, port=port, user=ct.default_user, password=ct.default_password)
self._connect()

# create collection in default db
collection_w = self.init_collection_wrap(name=cf.gen_unique_str(prefix))
Expand All @@ -226,7 +224,7 @@ def teardown_method(self, method):
teardown method: drop collection and db
"""
log.info("[database_teardown_method] Start teardown database test cases ...")

self._connect()
# clear db
for db in self.database_wrap.list_database()[0]:
# using db
Expand All @@ -235,9 +233,7 @@ def teardown_method(self, method):
# drop db collections
colls, _ = self.utility_wrap.list_collections()
for coll in colls:
cw = ApiCollectionWrapper()
cw.init_collection(coll)
cw.drop()
self.utility_wrap.drop_collection(coll)

# drop db
if db != ct.default_db:
Expand Down Expand Up @@ -507,14 +503,14 @@ def test_drop_using_db(self):
using_collections, _ = self.utility_wrap.list_collections()
assert collection_w_default.name in using_collections

def test_using_db_not_existed(self, host, port):
def test_using_db_not_existed(self):
"""
target: test using a not existed db
method: using a not existed db
expected: exception
"""
# create db
self.connection_wrap.connect(host=host, port=port, user=ct.default_user, password=ct.default_password)
self._connect()
collection_w = self.init_collection_wrap(cf.gen_unique_str(prefix))

# list collection with not exist using db -> exception
Expand Down Expand Up @@ -547,9 +543,7 @@ def teardown_method(self, method):
# drop db collections
colls, _ = self.utility_wrap.list_collections()
for coll in colls:
cw = ApiCollectionWrapper()
cw.init_collection(coll)
cw.drop()
self.utility_wrap.drop_collection(coll)

# drop db
if db != ct.default_db:
Expand Down

0 comments on commit a888606

Please sign in to comment.