e68b9e762d
* Added client-level REST helpers. Signed-off-by: dblock <dblock@amazon.com> * Move functions into an .http namespace. Signed-off-by: dblock <dblock@amazon.com> * Poetry update in samples. Signed-off-by: dblock <dblock@amazon.com> * Fix: typo. Signed-off-by: dblock <dblock@amazon.com> * Clarified what to use in which older versions. Signed-off-by: dblock <dblock@amazon.com> --------- Signed-off-by: dblock <dblock@amazon.com>
55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# The OpenSearch Contributors require contributions made to
|
|
# this file be licensed under the Apache-2.0 license or a
|
|
# compatible open source license.
|
|
#
|
|
# Modifications Copyright OpenSearch Contributors. See
|
|
# GitHub history for details.
|
|
|
|
import pytest
|
|
from _pytest.mark.structures import MarkDecorator
|
|
|
|
from .test_client import OpenSearchTestCaseWithDummyTransport
|
|
|
|
pytestmark: MarkDecorator = pytest.mark.asyncio
|
|
|
|
|
|
class TestHttpClient(OpenSearchTestCaseWithDummyTransport):
|
|
async def test_head(self) -> None:
|
|
await self.client.http.head("/")
|
|
self.assert_call_count_equals(1)
|
|
assert [(None, None, None)] == self.assert_url_called("HEAD", "/", 1)
|
|
|
|
async def test_get(self) -> None:
|
|
await self.client.http.get("/")
|
|
self.assert_call_count_equals(1)
|
|
assert [(None, None, None)] == self.assert_url_called("GET", "/", 1)
|
|
|
|
async def test_put(self) -> None:
|
|
await self.client.http.put(url="/xyz", params={"X": "Y"}, body="body")
|
|
self.assert_call_count_equals(1)
|
|
assert [({"X": "Y"}, None, "body")] == self.assert_url_called("PUT", "/xyz", 1)
|
|
|
|
async def test_post(self) -> None:
|
|
await self.client.http.post(url="/xyz", params={"X": "Y"}, body="body")
|
|
self.assert_call_count_equals(1)
|
|
assert [({"X": "Y"}, None, "body")] == self.assert_url_called("POST", "/xyz", 1)
|
|
|
|
async def test_post_with_headers(self) -> None:
|
|
await self.client.http.post(
|
|
url="/xyz", headers={"A": "B"}, params={"X": "Y"}, body="body"
|
|
)
|
|
self.assert_call_count_equals(1)
|
|
assert [({"X": "Y"}, {"A": "B"}, "body")] == self.assert_url_called(
|
|
"POST", "/xyz", 1
|
|
)
|
|
|
|
async def test_delete(self) -> None:
|
|
await self.client.http.delete(url="/xyz", params={"X": "Y"}, body="body")
|
|
self.assert_call_count_equals(1)
|
|
assert [({"X": "Y"}, None, "body")] == self.assert_url_called(
|
|
"DELETE", "/xyz", 1
|
|
)
|