Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions rapyuta_io_sdk_v2/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import httpx
from munch import Munch
from yaml import safe_load

from rapyuta_io_sdk_v2.config import Configuration
from rapyuta_io_sdk_v2.utils import handle_and_munchify_response, handle_server_errors
Expand Down Expand Up @@ -1235,15 +1236,14 @@ async def commit_revision(
json=config_tree_revision,
)

@handle_and_munchify_response
async def get_key_in_revision(
self,
tree_name: str,
revision_id: str,
key: str,
project_guid: str = None,
**kwargs,
) -> Munch:
):
"""Get a key in a revision.

Args:
Expand All @@ -1256,10 +1256,14 @@ async def get_key_in_revision(
Munch: Key details as a Munch object.
"""

return await self.c.get(
result = await self.c.get(
url=f"{self.v2api_host}/v2/configtrees/{tree_name}/revisions/{revision_id}/{key}/",
headers=self.config.get_headers(project_guid=project_guid, **kwargs),
)
# The data received from the API is always in string format. To use
# appropriate data-type in Python (as well in exports), we are
# passing it through YAML parser.
return safe_load(result.text)

@handle_and_munchify_response
async def put_key_in_revision(
Expand Down
12 changes: 8 additions & 4 deletions rapyuta_io_sdk_v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import httpx
from munch import Munch
from yaml import safe_load

from rapyuta_io_sdk_v2.config import Configuration
from rapyuta_io_sdk_v2.utils import handle_and_munchify_response, handle_server_errors
Expand Down Expand Up @@ -1218,15 +1219,14 @@ def commit_revision(
json=config_tree_revision,
)

@handle_and_munchify_response
def get_key_in_revision(
self,
tree_name: str,
revision_id: str,
key: str,
project_guid: str = None,
**kwargs,
) -> Munch:
):
"""Get a key in a revision.

Args:
Expand All @@ -1239,10 +1239,14 @@ def get_key_in_revision(
Munch: Key details as a Munch object.
"""

return self.c.get(
url=f"{self.v2api_host}/v2/configtrees/{tree_name}/revisions/{revision_id}/{key}/",
result = self.c.get(
url=f"{self.v2api_host}/v2/configtrees/{tree_name}/revisions/{revision_id}/{key}",
headers=self.config.get_headers(project_guid=project_guid, **kwargs),
)
# The data received from the API is always in string format. To use
# appropriate data-type in Python (as well in exports), we are
# passing it through YAML parser.
return safe_load(result.text)

@handle_and_munchify_response
def put_key_in_revision(
Expand Down
48 changes: 39 additions & 9 deletions tests/async_tests/test_configtree_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,27 +276,57 @@ async def test_commit_revision_success(client, mocker: AsyncMock): # noqa: F811


@pytest.mark.asyncio
async def test_get_key_in_revision(client, mocker: AsyncMock): # noqa: F811
async def test_get_key_in_revision_str(client, mocker: AsyncMock): # noqa: F811
# Mock the httpx.AsyncClient.get method
mock_get = mocker.patch("httpx.AsyncClient.get")

# Set up the mock response
mock_get.return_value = httpx.Response(
status_code=200,
json={
"metadata": {"guid": "test_revision_guid", "name": "test_revision"},
},
mock_get.return_value = httpx.Response(status_code=200, text="test_value")

# Call the get_key_in_revision method
response = await client.get_key_in_revision(
tree_name="mock_configtree_name", revision_id="mock_revision_id", key="mock_key"
)

# Validate the response
assert isinstance(response, str)
assert response == "test_value"


@pytest.mark.asyncio
async def test_get_key_in_revision_int(client, mocker: AsyncMock): # noqa: F811
# Mock the httpx.AsyncClient.get method
mock_get = mocker.patch("httpx.AsyncClient.get")

# Set up the mock response
mock_get.return_value = httpx.Response(status_code=200, text="999")

# Call the get_key_in_revision method
response = await client.get_key_in_revision(
tree_name="mock_configtree_name", revision_id="mock_revision_id", key="mock_key"
)

# Validate the response
assert isinstance(response, Munch)
assert response.metadata.guid == "test_revision_guid"
assert response.metadata.name == "test_revision"
assert isinstance(response, int)
assert response == 999


@pytest.mark.asyncio
async def test_get_key_in_revision_bool(client, mocker: AsyncMock): # noqa: F811
# Mock the httpx.AsyncClient.get method
mock_get = mocker.patch("httpx.AsyncClient.get")

# Set up the mock response
mock_get.return_value = httpx.Response(status_code=200, text="false")

# Call the get_key_in_revision method
response = await client.get_key_in_revision(
tree_name="mock_configtree_name", revision_id="mock_revision_id", key="mock_key"
)

# Validate the response
assert isinstance(response, bool)
assert not response


@pytest.mark.asyncio
Expand Down
51 changes: 44 additions & 7 deletions tests/sync_tests/test_configtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,14 @@ def test_commit_revision_success(client, mocker: MockFixture): # noqa: F811
assert response.metadata.name == "test_revision"


def test_get_key_in_revision(client, mocker: MockFixture): # noqa: F811
def test_get_key_in_revision_str(client, mocker: MockFixture): # noqa: F811
# Mock the httpx.Client.get method
mock_get = mocker.patch("httpx.Client.get")

# Set up the mock response
mock_get.return_value = httpx.Response(
status_code=200,
json={
"metadata": {"guid": "test_revision_guid", "name": "test_revision"},
},
text="test_value",
)

# Call the get_key_in_revision method
Expand All @@ -276,9 +274,48 @@ def test_get_key_in_revision(client, mocker: MockFixture): # noqa: F811
)

# Validate the response
assert isinstance(response, Munch)
assert response.metadata.guid == "test_revision_guid"
assert response.metadata.name == "test_revision"
assert isinstance(response, str)
assert response == "test_value"


def test_get_key_in_revision_int(client, mocker: MockFixture): # noqa: F811
# Mock the httpx.Client.get method
mock_get = mocker.patch("httpx.Client.get")

# Set up the mock response
mock_get.return_value = httpx.Response(
status_code=200,
text="1500",
)

# Call the get_key_in_revision method
response = client.get_key_in_revision(
tree_name="mock_configtree_name", revision_id="mock_revision_id", key="mock_key"
)

# Validate the response
assert isinstance(response, int)
assert response == 1500


def test_get_key_in_revision_bool(client, mocker: MockFixture): # noqa: F811
# Mock the httpx.Client.get method
mock_get = mocker.patch("httpx.Client.get")

# Set up the mock response
mock_get.return_value = httpx.Response(
status_code=200,
text="true",
)

# Call the get_key_in_revision method
response = client.get_key_in_revision(
tree_name="mock_configtree_name", revision_id="mock_revision_id", key="mock_key"
)

# Validate the response
assert isinstance(response, bool)
assert response


def test_put_key_in_revision_success(client, mocker: MockFixture): # noqa: F811
Expand Down