Skip to content

Commit

Permalink
✅ Chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guptadev21 committed Nov 27, 2024
1 parent eae023f commit 6b12de9
Show file tree
Hide file tree
Showing 5 changed files with 904 additions and 4 deletions.
6 changes: 3 additions & 3 deletions rapyuta_io_sdk_v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ def get_configtree(

@handle_and_munchify_response
def set_configtree_revision(
self, name: str, configtree: object, project_guid: str = None, **kwargs
self, name: str, configtree: dict, project_guid: str = None, **kwargs
) -> Munch:
"""Set a config tree revision.
Expand Down Expand Up @@ -1121,7 +1121,7 @@ def commit_revision(
self,
name: str,
revision_id: str,
configTreeRevision: object,
configTreeRevision: dict,
project_guid: str = None,
**kwargs,
) -> Munch:
Expand Down Expand Up @@ -1206,7 +1206,7 @@ def rename_key_in_revision(
name: str,
revision_id: str,
key: str,
configKeyRename: object,
configKeyRename: dict,
project_guid: str = None,
**kwargs,
) -> Munch:
Expand Down
76 changes: 76 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import json
from rapyuta_io_sdk_v2.config import Configuration
from tests.utils.test_util import mock_config # noqa: F401


def test_from_file(mocker):
# Mock configuration file content
mock_config_data = {
"project_id": "mock_project_guid",
"organization_id": "mock_org_guid",
"auth_token": "mock_auth_token",
}
mock_file_content = json.dumps(mock_config_data)

# Mock the open function
mocker.patch("builtins.open", mocker.mock_open(read_data=mock_file_content))

# Mock the default directory function
mocker.patch(
"rapyuta_io_sdk_v2.config.get_default_app_dir", return_value="/mock/default/dir"
)

# Call the method to test
config = Configuration.from_file(file_path="/mock/path/to/config.json")

# Assert the Configuration object contains the expected values
assert config.project_guid == mock_config_data["project_id"]
assert config.organization_guid == mock_config_data["organization_id"]
assert config.auth_token == mock_config_data["auth_token"]


def test_get_headers_basic(mock_config): # noqa: F811
# Call the method without passing any arguments
headers = mock_config.get_headers()

# Verify the headers
assert headers["Authorization"] == "Bearer mock_auth_token"
assert headers["organizationguid"] == "mock_org_guid"
assert headers["project"] == "mock_project_guid"


def test_get_headers_without_project(mock_config): # noqa: F811
# Call the method with `with_project=False`
headers = mock_config.get_headers(with_project=False)

# Verify the headers
assert headers["Authorization"] == "Bearer mock_auth_token"
assert headers["organizationguid"] == "mock_org_guid"
assert "project" not in headers


def test_get_headers_with_custom_values(mock_config): # noqa: F811
# Call the method with custom organization_guid and project_guid
headers = mock_config.get_headers(
organization_guid="custom_org_guid",
project_guid="custom_project_guid",
)

# Verify the headers
assert headers["Authorization"] == "Bearer mock_auth_token"
assert headers["organizationguid"] == "custom_org_guid"
assert headers["project"] == "custom_project_guid"


def test_get_headers_with_request_id(mocker, mock_config): # noqa: F811
# Mock the environment variable
mocker.patch("os.getenv", return_value="mock_request_id")

# Call the method
headers = mock_config.get_headers()

# Verify the headers
assert headers["Authorization"] == "Bearer mock_auth_token"
assert headers["organizationguid"] == "mock_org_guid"
assert headers["project"] == "mock_project_guid"
assert headers["X-Request-ID"] == "mock_request_id"
Loading

0 comments on commit 6b12de9

Please sign in to comment.