From 0d0eda24f89204ce070847f5f2cd2d382619bcea Mon Sep 17 00:00:00 2001 From: nico <109071306+NicoYuan1986@users.noreply.github.com> Date: Fri, 17 May 2024 15:07:37 +0800 Subject: [PATCH] test: modify some test cases (#33096) Signed-off-by: nico --- tests/python_client/requirements.txt | 1 + tests/python_client/testcases/test_utility.py | 129 ++++++++++++------ 2 files changed, 92 insertions(+), 38 deletions(-) diff --git a/tests/python_client/requirements.txt b/tests/python_client/requirements.txt index 84976974b8c84..177e44cd3692f 100644 --- a/tests/python_client/requirements.txt +++ b/tests/python_client/requirements.txt @@ -12,6 +12,7 @@ allure-pytest==2.7.0 pytest-print==0.2.1 pytest-level==0.1.1 pytest-xdist==2.5.0 +pymilvus==2.5.0rc31 pymilvus[bulk_writer]==2.5.0rc31 pytest-rerunfailures==9.1.1 git+https://github.com/Projectplace/pytest-tags diff --git a/tests/python_client/testcases/test_utility.py b/tests/python_client/testcases/test_utility.py index d077d83d7f056..f4eccf19597cc 100644 --- a/tests/python_client/testcases/test_utility.py +++ b/tests/python_client/testcases/test_utility.py @@ -57,42 +57,67 @@ def get_invalid_value_collection_name(self, request): """ @pytest.mark.tags(CaseLabel.L2) - def test_has_collection_name_invalid(self, get_invalid_collection_name): + def test_has_collection_name_type_invalid(self, get_invalid_type_collection_name): """ target: test has_collection with error collection name method: input invalid name expected: raise exception """ self._connect() - c_name = get_invalid_collection_name - if isinstance(c_name, str) and c_name: - self.utility_wrap.has_collection( - c_name, - check_task=CheckTasks.err_res, - check_items={ct.err_code: 1100, - ct.err_msg: "collection name should not be empty: invalid parameter"}) - # elif not isinstance(c_name, str): self.utility_wrap.has_collection(c_name, check_task=CheckTasks.err_res, - # check_items={ct.err_code: 1, ct.err_msg: "illegal"}) + c_name = get_invalid_type_collection_name + self.utility_wrap.has_collection(c_name, check_task=CheckTasks.err_res, + check_items={ct.err_code: 999, + ct.err_msg: f"`collection_name` value {c_name} is illegal"}) @pytest.mark.tags(CaseLabel.L2) - def test_has_partition_collection_name_invalid(self, get_invalid_collection_name): + def test_has_collection_name_value_invalid(self, get_invalid_value_collection_name): + """ + target: test has_collection with error collection name + method: input invalid name + expected: raise exception + """ + self._connect() + c_name = get_invalid_value_collection_name + error = {ct.err_code: 999, ct.err_msg: f"Invalid collection name: {c_name}"} + if c_name in [None, ""]: + error = {ct.err_code: 999, ct.err_msg: f"`collection_name` value {c_name} is illegal"} + elif c_name == " ": + error = {ct.err_code: 999, ct.err_msg: "collection name should not be empty: invalid parameter"} + self.utility_wrap.has_collection(c_name, check_task=CheckTasks.err_res, check_items=error) + + @pytest.mark.tags(CaseLabel.L2) + def test_has_partition_collection_name_type_invalid(self, get_invalid_type_collection_name): """ target: test has_partition with error collection name method: input invalid name expected: raise exception """ self._connect() - c_name = get_invalid_collection_name + c_name = get_invalid_type_collection_name p_name = cf.gen_unique_str(prefix) - if isinstance(c_name, str) and c_name: - self.utility_wrap.has_partition( - c_name, p_name, - check_task=CheckTasks.err_res, - check_items={ct.err_code: 1100, - ct.err_msg: "collection name should not be empty: invalid parameter"}) + self.utility_wrap.has_partition(c_name, p_name, check_task=CheckTasks.err_res, + check_items={ct.err_code: 999, + ct.err_msg: f"`collection_name` value {c_name} is illegal"}) @pytest.mark.tags(CaseLabel.L2) - def test_has_partition_name_invalid(self, get_invalid_partition_name): + def test_has_partition_collection_name_value_invalid(self, get_invalid_value_collection_name): + """ + target: test has_partition with error collection name + method: input invalid name + expected: raise exception + """ + self._connect() + c_name = get_invalid_value_collection_name + p_name = cf.gen_unique_str(prefix) + error = {ct.err_code: 999, ct.err_msg: f"Invalid collection name: {c_name}"} + if c_name in [None, ""]: + error = {ct.err_code: 999, ct.err_msg: f"`collection_name` value {c_name} is illegal"} + elif c_name == " ": + error = {ct.err_code: 999, ct.err_msg: "collection name should not be empty: invalid parameter"} + self.utility_wrap.has_partition(c_name, p_name, check_task=CheckTasks.err_res, check_items=error) + + @pytest.mark.tags(CaseLabel.L2) + def test_has_partition_name_type_invalid(self, get_invalid_type_collection_name): """ target: test has_partition with error partition name method: input invalid name @@ -101,21 +126,49 @@ def test_has_partition_name_invalid(self, get_invalid_partition_name): self._connect() ut = ApiUtilityWrapper() c_name = cf.gen_unique_str(prefix) - p_name = get_invalid_partition_name - if isinstance(p_name, str) and p_name: - ex, _ = ut.has_partition( - c_name, p_name, - check_task=CheckTasks.err_res, - check_items={ct.err_code: 1, ct.err_msg: "Invalid"}) + p_name = get_invalid_type_collection_name + ut.has_partition(c_name, p_name, check_task=CheckTasks.err_res, + check_items={ct.err_code: 999, + ct.err_msg: f"`partition_name` value {p_name} is illegal"}) @pytest.mark.tags(CaseLabel.L2) - def test_drop_collection_name_invalid(self, get_invalid_collection_name): + def test_has_partition_name_value_invalid(self, get_invalid_value_collection_name): + """ + target: test has_partition with error partition name + method: input invalid name + expected: raise exception + """ self._connect() - error1 = {ct.err_code: 1, ct.err_msg: f"`collection_name` value {get_invalid_collection_name} is illegal"} - error2 = {ct.err_code: 1100, ct.err_msg: f"Invalid collection name: {get_invalid_collection_name}."} - error = error1 if get_invalid_collection_name in [[], 1, [1, '2', 3], (1,), {1: 1}, None, ""] else error2 - self.utility_wrap.drop_collection(get_invalid_collection_name, check_task=CheckTasks.err_res, - check_items=error) + ut = ApiUtilityWrapper() + c_name = cf.gen_unique_str(prefix) + p_name = get_invalid_value_collection_name + if p_name == "12name": + pytest.skip("partition name 12name is legal") + error = {ct.err_code: 999, ct.err_msg: f"Invalid partition name: {p_name}"} + if p_name in [None]: + error = {ct.err_code: 999, ct.err_msg: f"`partition_name` value {p_name} is illegal"} + elif p_name in [" ", ""]: + error = {ct.err_code: 999, ct.err_msg: "Invalid partition name: . Partition name should not be empty."} + ut.has_partition(c_name, p_name, check_task=CheckTasks.err_res, check_items=error) + + @pytest.mark.tags(CaseLabel.L2) + def test_drop_collection_name_type_invalid(self, get_invalid_type_collection_name): + self._connect() + c_name = get_invalid_type_collection_name + self.utility_wrap.drop_collection(c_name, check_task=CheckTasks.err_res, + check_items={ct.err_code: 999, + ct.err_msg: f"`collection_name` value {c_name} is illegal"}) + + @pytest.mark.tags(CaseLabel.L2) + def test_drop_collection_name_value_invalid(self, get_invalid_value_collection_name): + self._connect() + c_name = get_invalid_value_collection_name + error = {ct.err_code: 999, ct.err_msg: f"Invalid collection name: {c_name}"} + if c_name in [None, ""]: + error = {ct.err_code: 999, ct.err_msg: f"`collection_name` value {c_name} is illegal"} + elif c_name == " ": + error = {ct.err_code: 999, ct.err_msg: "collection name should not be empty: invalid parameter"} + self.utility_wrap.drop_collection(c_name, check_task=CheckTasks.err_res, check_items=error) # TODO: enable @pytest.mark.tags(CaseLabel.L2) @@ -162,7 +215,8 @@ def test_index_process_invalid_index_name(self, invalid_index_name): check_task=CheckTasks.err_res, check_items=error) @pytest.mark.tags(CaseLabel.L2) - def test_wait_index_invalid_name(self, get_invalid_collection_name): + @pytest.mark.skip("not ready") + def test_wait_index_invalid_name(self, get_invalid_type_collection_name): """ target: test wait_index method: input invalid name @@ -436,13 +490,12 @@ def test_rename_collection_new_invalid_value(self, get_invalid_value_collection_ collection_w, vectors, _, insert_ids, _ = self.init_collection_general(prefix) old_collection_name = collection_w.name new_collection_name = get_invalid_value_collection_name + error = {"err_code": 1100, "err_msg": "Invalid collection name: %s. the first character of a collection name mu" + "st be an underscore or letter: invalid parameter" % new_collection_name} + if new_collection_name in [None, ""]: + error = {"err_code": 999, "err_msg": f"`collection_name` value {new_collection_name} is illegal"} self.utility_wrap.rename_collection(old_collection_name, new_collection_name, - check_task=CheckTasks.err_res, - check_items={"err_code": 1100, - "err_msg": "Invalid collection name: %s. the first " - "character of a collection name must be an " - "underscore or letter: invalid parameter" - % new_collection_name}) + check_task=CheckTasks.err_res, check_items=error) @pytest.mark.tags(CaseLabel.L2) def test_rename_collection_not_existed_collection(self):