Skip to content

Commit

Permalink
changing mock for urlparse
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitij-microsoft committed Oct 1, 2024
1 parent ae32d9d commit 0ab7bc4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def test_list(self, arg: str, mock_hub_operation: WorkspaceOperations) -> None:
else:
mock_hub_operation._operation.list_by_resource_group.assert_called_once()

def test_get(self, mock_hub_operation: WorkspaceOperations) -> None:
def test_get(self, mock_hub_operation: WorkspaceOperations, mocker: MockFixture) -> None:
mocker.patch("urllib.parse.urlparse")
mock_hub_operation.get(name="random_name")
mock_hub_operation._operation.get.assert_called_once()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ def mock_credential() -> Mock:
yield Mock()


def mock_urlparse(url: str) -> urllib.parse.ParseResult:
return urllib.parse.ParseResult(
scheme="http", netloc="example.com", path="/index.html", params="", query="a=1&b=2", fragment=""
)


urllib.parse.urlparse = mock_urlparse


@pytest.fixture
def mock_workspace_operation(
mock_workspace_scope: OperationScope,
Expand Down Expand Up @@ -97,7 +88,8 @@ def test_list(self, arg: str, mock_workspace_operation: WorkspaceOperations) ->
else:
mock_workspace_operation._operation.list_by_resource_group.assert_called_once()

def test_get(self, mock_workspace_operation: WorkspaceOperations) -> None:
def test_get(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None:
mocker.patch("urllib.parse.urlparse")
mock_workspace_operation.get("random_name")
mock_workspace_operation._operation.get.assert_called_once()

Expand All @@ -124,7 +116,8 @@ def test_begin_create(
mocker.patch("azure.ai.ml._arm_deployments.ArmDeploymentExecutor.deploy_resource", return_value=LROPoller)
mock_workspace_operation.begin_create(workspace=Workspace(name="name"))

def test_update(self, mock_workspace_operation: WorkspaceOperations) -> None:
def test_update(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None:
mocker.patch("urllib.parse.urlparse")
ws = Workspace(
name="name",
description="description",
Expand All @@ -145,6 +138,7 @@ def outgoing_call(rg, name, params, polling, cls):
def test_update_with_role_assignemnt(
self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture
) -> None:
mocker.patch("urllib.parse.urlparse")
mocker.patch(
"azure.ai.ml.operations.WorkspaceOperations._populate_feature_store_role_assignment_parameters",
return_value=({}, {}, {}),
Expand Down Expand Up @@ -173,6 +167,7 @@ def outgoing_call(rg, name, params, polling, cls):
mock_workspace_operation._operation.begin_update.assert_called()

def test_delete(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None:
mocker.patch("urllib.parse.urlparse")
mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None)
mocker.patch(
"azure.ai.ml.operations._workspace_operations_base.get_generic_arm_resource_by_arm_id", return_value=None
Expand All @@ -181,6 +176,7 @@ def test_delete(self, mock_workspace_operation: WorkspaceOperations, mocker: Moc
mock_workspace_operation._operation.begin_delete.assert_called_once()

def test_purge(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None:
mocker.patch("urllib.parse.urlparse")
mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None)
mocker.patch(
"azure.ai.ml.operations._workspace_operations_base.get_generic_arm_resource_by_arm_id", return_value=None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ def mock_credential() -> Mock:
yield Mock()


def mock_urlparse(url: str) -> urllib.parse.ParseResult:
return urllib.parse.ParseResult(
scheme="http", netloc="example.com", path="/index.html", params="", query="a=1&b=2", fragment=""
)


urllib.parse.urlparse = mock_urlparse


@pytest.fixture
def mock_workspace_operation_base(
mock_workspace_scope: OperationScope,
Expand Down Expand Up @@ -188,6 +179,8 @@ def test_create_get_exception_swallow(
def test_begin_create_existing_ws(
self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture
):
mocker.patch("urllib.parse.urlparse")

def outgoing_call(rg, name, params, polling, cls):
assert name == "name"
return DEFAULT
Expand All @@ -197,7 +190,8 @@ def outgoing_call(rg, name, params, polling, cls):
mock_workspace_operation_base.begin_create(workspace=Workspace(name="name"))
mock_workspace_operation_base._operation.begin_update.assert_called()

def test_update(self, mock_workspace_operation_base: WorkspaceOperationsBase) -> None:
def test_update(self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture) -> None:
mocker.patch("urllib.parse.urlparse")
ws = Workspace(
name="name",
tags={"key": "value"},
Expand Down Expand Up @@ -254,6 +248,7 @@ def outgoing_call(rg, name, params, polling, cls):
def test_update_with_empty_property_values(
self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture
) -> None:
mocker.patch("urllib.parse.urlparse")
ws = Workspace(name="name", description="", display_name="", image_build_compute="")
mocker.patch("azure.ai.ml.operations.WorkspaceOperations.get", return_value=ws)

Expand All @@ -277,6 +272,7 @@ def outgoing_call(rg, name, params, polling, cls):
mock_workspace_operation_base._operation.begin_update.assert_called()

def test_delete_no_wait(self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture) -> None:
mocker.patch("urllib.parse.urlparse")
mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None)
mocker.patch(
"azure.ai.ml.operations._workspace_operations_base.get_generic_arm_resource_by_arm_id", return_value=None
Expand All @@ -285,6 +281,7 @@ def test_delete_no_wait(self, mock_workspace_operation_base: WorkspaceOperations
mock_workspace_operation_base._operation.begin_delete.assert_called_once()

def test_delete_wait(self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture) -> None:
mocker.patch("urllib.parse.urlparse")
mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None)
mocker.patch(
"azure.ai.ml.operations._workspace_operations_base.get_generic_arm_resource_by_arm_id", return_value=None
Expand Down Expand Up @@ -610,6 +607,7 @@ def test_update_workspace_with_serverless_custom_vnet(
mock_workspace_operation_base: WorkspaceOperationsBase,
mocker: MockFixture,
) -> None:
mocker.patch("urllib.parse.urlparse")
ws = Workspace(name="name", location="test", serverless_compute=serverless_compute_settings)
spy = mocker.spy(mock_workspace_operation_base._operation, "begin_update")
mock_workspace_operation_base.begin_update(ws)
Expand Down

0 comments on commit 0ab7bc4

Please sign in to comment.