Skip to content

Commit 985d8a1

Browse files
aayush3011Aayush KatariasimorenohCopilot
authored
Fix full text policy test assertions to accommodate backend V2 read behavior (#45688)
* Fixing failing Full text policy test cases * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fixing failing Full text policy test cases * Fixing failing Full text policy test cases --------- Co-authored-by: Aayush Kataria <aayushkataria@Aayushs-MacBook-Pro-2.local> Co-authored-by: Simon Moreno <30335873+simorenoh@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 9a79037 commit 985d8a1

2 files changed

Lines changed: 87 additions & 43 deletions

File tree

sdk/cosmos/azure-cosmos/tests/test_full_text_policy.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# The MIT License (MIT)
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33

4+
import re
45
import unittest
56
import uuid
67

@@ -83,7 +84,8 @@ def test_create_full_text_container(self):
8384
indexing_policy=indexing_policy
8485
)
8586
properties = created_container.read()
86-
assert properties["fullTextPolicy"] == full_text_policy
87+
assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"]
88+
assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"]
8789
assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes']
8890
self.test_db.delete_container(created_container.id)
8991

@@ -97,7 +99,7 @@ def test_create_full_text_container(self):
9799
full_text_policy=full_text_policy_no_paths,
98100
)
99101
properties = created_container.read()
100-
assert properties["fullTextPolicy"] == full_text_policy_no_paths
102+
assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy_no_paths["defaultLanguage"]
101103
self.test_db.delete_container(created_container.id)
102104

103105
# 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):
115117
full_text_policy=full_text_policy_no_langs,
116118
)
117119
properties = created_container.read()
118-
assert properties["fullTextPolicy"] == full_text_policy_no_langs
120+
assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy_no_langs["defaultLanguage"]
121+
assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy_no_langs["fullTextPaths"]
119122
self.test_db.delete_container(created_container.id)
120123

121124
def test_replace_full_text_container(self):
@@ -149,7 +152,8 @@ def test_replace_full_text_container(self):
149152
indexing_policy=indexing_policy
150153
)
151154
properties = replaced_container.read()
152-
assert properties["fullTextPolicy"] == full_text_policy
155+
assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"]
156+
assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"]
153157
assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes']
154158
assert created_container_properties['indexingPolicy'] != properties['indexingPolicy']
155159
self.test_db.delete_container(created_container.id)
@@ -162,8 +166,9 @@ def test_replace_full_text_container(self):
162166
indexing_policy=indexing_policy
163167
)
164168
created_container_properties = created_container.read()
165-
assert properties["fullTextPolicy"] == full_text_policy
166-
assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes']
169+
assert created_container_properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"]
170+
assert created_container_properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"]
171+
assert created_container_properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes']
167172

168173
# Replace the container with new policies
169174
full_text_policy['fullTextPaths'][0]['path'] = "/new_path"
@@ -175,7 +180,8 @@ def test_replace_full_text_container(self):
175180
indexing_policy=indexing_policy
176181
)
177182
properties = replaced_container.read()
178-
assert properties["fullTextPolicy"] == full_text_policy
183+
assert properties["fullTextPolicy"]["defaultLanguage"] == full_text_policy["defaultLanguage"]
184+
assert properties["fullTextPolicy"]["fullTextPaths"] == full_text_policy["fullTextPaths"]
179185
assert properties["indexingPolicy"]['fullTextIndexes'] == indexing_policy['fullTextIndexes']
180186
assert created_container_properties['fullTextPolicy'] != properties['fullTextPolicy']
181187
assert created_container_properties["indexingPolicy"] != properties["indexingPolicy"]
@@ -201,7 +207,9 @@ def test_fail_create_full_text_policy(self):
201207
pytest.fail("Container creation should have failed for invalid path.")
202208
except exceptions.CosmosHttpResponseError as e:
203209
assert e.status_code == 400
204-
assert "The Full Text Policy contains an invalid Path: abstract" in e.http_error_message
210+
assert re.search(
211+
r"the full.text policy contains an invalid path.*abstract",
212+
e.http_error_message, re.IGNORECASE)
205213

