Skip to content

Commit f084d0d

Browse files
committed
Fixing failing integ tests
Signed-off-by: saimedhi <saimedhi@amazon.com>
1 parent 3e7d97f commit f084d0d

File tree

10 files changed

+88
-88
lines changed

10 files changed

+88
-88
lines changed

guides/plugins/security.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ print(response)
4545
user_name = "test-user"
4646
user_content = {"password": "test_password", "opendistro_security_roles": []}
4747

48-
response = client.security.create_user(user_name, body=user_content)
48+
response = client.security.create_user(username=user_name, body=user_content)
4949
print(response)
5050
```
5151

samples/security/users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def main() -> None:
4040
user_name = "test-user"
4141
user_content = {"password": "opensearch@123", "opendistro_security_roles": []}
4242

43-
response = client.security.create_user(user_name, body=user_content)
43+
response = client.security.create_user(username=user_name, body=user_content)
4444
print(response)
4545

4646
# Get a User

test_opensearchpy/test_async/test_server/test_helpers/test_actions.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ class TestStreamingBulk:
7373
async def test_actions_remain_unchanged(self, async_client: Any) -> None:
7474
actions1 = [{"_id": 1}, {"_id": 2}]
7575
async for ok, _ in actions.async_streaming_bulk(
76-
async_client, actions1, index="test-index"
76+
client=async_client, actions=actions1, index="test-index"
7777
):
7878
assert ok
7979
assert [{"_id": 1}, {"_id": 2}] == actions1
8080

8181
async def test_all_documents_get_inserted(self, async_client: Any) -> None:
8282
docs = [{"answer": x, "_id": x} for x in range(100)]
8383
async for ok, _ in actions.async_streaming_bulk(
84-
async_client, docs, index="test-index", refresh=True
84+
client=async_client, actions=docs, index="test-index", refresh=True
8585
):
8686
assert ok
8787

@@ -128,8 +128,8 @@ async def test_all_errors_from_chunk_are_raised_on_failure(
128128
self, async_client: Any
129129
) -> None:
130130
await async_client.indices.create(
131-
"i",
132-
{
131+
index="i",
132+
body={
133133
"mappings": {"properties": {"a": {"type": "integer"}}},
134134
"settings": {"number_of_shards": 1, "number_of_replicas": 0},
135135
},
@@ -154,7 +154,7 @@ async def test_different_op_types(self, async_client: Any) -> None:
154154
{"_op_type": "delete", "_index": "i", "_id": 45},
155155
{"_op_type": "update", "_index": "i", "_id": 42, "doc": {"answer": 42}},
156156
]
157-
async for ok, _ in actions.async_streaming_bulk(async_client, docs):
157+
async for ok, _ in actions.async_streaming_bulk(client=async_client, actions=docs):
158158
assert ok
159159

160160
assert not await async_client.exists(index="i", id=45)
@@ -172,8 +172,8 @@ async def test_transport_error_can_becaught(self, async_client: Any) -> None:
172172
results = [
173173
x
174174
async for x in actions.async_streaming_bulk(
175-
failing_client,
176-
docs,
175+
client=failing_client,
176+
actions=docs,
177177
raise_on_exception=False,
178178
raise_on_error=False,
179179
chunk_size=1,
@@ -207,8 +207,8 @@ async def test_rejected_documents_are_retried(self, async_client: Any) -> None:
207207
results = [
208208
x
209209
async for x in actions.async_streaming_bulk(
210-
failing_client,
211-
docs,
210+
client=failing_client,
211+
actions=docs,
212212
raise_on_exception=False,
213213
raise_on_error=False,
214214
chunk_size=1,
@@ -238,8 +238,8 @@ async def test_rejected_documents_are_retried_at_most_max_retries_times(
238238
results = [
239239
x
240240
async for x in actions.async_streaming_bulk(
241-
failing_client,
242-
docs,
241+
client=failing_client,
242+
actions=docs,
243243
raise_on_exception=False,
244244
raise_on_error=False,
245245
chunk_size=1,
@@ -285,7 +285,7 @@ class TestBulk:
285285
async def test_bulk_works_with_single_item(self, async_client: Any) -> None:
286286
docs = [{"answer": 42, "_id": 1}]
287287
success, failed = await actions.async_bulk(
288-
async_client, docs, index="test-index", refresh=True
288+
client=async_client, actions=docs, index="test-index", refresh=True
289289
)
290290

291291
assert 1 == success
@@ -298,7 +298,7 @@ async def test_bulk_works_with_single_item(self, async_client: Any) -> None:
298298
async def test_all_documents_get_inserted(self, async_client: Any) -> None:
299299
docs = [{"answer": x, "_id": x} for x in range(100)]
300300
success, failed = await actions.async_bulk(
301-
async_client, docs, index="test-index", refresh=True
301+
client=async_client, actions=docs, index="test-index", refresh=True
302302
)
303303

304304
assert 100 == success
@@ -311,7 +311,7 @@ async def test_all_documents_get_inserted(self, async_client: Any) -> None:
311311
async def test_stats_only_reports_numbers(self, async_client: Any) -> None:
312312
docs = [{"answer": x} for x in range(100)]
313313
success, failed = await actions.async_bulk(
314-
async_client, docs, index="test-index", refresh=True, stats_only=True
314+
client=async_client, actions=docs, index="test-index", refresh=True, stats_only=True
315315
)
316316

317317
assert 100 == success
@@ -320,8 +320,8 @@ async def test_stats_only_reports_numbers(self, async_client: Any) -> None:
320320

321321
async def test_errors_are_reported_correctly(self, async_client: Any) -> None:
322322
await async_client.indices.create(
323-
"i",
324-
{
323+
index="i",
324+
body={
325325
"mappings": {"properties": {"a": {"type": "integer"}}},
326326
"settings": {"number_of_shards": 1, "number_of_replicas": 0},
327327
},
@@ -347,8 +347,8 @@ async def test_errors_are_reported_correctly(self, async_client: Any) -> None:
347347

348348
async def test_error_is_raised(self, async_client: Any) -> None:
349349
await async_client.indices.create(
350-
"i",
351-
{
350+
index="i",
351+
body={
352352
"mappings": {"properties": {"a": {"type": "integer"}}},
353353
"settings": {"number_of_shards": 1, "number_of_replicas": 0},
354354
},
@@ -361,7 +361,7 @@ async def test_error_is_raised(self, async_client: Any) -> None:
361361
async def test_ignore_error_if_raised(self, async_client: Any) -> None:
362362
# ignore the status code 400 in tuple
363363
await actions.async_bulk(
364-
async_client, [{"a": 42}, {"a": "c"}], index="i", ignore_status=(400,)
364+
client=async_client, actions=[{"a": 42}, {"a": "c"}], index="i", ignore_status=(400,)
365365
)
366366

367367
# ignore the status code 400 in list
@@ -393,8 +393,8 @@ async def test_ignore_error_if_raised(self, async_client: Any) -> None:
393393

394394
async def test_errors_are_collected_properly(self, async_client: Any) -> None:
395395
await async_client.indices.create(
396-
"i",
397-
{
396+
index="i",
397+
body={
398398
"mappings": {"properties": {"a": {"type": "integer"}}},
399399
"settings": {"number_of_shards": 1, "number_of_replicas": 0},
400400
},
@@ -461,7 +461,7 @@ async def test_order_can_be_preserved(
461461
for x in range(100):
462462
bulk.append({"index": {"_index": "test_index", "_id": x}})
463463
bulk.append({"answer": x, "correct": x == 42})
464-
await async_client.bulk(bulk, refresh=True)
464+
await async_client.bulk(body=bulk, refresh=True)
465465

466466
docs = [
467467
doc
@@ -484,7 +484,7 @@ async def test_all_documents_are_read(
484484
for x in range(100):
485485
bulk.append({"index": {"_index": "test_index", "_id": x}})
486486
bulk.append({"answer": x, "correct": x == 42})
487-
await async_client.bulk(bulk, refresh=True)
487+
await async_client.bulk(body=bulk, refresh=True)
488488

489489
docs = [
490490
x
@@ -500,7 +500,7 @@ async def test_scroll_error(self, async_client: Any, scan_teardown: Any) -> None
500500
for x in range(4):
501501
bulk.append({"index": {"_index": "test_index"}})
502502
bulk.append({"value": x})
503-
await async_client.bulk(bulk, refresh=True)
503+
await async_client.bulk(body=bulk, refresh=True)
504504

505505
with patch.object(async_client, "scroll", MockScroll()):
506506
data = [
@@ -608,7 +608,7 @@ async def test_logger(
608608
for x in range(4):
609609
bulk.append({"index": {"_index": "test_index"}})
610610
bulk.append({"value": x})
611-
await async_client.bulk(bulk, refresh=True)
611+
await async_client.bulk(body=bulk, refresh=True)
612612

613613
with patch.object(async_client, "scroll", MockScroll()):
614614
_ = [
@@ -649,7 +649,7 @@ async def test_clear_scroll(self, async_client: Any, scan_teardown: Any) -> None
649649
for x in range(4):
650650
bulk.append({"index": {"_index": "test_index"}})
651651
bulk.append({"value": x})
652-
await async_client.bulk(bulk, refresh=True)
652+
await async_client.bulk(body=bulk, refresh=True)
653653

654654
with patch.object(
655655
async_client, "clear_scroll", wraps=async_client.clear_scroll
@@ -820,7 +820,7 @@ async def reindex_setup(async_client: Any) -> Any:
820820
"type": "answers" if x % 2 == 0 else "questions",
821821
}
822822
)
823-
await async_client.bulk(bulk, refresh=True)
823+
await async_client.bulk(body=bulk, refresh=True)
824824
yield
825825

826826

@@ -922,7 +922,7 @@ class TestParentChildReindex:
922922
async def test_children_are_reindexed_correctly(
923923
self, async_client: Any, parent_reindex_setup: Any
924924
) -> None:
925-
await actions.async_reindex(async_client, "test-index", "real-index")
925+
await actions.async_reindex(client=async_client, source_index="test-index", target_index="real-index")
926926
assert {"question_answer": "question"} == (
927927
await async_client.get(index="real-index", id=42)
928928
)["_source"]

test_opensearchpy/test_async/test_server/test_helpers/test_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def test_index_template_works(write_client: Any) -> None:
4848

4949

5050
async def test_index_can_be_saved_even_with_settings(write_client: Any) -> None:
51-
i = AsyncIndex("test-blog", using=write_client)
51+
i = AsyncIndex(name="test-blog", using=write_client)
5252
i.settings(number_of_shards=3, number_of_replicas=0)
5353
await i.save()
5454
i.settings(number_of_replicas=1)
@@ -70,7 +70,7 @@ async def test_index_exists(data_client: Any) -> None:
7070
async def test_index_can_be_created_with_settings_and_mappings(
7171
write_client: Any,
7272
) -> None:
73-
i = AsyncIndex("test-blog", using=write_client)
73+
i = AsyncIndex(name="test-blog", using=write_client)
7474
i.document(Post)
7575
i.settings(number_of_replicas=0, number_of_shards=1)
7676
await i.create()

test_opensearchpy/test_async/test_server/test_helpers/test_update_by_query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def test_update_by_query_no_script(
2525

2626
ubq = (
2727
AsyncUpdateByQuery(using=write_client)
28-
.index(index)
28+
.index(index=index)
2929
.filter(~Q("exists", field="is_public"))
3030
)
3131
response = await ubq.execute()
@@ -46,7 +46,7 @@ async def test_update_by_query_with_script(
4646

4747
ubq = (
4848
AsyncUpdateByQuery(using=write_client)
49-
.index(index)
49+
.index(index=index)
5050
.filter(~Q("exists", field="parent_shas"))
5151
.script(source="ctx._source.is_public = false")
5252
)
@@ -65,7 +65,7 @@ async def test_delete_by_query_with_script(
6565

6666
ubq = (
6767
AsyncUpdateByQuery(using=write_client)
68-
.index(index)
68+
.index(index=index)
6969
.filter(Q("match", parent_shas="1dd19210b5be92b960f7db6f66ae526288edccc3"))
7070
.script(source='ctx.op = "delete"')
7171
)

test_opensearchpy/test_async/test_server_secured/test_security_plugin.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ async def asyncTearDown(self) -> None:
5555
async def test_create_role(self) -> None:
5656
# Test to create role
5757
response = await self.client.security.create_role(
58-
self.ROLE_NAME, body=self.ROLE_CONTENT
58+
role=self.ROLE_NAME, body=self.ROLE_CONTENT
5959
)
6060

6161
self.assertNotIn("errors", response)
6262
self.assertIn(response.get("status"), ["CREATED", "OK"])
6363

6464
async def test_create_role_with_body_param_empty(self) -> None:
6565
try:
66-
await self.client.security.create_role(self.ROLE_NAME, body="")
66+
await self.client.security.create_role(role=self.ROLE_NAME, body="")
6767
except ValueError as error:
6868
assert str(error) == "Empty value passed for a required argument."
6969
else:
@@ -74,7 +74,7 @@ async def test_get_role(self) -> None:
7474
await self.test_create_role()
7575

7676
# Test to fetch the role
77-
response = await self.client.security.get_role(self.ROLE_NAME)
77+
response = await self.client.security.get_role(role=self.ROLE_NAME)
7878

7979
self.assertNotIn("errors", response)
8080
self.assertIn(self.ROLE_NAME, response)
@@ -88,7 +88,7 @@ async def test_update_role(self) -> None:
8888

8989
# Test to update role
9090
response = await self.client.security.create_role(
91-
self.ROLE_NAME, body=role_content
91+
role=self.ROLE_NAME, body=role_content
9292
)
9393

9494
self.assertNotIn("errors", response)
@@ -99,26 +99,26 @@ async def test_delete_role(self) -> None:
9999
await self.test_create_role()
100100

101101
# Test to delete the role
102-
response = await self.client.security.delete_role(self.ROLE_NAME)
102+
response = await self.client.security.delete_role(role=self.ROLE_NAME)
103103

104104
self.assertNotIn("errors", response)
105105

106106
# Try fetching the role
107107
with self.assertRaises(NotFoundError):
108-
response = await self.client.security.get_role(self.ROLE_NAME)
108+
response = await self.client.security.get_role(role=self.ROLE_NAME)
109109

110110
async def test_create_user(self) -> None:
111111
# Test to create user
112112
response = await self.client.security.create_user(
113-
self.USER_NAME, body=self.USER_CONTENT
113+
username=self.USER_NAME, body=self.USER_CONTENT
114114
)
115115

116116
self.assertNotIn("errors", response)
117117
self.assertIn(response.get("status"), ["CREATED", "OK"])
118118

119119
async def test_create_user_with_body_param_empty(self) -> None:
120120
try:
121-
await self.client.security.create_user(self.USER_NAME, body="")
121+
await self.client.security.create_user(username=self.USER_NAME, body="")
122122
except ValueError as error:
123123
assert str(error) == "Empty value passed for a required argument."
124124
else:
@@ -129,7 +129,7 @@ async def test_create_user_with_role(self) -> None:
129129

130130
# Test to create user
131131
response = await self.client.security.create_user(
132-
self.USER_NAME,
132+
username=self.USER_NAME,
133133
body={
134134
"password": "opensearchpy@123",
135135
"opendistro_security_roles": [self.ROLE_NAME],
@@ -158,7 +158,7 @@ async def test_update_user(self) -> None:
158158

159159
# Test to update user
160160
response = await self.client.security.create_user(
161-
self.USER_NAME, body=user_content
161+
username=self.USER_NAME, body=user_content
162162
)
163163

164164
self.assertNotIn("errors", response)

0 commit comments

Comments
 (0)