Skip to content

Commit

Permalink
feat: add support for version field in the environemtn (#24)
Browse files Browse the repository at this point in the history
added field is `Optional` to be compatible with the version of the BE that does not have it.

PART OF h2oai/cloud-discovery#159
FOLLOW UP FOR h2oai/cloud-discovery#160
  • Loading branch information
zoido committed Feb 27, 2023
1 parent 27cd79a commit e24d060
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/h2o_discovery/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ class Environment:
# define its own scope.
h2o_cloud_platform_oauth2_scope: str

# Version of the H2O Cloud Platform release that is running in the environment.
h2o_cloud_version: Optional[str]

@classmethod
def from_json_dict(cls, json: Mapping[str, str]) -> "Environment":
"""Create an Environment from a JSON dict returned by the server."""
return cls(
h2o_cloud_environment=json["h2oCloudEnvironment"],
issuer_url=json["issuerUrl"],
h2o_cloud_platform_oauth2_scope=json["h2oCloudPlatformOauth2Scope"],
h2o_cloud_version=json.get("h2oCloudVersion"),
)
2 changes: 2 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,15 @@ def _assert_pagination_api_calls(route):
"h2oCloudEnvironment": "https://cloud.fbi.com",
"h2oCloudPlatformOauth2Scope": "openid profile email",
"issuerUrl": "https://phantauth.net",
"h2oCloudVersion": "70.25",
}
}

EXPECTED_ENVIRONMENT_DATA = model.Environment(
h2o_cloud_environment="https://cloud.fbi.com",
h2o_cloud_platform_oauth2_scope="openid profile email",
issuer_url="https://phantauth.net",
h2o_cloud_version="70.25",
)

SERVICES_RESPONSES = [
Expand Down
1 change: 1 addition & 0 deletions tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def mock_client():
h2o_cloud_environment="https://test.example.com",
h2o_cloud_platform_oauth2_scope="test-scope",
issuer_url="https://test.example.com",
h2o_cloud_version="test-version",
)


Expand Down
22 changes: 22 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_environment_from_json_dict():
"h2oCloudEnvironment": "https://test.h2o.ai",
"issuerUrl": "https://test.h2o.ai",
"h2oCloudPlatformOauth2Scope": "test-platform-scope",
"h2oCloudVersion": "test-version",
}

# When
Expand All @@ -61,4 +62,25 @@ def test_environment_from_json_dict():
h2o_cloud_environment="https://test.h2o.ai",
issuer_url="https://test.h2o.ai",
h2o_cloud_platform_oauth2_scope="test-platform-scope",
h2o_cloud_version="test-version",
)


def test_environment_from_json_dict_with_missing_version():
# Given
json = {
"h2oCloudEnvironment": "https://test.h2o.ai",
"issuerUrl": "https://test.h2o.ai",
"h2oCloudPlatformOauth2Scope": "test-platform-scope",
}

# When
result = model.Environment.from_json_dict(json)

# Then
assert result == model.Environment(
h2o_cloud_environment="https://test.h2o.ai",
issuer_url="https://test.h2o.ai",
h2o_cloud_platform_oauth2_scope="test-platform-scope",
h2o_cloud_version=None,
)

0 comments on commit e24d060

Please sign in to comment.