diff --git a/sdk/cosmos/azure-cosmos/tests/test_full_text_policy.py b/sdk/cosmos/azure-cosmos/tests/test_full_text_policy.py index 2c3d883a7049..2f739fcb5b34 100644 --- a/sdk/cosmos/azure-cosmos/tests/test_full_text_policy.py +++ b/sdk/cosmos/azure-cosmos/tests/test_full_text_policy.py @@ -1,6 +1,7 @@ # The MIT License (MIT) # Copyright (c) Microsoft Corporation. All rights reserved. +import re import unittest import uuid @@ -83,7 +84,8 @@ def test_create_full_text_container(self): indexing_policy=indexing_policy ) properties = created_container.read() - assert properties["fullTextPolicy"] == full_text_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"] assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes'] self.test_db.delete_container(created_container.id) @@ -97,7 +99,7 @@ def test_create_full_text_container(self): full_text_policy=full_text_policy_no_paths, ) properties = created_container.read() - assert properties["fullTextPolicy"] == full_text_policy_no_paths + assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy_no_paths["defaultLanguage"] self.test_db.delete_container(created_container.id) # Create a container with a full text policy with a given path containing only default language @@ -115,7 +117,8 @@ def test_create_full_text_container(self): full_text_policy=full_text_policy_no_langs, ) properties = created_container.read() - assert properties["fullTextPolicy"] == full_text_policy_no_langs + assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy_no_langs["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy_no_langs["fullTextPaths"] self.test_db.delete_container(created_container.id) def test_replace_full_text_container(self): @@ -149,7 +152,8 @@ def test_replace_full_text_container(self): indexing_policy=indexing_policy ) properties = replaced_container.read() - assert properties["fullTextPolicy"] == full_text_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"] assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes'] assert created_container_properties['indexingPolicy'] != properties['indexingPolicy'] self.test_db.delete_container(created_container.id) @@ -162,8 +166,9 @@ def test_replace_full_text_container(self): indexing_policy=indexing_policy ) created_container_properties = created_container.read() - assert properties["fullTextPolicy"] == full_text_policy - assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes'] + assert created_container_properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"] + assert created_container_properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"] + assert created_container_properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes'] # Replace the container with new policies full_text_policy['fullTextPaths'][0]['path'] = "/new_path" @@ -175,7 +180,8 @@ def test_replace_full_text_container(self): indexing_policy=indexing_policy ) properties = replaced_container.read() - assert properties["fullTextPolicy"] == full_text_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"] assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes'] assert created_container_properties['fullTextPolicy'] != properties['fullTextPolicy'] assert created_container_properties["indexingPolicy"] != properties["indexingPolicy"] @@ -201,7 +207,9 @@ def test_fail_create_full_text_policy(self): pytest.fail("Container creation should have failed for invalid path.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "The Full Text Policy contains an invalid Path: abstract" in e.http_error_message + assert re.search( + r"the full.text policy contains an invalid path.*abstract", + e.http_error_message, re.IGNORECASE) # Pass a full text policy with an unsupported default language full_text_policy_wrong_default = { @@ -222,8 +230,9 @@ def test_fail_create_full_text_policy(self): pytest.fail("Container creation should have failed for wrong supported language.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "The Full Text Policy contains an unsupported language spa-SPA. Supported languages are:"\ - in e.http_error_message + assert re.search( + r"the full.text policy contains an unsupported language.*spa-SPA", + e.http_error_message, re.IGNORECASE) # Pass a full text policy with an unsupported path language full_text_policy_wrong_default = { @@ -244,8 +253,9 @@ def test_fail_create_full_text_policy(self): pytest.fail("Container creation should have failed for wrong supported language.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "The Full Text Policy contains an unsupported language spa-SPA. Supported languages are:"\ - in e.http_error_message + assert re.search( + r"the full.text policy contains an unsupported language.*spa-SPA", + e.http_error_message, re.IGNORECASE) def test_fail_create_full_text_indexing_policy(self): full_text_policy = { @@ -274,8 +284,9 @@ def test_fail_create_full_text_indexing_policy(self): # pytest.fail("Container creation should have failed for lack of embedding policy.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "The path of the Full Text Index /path does not match the path specified in the Full Text Policy"\ - in e.http_error_message + assert re.search( + r"the path of the full.text index.*does not match the path specified in the full.text policy", + e.http_error_message, re.IGNORECASE) # Pass a full text indexing policy with a wrongly formatted path indexing_policy_wrong_path = { @@ -293,7 +304,9 @@ def test_fail_create_full_text_indexing_policy(self): pytest.fail("Container creation should have failed for invalid path.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "Full-text index specification at index (0) contains invalid path" in e.http_error_message + assert re.search( + r"full.text index specification at index \(0\) contains invalid path", + e.http_error_message, re.IGNORECASE) # Pass a full text indexing policy without a path field indexing_policy_no_path = { @@ -311,7 +324,9 @@ def test_fail_create_full_text_indexing_policy(self): pytest.fail("Container creation should have failed for missing path.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "Missing path in full-text index specification at index (0)" in e.http_error_message + assert re.search( + r"missing path in full.text index specification at index \(0\)", + e.http_error_message, re.IGNORECASE) # Skipped until testing pipeline is set up for full text multi-language support @pytest.mark.skip @@ -342,7 +357,8 @@ def test_supported_languages_in_full_text_policy(self): full_text_policy=updated_policy ) properties = replaced_container.read() - assert properties["fullTextPolicy"] == updated_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"] finally: self.test_db.delete_container(container.id) @@ -376,7 +392,8 @@ def test_default_language_fallback(self): full_text_policy=updated_policy ) properties = replaced_container.read() - assert properties["fullTextPolicy"] == updated_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"] # Insert and verify item item = { "id": str(uuid.uuid4()), @@ -429,7 +446,8 @@ def test_mismatched_default_and_path_languages(self): full_text_policy=updated_policy ) properties = replaced_container.read() - assert properties["fullTextPolicy"] == updated_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"] finally: # Delete the container at the end of the test @@ -472,7 +490,8 @@ def test_replace_full_text_policy_with_different_languages(self): full_text_policy=updated_policy ) properties = replaced_container.read() - assert properties["fullTextPolicy"] == updated_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"] finally: # Delete the container at the end of the test @@ -515,7 +534,8 @@ def test_replace_full_text_policy_with_different_path_languages(self): full_text_policy=updated_policy ) properties = replaced_container.read() - assert properties["fullTextPolicy"] == updated_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"] finally: # Delete the container at the end of the test @@ -611,7 +631,9 @@ def test_unsupported_language_in_full_text_policy(self): pytest.fail("Container replacement should have failed for unsupported language.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "The Full Text Policy contains an unsupported language" in e.http_error_message + assert re.search( + r"the full.text policy contains an unsupported language", + e.http_error_message, re.IGNORECASE) finally: self.test_db.delete_container(container.id) diff --git a/sdk/cosmos/azure-cosmos/tests/test_full_text_policy_async.py b/sdk/cosmos/azure-cosmos/tests/test_full_text_policy_async.py index 378ce6138b81..c962c5d398e8 100644 --- a/sdk/cosmos/azure-cosmos/tests/test_full_text_policy_async.py +++ b/sdk/cosmos/azure-cosmos/tests/test_full_text_policy_async.py @@ -1,6 +1,7 @@ # The MIT License (MIT) # Copyright (c) Microsoft Corporation. All rights reserved. +import re import unittest import uuid @@ -98,7 +99,8 @@ async def test_create_full_text_container_async(self): indexing_policy=indexing_policy ) properties = await created_container.read() - assert properties["fullTextPolicy"] == full_text_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"] assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes'] await self.test_db.delete_container(created_container.id) @@ -112,7 +114,7 @@ async def test_create_full_text_container_async(self): full_text_policy=full_text_policy_no_paths, ) properties = await created_container.read() - assert properties["fullTextPolicy"] == full_text_policy_no_paths + assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy_no_paths["defaultLanguage"] await self.test_db.delete_container(created_container.id) # Create a container with a full text policy with a given path containing only default language @@ -130,7 +132,8 @@ async def test_create_full_text_container_async(self): full_text_policy=full_text_policy_no_langs, ) properties = await created_container.read() - assert properties["fullTextPolicy"] == full_text_policy_no_langs + assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy_no_langs["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy_no_langs["fullTextPaths"] async def test_replace_full_text_container_async(self): # Replace a container without a full text policy and full text indexing policy @@ -163,7 +166,8 @@ async def test_replace_full_text_container_async(self): indexing_policy=indexing_policy ) properties = await replaced_container.read() - assert properties["fullTextPolicy"] == full_text_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"] assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes'] assert created_container_properties['indexingPolicy'] != properties['indexingPolicy'] await self.test_db.delete_container(created_container.id) @@ -176,7 +180,8 @@ async def test_replace_full_text_container_async(self): indexing_policy=indexing_policy ) created_container_properties = await created_container.read() - assert created_container_properties["fullTextPolicy"] == full_text_policy + assert created_container_properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"] + assert created_container_properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"] assert created_container_properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes'] # Replace the container with new policies @@ -189,7 +194,8 @@ async def test_replace_full_text_container_async(self): indexing_policy=indexing_policy ) properties = await replaced_container.read() - assert properties["fullTextPolicy"] == full_text_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"] assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes'] assert created_container_properties['fullTextPolicy'] != properties['fullTextPolicy'] assert created_container_properties["indexingPolicy"] != properties["indexingPolicy"] @@ -215,7 +221,9 @@ async def test_fail_create_full_text_policy_async(self): pytest.fail("Container creation should have failed for invalid path.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "The Full Text Policy contains an invalid Path: abstract" in e.http_error_message + assert re.search( + r"the full.text policy contains an invalid path.*abstract", + e.http_error_message, re.IGNORECASE) # Pass a full text policy with an unsupported default language full_text_policy_wrong_default = { @@ -236,8 +244,9 @@ async def test_fail_create_full_text_policy_async(self): pytest.fail("Container creation should have failed for wrong supported language.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "The Full Text Policy contains an unsupported language spa-SPA. Supported languages are:" \ - in e.http_error_message + assert re.search( + r"the full.text policy contains an unsupported language.*spa-SPA", + e.http_error_message, re.IGNORECASE) # Pass a full text policy with an unsupported path language full_text_policy_wrong_default = { @@ -258,8 +267,9 @@ async def test_fail_create_full_text_policy_async(self): pytest.fail("Container creation should have failed for wrong supported language.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "The Full Text Policy contains an unsupported language spa-SPA. Supported languages are:" \ - in e.http_error_message + assert re.search( + r"the full.text policy contains an unsupported language.*spa-SPA", + e.http_error_message, re.IGNORECASE) async def test_fail_create_full_text_indexing_policy_async(self): full_text_policy = { @@ -288,8 +298,9 @@ async def test_fail_create_full_text_indexing_policy_async(self): # pytest.fail("Container creation should have failed for lack of embedding policy.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "The path of the Full Text Index /path does not match the path specified in the Full Text Policy" \ - in e.http_error_message + assert re.search( + r"the path of the full.text index.*does not match the path specified in the full.text policy", + e.http_error_message, re.IGNORECASE) # Pass a full text indexing policy with a wrongly formatted path indexing_policy_wrong_path = { @@ -307,7 +318,9 @@ async def test_fail_create_full_text_indexing_policy_async(self): pytest.fail("Container creation should have failed for invalid path.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "Full-text index specification at index (0) contains invalid path" in e.http_error_message + assert re.search( + r"full.text index specification at index \(0\) contains invalid path", + e.http_error_message, re.IGNORECASE) # Pass a full text indexing policy without a path field indexing_policy_no_path = { @@ -325,7 +338,9 @@ async def test_fail_create_full_text_indexing_policy_async(self): pytest.fail("Container creation should have failed for missing path.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "Missing path in full-text index specification at index (0)" in e.http_error_message + assert re.search( + r"missing path in full.text index specification at index \(0\)", + e.http_error_message, re.IGNORECASE) # Skipped until testing pipeline is set up for full text multi-language support @pytest.mark.skip @@ -355,7 +370,8 @@ async def test_supported_languages_in_full_text_policy_async(self): full_text_policy=updated_policy ) properties = await replaced_container.read() - assert properties["fullTextPolicy"] == updated_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"] finally: await self.test_db.delete_container(container.id) @@ -387,7 +403,8 @@ async def test_default_language_fallback_async(self): full_text_policy=updated_policy ) properties = await replaced_container.read() - assert properties["fullTextPolicy"] == updated_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"] item = { "id": str(uuid.uuid4()), "abstract": self.language_abstracts[language_code], @@ -439,7 +456,8 @@ async def test_mismatched_default_and_path_languages_async(self): full_text_policy=updated_policy ) properties = await replaced_container.read() - assert properties["fullTextPolicy"] == updated_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"] finally: await self.test_db.delete_container(container.id) @@ -482,7 +500,9 @@ async def test_unsupported_language_in_full_text_policy_async(self): pytest.fail("Container replacement should have failed for unsupported language.") except exceptions.CosmosHttpResponseError as e: assert e.status_code == 400 - assert "The Full Text Policy contains an unsupported language" in e.http_error_message + assert re.search( + r"the full.text policy contains an unsupported language", + e.http_error_message, re.IGNORECASE) finally: await self.test_db.delete_container(container.id) @@ -522,7 +542,8 @@ async def test_replace_full_text_policy_with_different_languages_async(self): full_text_policy=updated_policy ) properties = await replaced_container.read() - assert properties["fullTextPolicy"] == updated_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"] finally: await self.test_db.delete_container(container.id) @@ -562,7 +583,8 @@ async def test_replace_full_text_policy_with_different_path_languages_async(self full_text_policy=updated_policy ) properties = await replaced_container.read() - assert properties["fullTextPolicy"] == updated_policy + assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"] + assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"] finally: await self.test_db.delete_container(container.id)