Skip to content

Commit

Permalink
test: [CP] add alter tests (milvus-io#38659)
Browse files Browse the repository at this point in the history
related issue: milvus-io#38471

---------

Signed-off-by: yanliang567 <[email protected]>
  • Loading branch information
yanliang567 authored and NicoYuan1986 committed Dec 26, 2024
1 parent 5ca7702 commit 876fa8a
Show file tree
Hide file tree
Showing 8 changed files with 567 additions and 29 deletions.
157 changes: 134 additions & 23 deletions tests/python_client/base/high_level_api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ def create_schema(self, client, timeout=None, check_task=None,
return res, check_result

@trace()
def create_collection(self, client, collection_name, dimension, timeout=None, check_task=None,
def create_collection(self, client, collection_name, dimension=None, primary_field_name='id',
id_type='int', vector_field_name='vector', metric_type='COSINE',
auto_id=False, schema=None, index_params=None, timeout=None, check_task=None,
check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.create_collection, collection_name, dimension], **kwargs)
res, check = api_request([client.create_collection, collection_name, dimension, primary_field_name,
id_type, vector_field_name, metric_type, auto_id, timeout, schema,
index_params], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
collection_name=collection_name, dimension=dimension,
**kwargs).run()
Expand All @@ -85,7 +88,6 @@ def insert(self, client, collection_name, data, timeout=None, check_task=None, c
func_name = sys._getframe().f_code.co_name
res, check = api_request([client.insert, collection_name, data], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
collection_name=collection_name, data=data,
**kwargs).run()
return res, check_result

Expand Down Expand Up @@ -219,9 +221,9 @@ def list_partitions(self, client, collection_name, check_task=None, check_items=
return res, check_result

@trace()
def list_indexes(self, client, collection_name, check_task=None, check_items=None, **kwargs):
def list_indexes(self, client, collection_name, field_name=None, check_task=None, check_items=None, **kwargs):
func_name = sys._getframe().f_code.co_name
res, check = api_request([client.list_indexes, collection_name], **kwargs)
res, check = api_request([client.list_indexes, collection_name, field_name], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
collection_name=collection_name,
**kwargs).run()
Expand Down Expand Up @@ -313,19 +315,6 @@ def rename_collection(self, client, old_name, new_name, timeout=None, check_task
**kwargs).run()
return res, check_result

@trace()
def use_database(self, client, db_name, timeout=None, check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.use_database, db_name], **kwargs)
check_result = ResponseChecker(res, func_name, check_task,
check_items, check,
db_name=db_name,
**kwargs).run()
return res, check_result

@trace()
def create_partition(self, client, collection_name, partition_name, timeout=None, check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
Expand Down Expand Up @@ -533,10 +522,7 @@ def using_database(self, client, db_name, timeout=None, check_task=None, check_i

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.using_database, db_name], **kwargs)
check_result = ResponseChecker(res, func_name, check_task,
check_items, check,
db_name=db_name,
**kwargs).run()
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

def create_user(self, user_name, password, timeout=None, check_task=None, check_items=None, **kwargs):
Expand Down Expand Up @@ -678,3 +664,128 @@ def revoke_privilege(self, role_name, object_type, privilege, object_name, db_na
role_name=role_name, object_type=object_type, privilege=privilege,
object_name=object_name, db_name=db_name, **kwargs).run()
return res, check_result

@trace()
def alter_index_properties(self, client, collection_name, index_name, properties, timeout=None,
check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.alter_index_properties, collection_name, index_name, properties],
**kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

@trace()
def drop_index_properties(self, client, collection_name, index_name, property_keys, timeout=None,
check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.drop_index_properties, collection_name, index_name, property_keys],
**kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

@trace()
def alter_collection_properties(self, client, collection_name, properties, timeout=None,
check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.alter_collection_properties, collection_name, properties],
**kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

@trace()
def drop_collection_properties(self, client, collection_name, property_keys, timeout=None,
check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.drop_collection_properties, collection_name, property_keys, timeout],
**kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

@trace()
def alter_collection_field(self, client, collection_name, field_name, field_params, timeout=None,
check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.alter_collection_field, collection_name, field_name, field_params, timeout],
**kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

@trace()
def alter_database_properties(self, client, db_name, properties, timeout=None,
check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.alter_database_properties, db_name, properties], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

@trace()
def drop_database_properties(self, client, db_name, property_keys, timeout=None,
check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.drop_database_properties, db_name, property_keys], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

@trace()
def create_database(self, client, db_name, timeout=None, check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.create_database, db_name], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

@trace()
def describe_database(self, client, db_name, timeout=None, check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.describe_database, db_name], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

@trace()
def drop_database(self, client, db_name, timeout=None, check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.drop_database, db_name], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result

@trace()
def list_databases(self, client, timeout=None, check_task=None, check_items=None, **kwargs):
timeout = TIMEOUT if timeout is None else timeout
kwargs.update({"timeout": timeout})

func_name = sys._getframe().f_code.co_name
res, check = api_request([client.list_databases], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
return res, check_result





29 changes: 29 additions & 0 deletions tests/python_client/check/func_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def run(self):
elif self.check_task == CheckTasks.check_describe_collection_property:
# describe collection interface(high level api) response check
result = self.check_describe_collection_property(self.response, self.func_name, self.check_items)
elif self.check_task == CheckTasks.check_collection_fields_properties:
# check field properties in describe collection response
result = self.check_collection_fields_properties(self.response, self.func_name, self.check_items)

elif self.check_task == CheckTasks.check_insert_result:
# check `insert` interface response
Expand Down Expand Up @@ -257,6 +260,32 @@ def check_describe_collection_property(res, func_name, check_items):

return True

@staticmethod
def check_collection_fields_properties(res, func_name, check_items):
"""
According to the check_items to check collection field properties of res, which return from func_name
:param res: actual response of client.describe_collection()
:type res: Collection
:param func_name: describe_collection
:type func_name: str
:param check_items: which field properties expected to be checked, like max_length etc.
:type check_items: dict, {field_name: {field_properties}, ...}
"""
exp_func_name = "describe_collection"
if func_name != exp_func_name:
log.warning("The function name is {} rather than {}".format(func_name, exp_func_name))
if len(check_items) == 0:
raise Exception("No expect values found in the check task")
if check_items.get("collection_name", None) is not None:
assert res["collection_name"] == check_items.get("collection_name")
for key in check_items.keys():
for field in res["fields"]:
if field["name"] == key:
assert field['params'].items() >= check_items[key].items()
return True

@staticmethod
def check_partition_property(partition, func_name, check_items):
exp_func_name = "init_partition"
Expand Down
1 change: 1 addition & 0 deletions tests/python_client/common/common_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class CheckTasks:
check_rg_property = "check_resource_group_property"
check_describe_collection_property = "check_describe_collection_property"
check_insert_result = "check_insert_result"
check_collection_fields_properties = "check_collection_fields_properties"


class BulkLoadStates:
Expand Down
Loading

0 comments on commit 876fa8a

Please sign in to comment.