206214
# Pass a full text policy with an unsupported default language
207215
full_text_policy_wrong_default = {
@@ -222,8 +230,9 @@ def test_fail_create_full_text_policy(self):
222230
pytest.fail("Container creation should have failed for wrong supported language.")
223231
except exceptions.CosmosHttpResponseError as e:
224232
assert e.status_code == 400
225-
assert "The Full Text Policy contains an unsupported language spa-SPA. Supported languages are:"\
226-
in e.http_error_message
233+
assert re.search(
234+
r"the full.text policy contains an unsupported language.*spa-SPA",
235+
e.http_error_message, re.IGNORECASE)
227236

228237
# Pass a full text policy with an unsupported path language
229238
full_text_policy_wrong_default = {
@@ -244,8 +253,9 @@ def test_fail_create_full_text_policy(self):
244253
pytest.fail("Container creation should have failed for wrong supported language.")
245254
except exceptions.CosmosHttpResponseError as e:
246255
assert e.status_code == 400
247-
assert "The Full Text Policy contains an unsupported language spa-SPA. Supported languages are:"\
248-
in e.http_error_message
256+
assert re.search(
257+
r"the full.text policy contains an unsupported language.*spa-SPA",
258+
e.http_error_message, re.IGNORECASE)
249259

250260
def test_fail_create_full_text_indexing_policy(self):
251261
full_text_policy = {
@@ -274,8 +284,9 @@ def test_fail_create_full_text_indexing_policy(self):
274284
# pytest.fail("Container creation should have failed for lack of embedding policy.")
275285
except exceptions.CosmosHttpResponseError as e:
276286
assert e.status_code == 400
277-
assert "The path of the Full Text Index /path does not match the path specified in the Full Text Policy"\
278-
in e.http_error_message
287+
assert re.search(
288+
r"the path of the full.text index.*does not match the path specified in the full.text policy",
289+
e.http_error_message, re.IGNORECASE)
279290

280291
# Pass a full text indexing policy with a wrongly formatted path
281292
indexing_policy_wrong_path = {
@@ -293,7 +304,9 @@ def test_fail_create_full_text_indexing_policy(self):
293304
pytest.fail("Container creation should have failed for invalid path.")
294305
except exceptions.CosmosHttpResponseError as e:
295306
assert e.status_code == 400
296-
assert "Full-text index specification at index (0) contains invalid path" in e.http_error_message
307+
assert re.search(
308+
r"full.text index specification at index \(0\) contains invalid path",
309+
e.http_error_message, re.IGNORECASE)
297310

298311
# Pass a full text indexing policy without a path field
299312
indexing_policy_no_path = {
@@ -311,7 +324,9 @@ def test_fail_create_full_text_indexing_policy(self):
311324
pytest.fail("Container creation should have failed for missing path.")
312325
except exceptions.CosmosHttpResponseError as e:
313326
assert e.status_code == 400
314-
assert "Missing path in full-text index specification at index (0)" in e.http_error_message
327+
assert re.search(
328+
r"missing path in full.text index specification at index \(0\)",
329+
e.http_error_message, re.IGNORECASE)
315330

316331
# Skipped until testing pipeline is set up for full text multi-language support
317332
@pytest.mark.skip
@@ -342,7 +357,8 @@ def test_supported_languages_in_full_text_policy(self):
342357
full_text_policy=updated_policy
343358
)
344359
properties = replaced_container.read()
345-
assert properties["fullTextPolicy"] == updated_policy
360+
assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"]
361+
assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"]
346362
finally:
347363
self.test_db.delete_container(container.id)
348364

@@ -376,7 +392,8 @@ def test_default_language_fallback(self):
376392
full_text_policy=updated_policy
377393
)
378394
properties = replaced_container.read()
379-
assert properties["fullTextPolicy"] == updated_policy
395+
assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"]
396+
assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"]
380397
# Insert and verify item
381398
item = {
382399
"id": str(uuid.uuid4()),
@@ -429,7 +446,8 @@ def test_mismatched_default_and_path_languages(self):
429446
full_text_policy=updated_policy
430447
)
431448
properties = replaced_container.read()
432-
assert properties["fullTextPolicy"] == updated_policy
449+
assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"]
450+
assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"]
433451

434452
finally:
435453
# Delete the container at the end of the test
@@ -472,7 +490,8 @@ def test_replace_full_text_policy_with_different_languages(self):
472490
full_text_policy=updated_policy
473491
)
474492
properties = replaced_container.read()
475-
assert properties["fullTextPolicy"] == updated_policy
493+
assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"]
494+
assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"]
476495

477496
finally:
478497
# Delete the container at the end of the test
@@ -515,7 +534,8 @@ def test_replace_full_text_policy_with_different_path_languages(self):
515534
full_text_policy=updated_policy
516535
)
517536
properties = replaced_container.read()
518-
assert properties["fullTextPolicy"] == updated_policy
537+
assert properties["fullTextPolicy"]["defaultLanguage"] == updated_policy["defaultLanguage"]
538+
assert properties["fullTextPolicy"]["fullTextPaths"] == updated_policy["fullTextPaths"]
519539

520540
finally:
521541
# Delete the container at the end of the test
@@ -611,7 +631,9 @@ def test_unsupported_language_in_full_text_policy(self):
611631
pytest.fail("Container replacement should have failed for unsupported language.")
612632
except exceptions.CosmosHttpResponseError as e:
613633
assert e.status_code == 400
614-
assert "The Full Text Policy contains an unsupported language" in e.http_error_message
634+
assert re.search(
635+
r"the full.text policy contains an unsupported language",
636+
e.http_error_message, re.IGNORECASE)
615637
finally:
616638
self.test_db.delete_container(container.id)
617639

0 commit comments

Comments
 (0)