From 6df8aa8654c83548616aaa67012797731f7693b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B4=AB=E6=99=B4?= Date: Wed, 3 Mar 2021 17:55:13 +0800 Subject: [PATCH] Add 0331 tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 紫晴 --- .../collection/test_create_collection.py | 55 ++++++++++++++----- .../collection/test_describe_collection.py | 21 ++++--- .../collection/test_drop_collection.py | 20 +++---- .../collection/test_has_collection.py | 1 + tests/python_test/test_partition.py | 2 + 5 files changed, 63 insertions(+), 36 deletions(-) diff --git a/tests/python_test/collection/test_create_collection.py b/tests/python_test/collection/test_create_collection.py index 36781d5614..2a3f1a9fe0 100644 --- a/tests/python_test/collection/test_create_collection.py +++ b/tests/python_test/collection/test_create_collection.py @@ -82,8 +82,13 @@ class TestCreateCollection: # pdb.set_trace() connect.insert(collection, default_entity) - with pytest.raises(Exception) as e: + try: connect.create_collection(collection, default_fields) + except Exception as e: + code = getattr(e, 'code', "The exception does not contain the field of code.") + assert code == 1 + message = getattr(e, 'message', "The exception does not contain the field of message.") + assert message == "Create collection failed: collection %s exist" % collection @pytest.mark.tags("0331") def test_create_collection_after_insert_flush(self, connect, collection): @@ -94,8 +99,13 @@ class TestCreateCollection: ''' connect.insert(collection, default_entity) # connect.flush([collection]) - with pytest.raises(Exception) as e: + try: connect.create_collection(collection, default_fields) + except Exception as e: + code = getattr(e, 'code', "The exception does not contain the field of code.") + assert code == 1 + message = getattr(e, 'message', "The exception does not contain the field of message.") + assert message == "Create collection failed: collection %s exist" % collection # TODO: assert exception @pytest.mark.tags("0331") @@ -118,8 +128,13 @@ class TestCreateCollection: ''' collection_name = gen_unique_str(uid) connect.create_collection(collection_name, default_fields) - with pytest.raises(Exception) as e: + try: connect.create_collection(collection_name, default_fields) + except Exception as e: + code = getattr(e, 'code', "The exception does not contain the field of code.") + assert code == 1 + message = getattr(e, 'message', "The exception does not contain the field of message.") + assert message == "Create collection failed: collection %s exist" % collection_name @pytest.mark.tags("0331") def test_create_after_drop_collection(self, connect, collection): @@ -229,17 +244,16 @@ class TestCreateCollectionInvalid(object): @pytest.mark.level(2) @pytest.mark.tags("0331") - def test_create_collection_with_empty_collection_name(self, connect): - collection_name = '' - with pytest.raises(Exception) as e: - connect.create_collection(collection_name, default_fields) - - @pytest.mark.level(2) - @pytest.mark.tags("0331") - def test_create_collection_with_none_collection_name(self, connect): - collection_name = None - with pytest.raises(Exception) as e: + @pytest.mark.parametrize("collection_name", ('', None)) + def test_create_collection_with_empty_or_None_collection_name(self, connect, collection_name): + # collection_name = '' + try: connect.create_collection(collection_name, default_fields) + except Exception as e: + code = getattr(e, 'code', "The exception does not contain the field of code.") + assert code == 1 + message = getattr(e, 'message', "The exception does not contain the field of message.") + assert message == "Collection name should not be empty" @pytest.mark.tags("0331") def test_create_collection_no_dimension(self, connect): @@ -251,8 +265,13 @@ class TestCreateCollectionInvalid(object): collection_name = gen_unique_str(uid) fields = copy.deepcopy(default_fields) fields["fields"][-1]["params"].pop("dim") - with pytest.raises(Exception) as e: + try: connect.create_collection(collection_name, fields) + except Exception as e: + code = getattr(e, 'code', "The exception does not contain the field of code.") + assert code == 1 + message = getattr(e, 'message', "The exception does not contain the field of message.") + assert message == "dimension is not defined in field type params" def _test_create_collection_no_segment_row_limit(self, connect): ''' @@ -278,8 +297,14 @@ class TestCreateCollectionInvalid(object): field_name = gen_unique_str("field_name") field = {"name": field_name, "type": DataType.INT64} fields["fields"].append(field) - with pytest.raises(Exception) as e: + + try: connect.create_collection(collection_name, fields) + except Exception as e: + code = getattr(e, 'code', "The exception does not contain the field of code.") + assert code == 1 + message = getattr(e, 'message', "The exception does not contain the field of message.") + assert message == "maximum field's number should be limited to 64" # TODO: assert exception @pytest.mark.level(2) diff --git a/tests/python_test/collection/test_describe_collection.py b/tests/python_test/collection/test_describe_collection.py index 24ea0f9c53..f441cdb436 100644 --- a/tests/python_test/collection/test_describe_collection.py +++ b/tests/python_test/collection/test_describe_collection.py @@ -6,6 +6,7 @@ from constants import * uid = "describe_collection" + class TestDescribeCollection: @pytest.fixture( @@ -95,8 +96,13 @@ class TestDescribeCollection: connect.create_collection(collection_name, default_fields) connect.describe_collection(collection_name) connect.drop_collection(collection_name) - with pytest.raises(Exception) as e: + try: connect.describe_collection(collection_name) + except Exception as e: + code = getattr(e, 'code', "The exception does not contain the field of code.") + assert code == 1 + message = getattr(e, 'message', "The exception does not contain the field of message.") + assert message == "describe collection failed: can't find collection: %s" % collection_name @pytest.mark.level(2) @pytest.mark.tags("0331") @@ -146,7 +152,7 @@ class TestDescribeCollection: res_ids = connect.insert(collection_name, entities) connect.flush([collection_name]) res = connect.describe_collection(collection_name) - assert res['auto_id'] == True + assert res['auto_id'] is True # assert res['segment_row_limit'] == default_segment_row_limit assert len(res["fields"]) == 2 for field in res["fields"]: @@ -177,14 +183,7 @@ class TestDescribeCollectionInvalid(object): @pytest.mark.level(2) @pytest.mark.tags("0331") - def test_describe_collection_with_empty_collection_name(self, connect): - collection_name = '' - with pytest.raises(Exception) as e: - connect.describe_collection(collection_name) - - @pytest.mark.level(2) - @pytest.mark.tags("0331") - def test_describe_collection_with_none_collection_name(self, connect): - collection_name = None + @pytest.mark.parametrize("collection_name", ('', None)) + def test_describe_collection_with_empty_or_None_collection_name(self, connect, collection_name): with pytest.raises(Exception) as e: connect.describe_collection(collection_name) diff --git a/tests/python_test/collection/test_drop_collection.py b/tests/python_test/collection/test_drop_collection.py index b8249a12b2..f3fe56c3b7 100644 --- a/tests/python_test/collection/test_drop_collection.py +++ b/tests/python_test/collection/test_drop_collection.py @@ -10,6 +10,7 @@ from constants import * uid = "drop_collection" + class TestDropCollection: """ ****************************************************************** @@ -17,7 +18,7 @@ class TestDropCollection: ****************************************************************** """ @pytest.mark.tags("0331") - def test_drop_collection(self, connect, collection): + def test_drop_collection_A(self, connect, collection): ''' target: test delete collection created with correct params method: create collection and then delete, @@ -47,8 +48,13 @@ class TestDropCollection: expected: False ''' collection_name = gen_unique_str(uid) - with pytest.raises(Exception) as e: + try: connect.drop_collection(collection_name) + except Exception as e: + code = getattr(e, 'code', "The exception does not contain the field of code.") + assert code == 1 + message = getattr(e, 'message', "The exception does not contain the field of message.") + assert message == "describe collection failed: can't find collection: %s" % collection_name @pytest.mark.level(2) @pytest.mark.tags("0331") @@ -98,13 +104,7 @@ class TestDropCollectionInvalid(object): connect.has_collection(collection_name) @pytest.mark.tags("0331") - def test_drop_collection_with_empty_collection_name(self, connect): - collection_name = '' - with pytest.raises(Exception) as e: - connect.has_collection(collection_name) - - @pytest.mark.tags("0331") - def test_drop_collection_with_none_collection_name(self, connect): - collection_name = None + @pytest.mark.parametrize("collection_name", ('', None)) + def test_drop_collection_with_empty_or_None_collection_name(self, connect, collection_name): with pytest.raises(Exception) as e: connect.has_collection(collection_name) diff --git a/tests/python_test/collection/test_has_collection.py b/tests/python_test/collection/test_has_collection.py index 2e1a37c61d..688cbd9f34 100644 --- a/tests/python_test/collection/test_has_collection.py +++ b/tests/python_test/collection/test_has_collection.py @@ -10,6 +10,7 @@ from constants import * uid = "has_collection" + class TestHasCollection: """ ****************************************************************** diff --git a/tests/python_test/test_partition.py b/tests/python_test/test_partition.py index 5923791241..d9cd34eeea 100644 --- a/tests/python_test/test_partition.py +++ b/tests/python_test/test_partition.py @@ -157,6 +157,7 @@ class TestCreateBase: message = getattr(e, 'message', "The exception does not contain the field of message.") assert message == "partitionID of partitionName:%s can not be find" % tag_new + @pytest.mark.tags("fail") def test_create_partition_insert_same_tags(self, connect, id_collection): ''' target: test create partition, and insert vectors, check status returned @@ -174,6 +175,7 @@ class TestCreateBase: res = connect.get_collection_stats(id_collection) assert res["row_count"] == default_nb * 2 + @pytest.mark.tags("fail") @pytest.mark.level(2) def test_create_partition_insert_same_tags_two_collections(self, connect, collection): '''