merge staging. update create_create_billing_owner azure csp tests

This commit is contained in:
2020-02-11 16:57:37 -05:00
8 changed files with 505 additions and 8 deletions

View File

@@ -23,6 +23,7 @@ from atst.domain.csp.cloud.models import (
ApplicationCSPResult,
BillingInstructionCSPPayload,
BillingInstructionCSPResult,
BillingOwnerCSPPayload,
BillingProfileCreationCSPPayload,
BillingProfileCreationCSPResult,
BillingProfileTenantAccessCSPPayload,
@@ -1276,6 +1277,49 @@ def test_create_user_role_failure(mock_azure: AzureCloudProvider):
mock_azure.create_user_role(payload)
def test_create_billing_owner(mock_azure: AzureCloudProvider):
with patch.object(
AzureCloudProvider,
"_get_tenant_principal_token",
wraps=mock_azure._get_tenant_principal_token,
) as _get_tenant_principal_token:
_get_tenant_principal_token.return_value = "token"
final_result = "1-2-3"
# create_billing_owner does: POST, PATCH, GET, POST
def make_mock_result(return_value=None):
mock_result_create = Mock()
mock_result_create.ok = True
mock_result_create.json.return_value = return_value
return mock_result_create
post_results = [make_mock_result({"id": final_result}), make_mock_result()]
mock_post = lambda *a, **k: post_results.pop(0)
# mock POST so that it pops off results in the order we want
mock_azure.sdk.requests.post = mock_post
# return value for PATCH doesn't matter much
mock_azure.sdk.requests.patch.return_value = make_mock_result()
# return value for GET needs to be a JSON object with a list of role definitions
mock_azure.sdk.requests.get.return_value = make_mock_result(
{"value": [{"displayName": "Billing Administrator", "id": "4567"}]}
)
payload = BillingOwnerCSPPayload(
tenant_id=uuid4().hex,
domain_name="rebelalliance",
password_recovery_email_address="many@bothans.org",
)
result = mock_azure.create_billing_owner(payload)
assert result.billing_owner_id == final_result
def test_update_tenant_creds(mock_azure: AzureCloudProvider):
with patch.object(
AzureCloudProvider, "set_secret", wraps=mock_azure.set_secret,

View File

@@ -8,6 +8,7 @@ from atst.domain.csp.cloud.models import (
ManagementGroupCSPPayload,
ManagementGroupCSPResponse,
UserCSPPayload,
BillingOwnerCSPPayload,
)
@@ -141,3 +142,38 @@ def test_UserCSPPayload_user_principal_name():
def test_UserCSPPayload_password():
payload = UserCSPPayload(**user_payload)
assert payload.password
class TestBillingOwnerCSPPayload:
user_payload = {
"tenant_id": "123",
"domain_name": "rebelalliance",
"password_recovery_email_address": "han@moseisley.cantina",
}
def test_display_name(self):
payload = BillingOwnerCSPPayload(**self.user_payload)
assert payload.display_name == "billing_admin"
def test_tenant_host_name(self):
payload = BillingOwnerCSPPayload(**self.user_payload)
assert payload.tenant_host_name == self.user_payload["domain_name"]
def test_mail_nickname(self):
payload = BillingOwnerCSPPayload(**self.user_payload)
assert payload.mail_nickname == "billing_admin"
def test_password(self):
payload = BillingOwnerCSPPayload(**self.user_payload)
assert payload.password
def test_user_principal_name(self):
payload = BillingOwnerCSPPayload(**self.user_payload)
assert (
payload.user_principal_name
== f"billing_admin@rebelalliance.onmicrosoft.com"
)
def test_email(self):
payload = BillingOwnerCSPPayload(**self.user_payload)
assert payload.email == self.user_payload["password_recovery_email_address"]

View File

@@ -217,6 +217,7 @@ def test_fsm_transition_start(mock_cloud_provider, portfolio: Portfolio):
FSMStates.INITIAL_MGMT_GROUP_VERIFICATION_CREATED,
FSMStates.TENANT_ADMIN_OWNERSHIP_CREATED,
FSMStates.TENANT_PRINCIPAL_OWNERSHIP_CREATED,
FSMStates.BILLING_OWNER_CREATED,
]
if portfolio.csp_data is not None: