Skip to content

Commit

Permalink
SIMPLE-7496 Deprecated get_diagnostics with no args (#139)
Browse files Browse the repository at this point in the history
* SIMPLE-7496 Deprecated get_diagnostics with no args

Removed unused group permissions

Renamed modules (no need to use plural)

Fixed indents in docstrings and docstring themselves in a couple of modules
  • Loading branch information
tmikuska authored Feb 28, 2025
1 parent c310fb2 commit 2801b6e
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 208 deletions.
170 changes: 85 additions & 85 deletions poetry.lock

Large diffs are not rendered by default.

61 changes: 32 additions & 29 deletions tests/test_client_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from virl2_client.virl2_client import (
ClientConfig,
ClientLibrary,
DiagnosticCategory,
DiagnosticsCategory,
InitializationError,
Version,
)
Expand Down Expand Up @@ -730,38 +730,41 @@ def test_convergence_parametrization(client_library_server_current, mocked_sessi


@pytest.mark.parametrize(
"categories, expected_paths",
"categories",
[
(None, [diag.value for diag in DiagnosticCategory]),
([DiagnosticCategory.COMPUTES], [DiagnosticCategory.COMPUTES.value]),
(
[DiagnosticCategory.LABS, DiagnosticCategory.SERVICES],
[DiagnosticCategory.LABS.value, DiagnosticCategory.SERVICES.value],
),
(),
[DiagnosticsCategory.ALL],
[DiagnosticsCategory.COMPUTES],
[DiagnosticsCategory.LABS, DiagnosticsCategory.SERVICES],
[DiagnosticsCategory.ALL, DiagnosticsCategory.COMPUTES],
],
)
def test_get_diagnostics_paths(client_library, categories, expected_paths):
with respx.mock(base_url="https://0.0.0.0/api/v0/") as respx_mock:
for path in expected_paths:
respx_mock.get(f"diagnostics/{path}").mock(
return_value=httpx.Response(200, json={"data": "sample"})
)
diagnostics_data = client_library.get_diagnostics(categories=categories)
for path in expected_paths:
assert path in diagnostics_data
assert diagnostics_data[path] == {"data": "sample"}
@pytest.mark.parametrize("valid", [True, False])
def test_get_diagnostics_paths(
client_library: ClientLibrary, categories: list[DiagnosticsCategory], valid: bool
):
data = {"data": "sample"}
if valid:
return_value = httpx.Response(200, json=data)
else:
return_value = httpx.Response(404)

expected_categories = categories
if not categories or DiagnosticsCategory.ALL in categories:
expected_categories = list(DiagnosticsCategory)[1:]

def test_get_diagnostics_error_handling(client_library):
with respx.mock(base_url="https://0.0.0.0/api/v0/") as respx_mock:
for diag_type in DiagnosticCategory:
respx_mock.get(f"diagnostics/{diag_type.value}").mock(
return_value=httpx.Response(404)
for category in expected_categories:
respx_mock.get(f"diagnostics/{category.value}").mock(
return_value=return_value
)

diagnostics_data = client_library.get_diagnostics()

for diag_type in DiagnosticCategory:
assert diagnostics_data[diag_type.value] == {
"error": f"Failed to fetch {diag_type.value} diagnostics"
}
if categories:
diagnostics_data = client_library.get_diagnostics(*categories)
else:
with pytest.deprecated_call():
diagnostics_data = client_library.get_diagnostics(*categories)

for category in expected_categories:
if not valid:
data = {"error": f"Failed to fetch {category.value} diagnostics"}
assert diagnostics_data[category.value] == data
2 changes: 1 addition & 1 deletion tests/test_image_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import pytest

from virl2_client.exceptions import InvalidImageFile
from virl2_client.models.node_image_definitions import NodeImageDefinitions
from virl2_client.models import NodeImageDefinitions

WRONG_FORMAT_LIST = [
"",
Expand Down
8 changes: 4 additions & 4 deletions virl2_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
from .annotation import Annotation
from .auth_management import AuthManagement
from .authentication import TokenAuth
from .groups import GroupManagement
from .group import GroupManagement
from .interface import Interface
from .lab import Lab
from .licensing import Licensing
from .link import Link
from .node import Node
from .node_image_definitions import NodeImageDefinitions
from .resource_pools import ResourcePoolManagement
from .node_image_definition import NodeImageDefinitions
from .resource_pool import ResourcePoolManagement
from .smart_annotation import SmartAnnotation
from .system import SystemManagement
from .users import UserManagement
from .user import UserManagement

__all__ = (
"Interface",
Expand Down
2 changes: 1 addition & 1 deletion virl2_client/models/auth_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from ..exceptions import MethodNotActive
from ..utils import get_url_from_template
from .resource_pools import ResourcePool
from .resource_pool import ResourcePool

if TYPE_CHECKING:
from httpx import Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def create_group(
description: str = "",
members: list[str] | None = None,
labs: list[dict[str, str]] | None = None,
permissions: str | None = None,
) -> dict:
"""
Create a group.
Expand All @@ -95,15 +94,13 @@ def create_group(
:param description: The description of the group.
:param members: The members of the group.
:param labs: The labs associated with the group.
:param permissions: Group permissions.
:returns: The created group object.
"""
data = {"name": name}
optional_data = {
"description": description,
"members": members,
"labs": labs,
"permissions": permissions,
}
for key, value in optional_data.items():
if value:
Expand All @@ -118,7 +115,6 @@ def update_group(
description: str | None = None,
members: list[str] | None = None,
labs: list[dict[str, str]] | None = None,
permissions: str | None = None,
) -> dict:
"""
Update a group.
Expand All @@ -128,7 +124,6 @@ def update_group(
:param description: The description of the group.
:param members: The members of the group.
:param labs: The labs associated with the group.
:param permissions: Group permissions.
:returns: The updated group object.
"""
data: dict[str, str | list] = {}
Expand All @@ -140,8 +135,6 @@ def update_group(
data["members"] = members
if labs is not None:
data["labs"] = labs
if permissions is not None:
data["permissions"] = permissions
url = self._url_for("group", group_id=group_id)
return self._session.patch(url, json=data).json()

Expand Down
Loading

0 comments on commit 2801b6e

Please sign in to comment.