Sample create and validate billing profile integration

Adds 2 methods to the azure csp interface to create and subsequently validate creation of the billing profile.
This commit is contained in:
tomdds
2020-01-13 16:48:05 -05:00
parent 7c22922d6d
commit 161462f3cb
2 changed files with 204 additions and 79 deletions

View File

@@ -7,6 +7,11 @@ from atst.domain.csp.cloud import (
AzureCloudProvider,
TenantCSPResult,
TenantCSPPayload,
BillingProfileCSPPayload,
BillingProfileAddress,
BillingProfileCreateCSPResult,
BillingProfileVerifyCSPPayload,
BillingProfileCSPResult,
)
from tests.mock_azure import mock_azure, AUTH_CREDENTIALS
@@ -156,3 +161,95 @@ def test_create_tenant(mock_azure: AzureCloudProvider):
print(result)
body: TenantCSPResult = result.get("body")
assert body.tenant_id == "60ff9d34-82bf-4f21-b565-308ef0533435"
def test_create_billing_profile(mock_azure: AzureCloudProvider):
# mock_azure.sdk.adal.AuthenticationContext.return_value.context.acquire_token_with_client_credentials.return_value = {
# "accessToken": "TOKEN"
# }
# mock_result = Mock()
# mock_result.headers = {
# "Location": "http://retry-url",
# "Retry-After": "10",
# }
# mock_result.status_code = 202
# mock_azure.sdk.requests.post.return_value = mock_result
payload = BillingProfileCSPPayload(
**dict(
address=dict(
address_line_1="123 S Broad Street, Suite 2400",
company_name="Promptworks",
city="Philadelphia",
region="PA",
country="US",
postal_code="19109",
),
creds={"username": "mock-cloud", "pass": "shh"},
tenant_id="60ff9d34-82bf-4f21-b565-308ef0533435",
display_name="Test Billing Profile",
)
)
result = mock_azure.create_billing_profile(payload)
print(result)
body: BillingProfileCreateCSPResult = result.get("body")
assert body.retry_after == 10
def test_validate_billing_profile_creation(mock_azure: AzureCloudProvider):
mock_azure.sdk.adal.AuthenticationContext.return_value.context.acquire_token_with_client_credentials.return_value = {
"accessToken": "TOKEN"
}
mock_result = Mock()
mock_result.status_code = 200
mock_result.json.return_value = {
"id": "/providers/Microsoft.Billing/billingAccounts/7c89b735-b22b-55c0-ab5a-c624843e8bf6:de4416ce-acc6-44b1-8122-c87c4e903c91_2019-05-31/billingProfiles/XC36-GRNZ-BG7-TGB",
"name": "XC36-GRNZ-BG7-TGB",
"properties": {
"address": {
"addressLine1": "123 S Broad Street, Suite 2400",
"city": "Philadelphia",
"companyName": "Promptworks",
"country": "US",
"postalCode": "19109",
"region": "PA",
},
"currency": "USD",
"displayName": "First Portfolio Billing Profile",
"enabledAzurePlans": [],
"hasReadAccess": True,
"invoiceDay": 5,
"invoiceEmailOptIn": False,
"invoiceSections": [
{
"id": "/providers/Microsoft.Billing/billingAccounts/7c89b735-b22b-55c0-ab5a-c624843e8bf6:de4416ce-acc6-44b1-8122-c87c4e903c91_2019-05-31/billingProfiles/XC36-GRNZ-BG7-TGB/invoiceSections/6HMZ-2HLO-PJA-TGB",
"name": "6HMZ-2HLO-PJA-TGB",
"properties": {"displayName": "First Portfolio Billing Profile"},
"type": "Microsoft.Billing/billingAccounts/billingProfiles/invoiceSections",
}
],
},
"type": "Microsoft.Billing/billingAccounts/billingProfiles",
}
mock_azure.sdk.requests.get.return_value = mock_result
payload = BillingProfileVerifyCSPPayload(
**dict(
creds={
"username": "username",
"password": "password",
"tenant_id": "tenant_id",
},
location="https://management.azure.com/providers/Microsoft.Billing/billingAccounts/7c89b735-b22b-55c0-ab5a-c624843e8bf6:de4416ce-acc6-44b1-8122-c87c4e903c91_2019-05-31/operationResults/createBillingProfile_478d5706-71f9-4a8b-8d4e-2cbaca27a668?api-version=2019-10-01-preview",
)
)
result = mock_azure.validate_billing_profile_created(payload)
body: BillingProfileCreateCSPResult = result.get("body")
assert body.billing_profile_name == "XC36-GRNZ-BG7-TGB"
assert (
body.billing_profile_properties.display_name
== "First Portfolio Billing Profile"
)