Rudimentary tests to validate mocking
This commit is contained in:
parent
99e306e602
commit
63ea7db390
@ -488,21 +488,21 @@ class AzureCloudProvider(CloudProviderInterface):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Create role assignment for
|
# Create role assignment for
|
||||||
role_assignment_id = uuid.uuid4()
|
role_assignment_id = str(uuid4())
|
||||||
role_assignment_create_params = auth_client.role_assignments.models.RoleAssignmentCreateParameters(
|
role_assignment_create_params = auth_client.role_assignments.models.RoleAssignmentCreateParameters(
|
||||||
role_definition_id=REMOTE_ROOT_ROLE_DEF_ID,
|
role_definition_id=REMOTE_ROOT_ROLE_DEF_ID,
|
||||||
principal_id=managment_principal.id,
|
principal_id=managment_principal.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.sdk.authorization.models.RoleAssignment = auth_client.role_assignments.create(
|
auth_client.role_assignments.create(
|
||||||
scope=f"/subscriptions/{subscription.id}/",
|
scope=f"/subscriptions/{subscription.id}/",
|
||||||
role_assignment_name=role_assignment_id,
|
role_assignment_name=role_assignment_id,
|
||||||
parameters=role_assignment_create_params,
|
parameters=role_assignment_create_params,
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"csp_user_id": service_principal.object_id,
|
"csp_user_id": managment_principal.object_id,
|
||||||
"credentials": service_principal.password_credentials,
|
"credentials": managment_principal.password_credentials,
|
||||||
"role_name": role_assignment_id,
|
"role_name": role_assignment_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import Mock
|
from unittest.mock import Mock
|
||||||
|
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
from atst.domain.csp.cloud import EnvironmentCreationException, AzureCloudProvider
|
from atst.domain.csp.cloud import EnvironmentCreationException, AzureCloudProvider
|
||||||
from atst.jobs import (
|
from atst.jobs import (
|
||||||
do_create_environment,
|
do_create_environment,
|
||||||
@ -13,4 +15,30 @@ from tests.factories import EnvironmentFactory
|
|||||||
|
|
||||||
|
|
||||||
def test_create_environment_succeeds(mock_azure: AzureCloudProvider):
|
def test_create_environment_succeeds(mock_azure: AzureCloudProvider):
|
||||||
print(mock_azure._get_credential_obj(mock_azure._root_creds))
|
environment = EnvironmentFactory.create()
|
||||||
|
|
||||||
|
subscription_id = str(uuid4())
|
||||||
|
|
||||||
|
mock_azure.sdk.subscription.SubscriptionClient.return_value.subscription_factory.create_subscription.return_value.result.return_value.subscription_link = (
|
||||||
|
f"subscriptions/{subscription_id}"
|
||||||
|
)
|
||||||
|
|
||||||
|
result = mock_azure.create_environment(
|
||||||
|
AUTH_CREDENTIALS, environment.creator, environment
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result == subscription_id
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_atat_admin_user_succeeds(mock_azure: AzureCloudProvider):
|
||||||
|
environment_id = str(uuid4())
|
||||||
|
|
||||||
|
csp_user_id = str(uuid4)
|
||||||
|
|
||||||
|
mock_azure.sdk.graphrbac.GraphRbacManagementClient.return_value.service_principals.create.return_value.object_id = (
|
||||||
|
csp_user_id
|
||||||
|
)
|
||||||
|
|
||||||
|
result = mock_azure.create_atat_admin_user(AUTH_CREDENTIALS, environment_id)
|
||||||
|
|
||||||
|
assert result.get("csp_user_id") == csp_user_id
|
||||||
|
@ -19,9 +19,7 @@ AUTH_CREDENTIALS = {
|
|||||||
def mock_subscription():
|
def mock_subscription():
|
||||||
from azure.mgmt import subscription
|
from azure.mgmt import subscription
|
||||||
|
|
||||||
sub_mock = Mock(spec=subscription)
|
return Mock(spec=subscription)
|
||||||
|
|
||||||
return sub_mock
|
|
||||||
|
|
||||||
|
|
||||||
def mock_authorization():
|
def mock_authorization():
|
||||||
@ -39,8 +37,7 @@ def mock_graphrbac():
|
|||||||
def mock_credentials():
|
def mock_credentials():
|
||||||
import azure.common.credentials as credentials
|
import azure.common.credentials as credentials
|
||||||
|
|
||||||
cred_mock = Mock(spec=credentials)
|
return Mock(spec=credentials)
|
||||||
return cred_mock
|
|
||||||
|
|
||||||
|
|
||||||
class MockAzureSDK(object):
|
class MockAzureSDK(object):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user