Update AADP Purchase url and respose format to newer schema.

This commit is contained in:
tomdds 2020-01-31 15:38:03 -05:00
parent a0ea3e3220
commit bbed83d897
2 changed files with 20 additions and 30 deletions

View File

@ -539,7 +539,7 @@ class AzureCloudProvider(CloudProviderInterface):
"Authorization": f"Bearer {sp_token}", "Authorization": f"Bearer {sp_token}",
} }
product_purchase_url = f"https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{payload.billing_account_name}/billingProfiles/{payload.billing_profile_name}/products?api-version=2019-10-01-preview" product_purchase_url = f"https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{payload.billing_account_name}/billingProfiles/{payload.billing_profile_name}/purchaseProduct?api-version=2019-10-01-preview"
result = self.sdk.requests.post( result = self.sdk.requests.post(
product_purchase_url, product_purchase_url,
@ -577,9 +577,7 @@ class AzureCloudProvider(CloudProviderInterface):
# 202 has location/retry after headers # 202 has location/retry after headers
return self._ok(ProductPurchaseCSPResult(**result.headers)) return self._ok(ProductPurchaseCSPResult(**result.headers))
elif result.status_code == 200: elif result.status_code == 200:
premium_purchase_date = result.json()["product"]["properties"][ premium_purchase_date = result.json()["properties"]["purchaseDate"]
"purchaseDate"
]
return self._ok( return self._ok(
ProductPurchaseVerificationCSPResult( ProductPurchaseVerificationCSPResult(
premium_purchase_date=premium_purchase_date premium_purchase_date=premium_purchase_date

View File

@ -484,32 +484,24 @@ def test_create_product_purchase_verification(mock_azure):
mock_result = Mock() mock_result = Mock()
mock_result.status_code = 200 mock_result.status_code = 200
mock_result.json.return_value = { mock_result.json.return_value = {
"status": "string", "id": "/providers/Microsoft.Billing/billingAccounts/BILLINGACCOUNTNAME/billingProfiles/BILLINGPROFILENAME/invoiceSections/INVOICESECTION/products/29386e29-a025-faae-f70b-b1cbbc266600",
"product": { "name": "29386e29-a025-faae-f70b-b1cbbc266600",
"id": "string", "properties": {
"name": "string", "availabilityId": "C07TTFC7Q9XK",
"type": "string", "billingProfileId": "/providers/Microsoft.Billing/billingAccounts/BILLINGACCOUNTNAME/billingProfiles/BILLINGPROFILENAME",
"properties": { "billingProfileDisplayName": "ATAT Billing Profile",
"displayName": "string", "endDate": "01/30/2021",
"purchaseDate": "2020-01-30T18:57:05.981Z", "invoiceSectionId": "/providers/Microsoft.Billing/billingAccounts/BILLINGACCOUNTNAME/billingProfiles/BILLINGPROFILENAME/invoiceSections/INVOICESECTION",
"productTypeId": "string", "invoiceSectionDisplayName": "ATAT Billing Profile",
"productType": "string", "productType": "Azure Active Directory Premium P1",
"status": "Active", "productTypeId": "C07TTFC7Q9XK",
"endDate": "2020-01-30T18:57:05.981Z", "skuId": "0002",
"billingFrequency": "OneTime", "skuDescription": "Azure Active Directory Premium P1",
"lastCharge": {"currency": "string", "value": 0}, "purchaseDate": "01/31/2020",
"lastChargeDate": "2020-01-30T18:57:05.981Z", "quantity": 5,
"quantity": 0, "status": "AutoRenew",
"skuId": "string",
"skuDescription": "string",
"availabilityId": "string",
"parentProductId": "string",
"invoiceSectionId": "string",
"invoiceSectionDisplayName": "string",
"billingProfileId": "string",
"billingProfileDisplayName": "string",
},
}, },
"type": "Microsoft.Billing/billingAccounts/billingProfiles/invoiceSections/products",
} }
mock_azure.sdk.requests.get.return_value = mock_result mock_azure.sdk.requests.get.return_value = mock_result
@ -523,7 +515,7 @@ def test_create_product_purchase_verification(mock_azure):
result = mock_azure.create_product_purchase_verification(payload) result = mock_azure.create_product_purchase_verification(payload)
body: ProductPurchaseVerificationCSPResult = result.get("body") body: ProductPurchaseVerificationCSPResult = result.get("body")
assert body.premium_purchase_date == "2020-01-30T18:57:05.981Z" assert body.premium_purchase_date == "01/31/2020"
def test_create_tenant_principal_app(mock_azure: AzureCloudProvider): def test_create_tenant_principal_app(mock_azure: AzureCloudProvider):