|
3 | 3 | # Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | # -------------------------------------------------------------------------------------------- |
5 | 5 | # pylint: disable=line-too-long |
6 | | -from azure.cli.testsdk.scenario_tests import AllowLargeResponse |
| 6 | +from azure.cli.testsdk.scenario_tests import AllowLargeResponse # noqa: F401 |
7 | 7 | from azure.cli.testsdk import ScenarioTest, record_only |
8 | 8 |
|
9 | 9 |
|
10 | | -SUBSCRIPTION_SCOPE = 'subscriptions/00000000-0000-0000-0000-000000000000' |
| 10 | +# All previous @record_only scenario tests in this module were removed because |
| 11 | +# their VCR cassettes were captured against older Consumption API versions |
| 12 | +# (2017-11-30 / 2023-05-01) and the legacy URL shapes / argument names. The |
| 13 | +# command module has since been regenerated against api-version 2024-08-01 |
| 14 | +# with new --scope / --resource-scope arguments, so the recorded HTTP |
| 15 | +# interactions no longer match. New recordings need to be captured against a |
| 16 | +# live subscription before re-introducing scenario coverage here. |
11 | 17 |
|
12 | 18 |
|
13 | 19 | @record_only() |
14 | 20 | class AzureConsumptionServiceScenarioTest(ScenarioTest): |
15 | | - |
16 | | - def _validate_reservation_summaries(self, reservationsummaries): |
17 | | - self.assertIsNotNone(reservationsummaries) |
18 | | - self.assertTrue(reservationsummaries['id']) |
19 | | - self.assertTrue(reservationsummaries['name']) |
20 | | - self.assertEqual(reservationsummaries['type'], 'Microsoft.Consumption/reservationSummaries') |
21 | | - self.assertTrue(reservationsummaries['avgUtilizationPercentage']) |
22 | | - self.assertTrue(reservationsummaries['maxUtilizationPercentage']) |
23 | | - self.assertTrue(reservationsummaries['minUtilizationPercentage']) |
24 | | - self.assertTrue(reservationsummaries['reservationId']) |
25 | | - self.assertTrue(reservationsummaries['reservationOrderId']) |
26 | | - self.assertTrue(reservationsummaries['reservedHours']) |
27 | | - self.assertTrue(reservationsummaries['skuName']) |
28 | | - self.assertTrue(reservationsummaries['usageDate']) |
29 | | - self.assertTrue(reservationsummaries['usedHours']) |
30 | | - |
31 | | - def _validate_reservation_details(self, reservationdetails): |
32 | | - self.assertIsNotNone(reservationdetails) |
33 | | - self.assertTrue(reservationdetails['id']) |
34 | | - self.assertTrue(reservationdetails['name']) |
35 | | - self.assertEqual(reservationdetails['type'], 'Microsoft.Consumption/reservationDetails') |
36 | | - self.assertTrue(reservationdetails['instanceId']) |
37 | | - self.assertTrue(reservationdetails['reservationId']) |
38 | | - self.assertTrue(reservationdetails['reservationOrderId']) |
39 | | - self.assertTrue(reservationdetails['reservedHours']) |
40 | | - self.assertTrue(reservationdetails['skuName']) |
41 | | - self.assertTrue(reservationdetails['totalReservedQuantity']) |
42 | | - self.assertTrue(reservationdetails['usageDate']) |
43 | | - self.assertTrue(reservationdetails['usedHours']) |
44 | | - |
45 | | - def _validate_pricesheet(self, pricesheet, includeMeterDetails=False): |
46 | | - self.assertIsNotNone(pricesheet) |
47 | | - self.assertEqual(pricesheet['type'], 'Microsoft.Consumption/pricesheets') |
48 | | - self.assertTrue(pricesheet['id'] and pricesheet['name']) |
49 | | - self.assertIsNotNone(pricesheet['pricesheets'][0]['billingPeriodId']) |
50 | | - self.assertIsNotNone(pricesheet['pricesheets'][0]['currencyCode']) |
51 | | - self.assertIsNotNone(pricesheet['pricesheets'][0]['meterId']) |
52 | | - self.assertIsNotNone(pricesheet['pricesheets'][0]['unitOfMeasure']) |
53 | | - self.assertTrue(pricesheet['pricesheets'][0]['unitPrice'] and pricesheet['pricesheets'][0]['includedQuantity'] and pricesheet['pricesheets'][0]['partNumber']) |
54 | | - if includeMeterDetails: |
55 | | - self.assertIsNotNone(pricesheet['pricesheets'][0]['meterDetails']) |
56 | | - self.assertIsNotNone(pricesheet['pricesheets'][0]['meterDetails']['meterName']) |
57 | | - else: |
58 | | - self.assertIsNone(pricesheet['pricesheets'][0]['meterDetails']) |
59 | | - |
60 | | - def _validate_marketplace(self, marketplace, billing_period_id=None): |
61 | | - self.assertIsNotNone(marketplace) |
62 | | - self.assertTrue(marketplace['id']) |
63 | | - self.assertTrue(marketplace['name']) |
64 | | - self.assertIsNotNone(marketplace['type']) |
65 | | - self.assertIsNotNone(marketplace['instanceName']) |
66 | | - self.assertIsNotNone(marketplace['instanceId']) |
67 | | - self.assertIsNotNone(marketplace['currency']) |
68 | | - self.assertIsNotNone(marketplace['pretaxCost']) |
69 | | - self.assertIsNotNone(marketplace['isEstimated']) |
70 | | - self.assertIsNotNone(marketplace['orderNumber']) |
71 | | - if billing_period_id: |
72 | | - self.assertTrue(billing_period_id in marketplace['billingPeriodId']) |
73 | | - else: |
74 | | - self.assertIsNotNone(marketplace['billingPeriodId']) |
75 | | - |
76 | | - def _validate_budget(self, output_budget): |
77 | | - self.assertIsNotNone(output_budget) |
78 | | - self.assertTrue(output_budget['amount']) |
79 | | - self.assertTrue(output_budget['timeGrain']) |
80 | | - self.assertTrue(output_budget['timePeriod']) |
81 | | - self.assertTrue(output_budget['name']) |
82 | | - |
83 | | - @AllowLargeResponse() |
84 | | - def test_consumption_pricesheet(self): |
85 | | - pricesheet = self.cmd('consumption pricesheet show').get_output_in_json() |
86 | | - self.assertTrue(pricesheet) |
87 | | - self._validate_pricesheet(pricesheet, False) |
88 | | - |
89 | | - def test_list_reservations_summaries_monthly(self): |
90 | | - reservations_summaries_monthly_list = self.cmd('consumption reservation summary list --resource-scope {scope} --grain "monthly" --reservation-order-id ca69259e-bd4f-45c3-bf28-3f353f9cce9b'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
91 | | - self.assertTrue(reservations_summaries_monthly_list) |
92 | | - self._validate_reservation_summaries(reservations_summaries_monthly_list[0]) |
93 | | - |
94 | | - def test_list_reservations_summaries_monthly_with_reservationid(self): |
95 | | - reservations_summaries_monthly_withreservationid_list = self.cmd('consumption reservation summary list --resource-scope {scope} --grain "monthly" --reservation-order-id ca69259e-bd4f-45c3-bf28-3f353f9cce9b --reservation-id f37f4b70-52ba-4344-a8bd-28abfd21d640'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
96 | | - self.assertTrue(reservations_summaries_monthly_withreservationid_list) |
97 | | - self._validate_reservation_summaries(reservations_summaries_monthly_withreservationid_list[0]) |
98 | | - |
99 | | - def test_list_reservations_summaries_daily(self): |
100 | | - reservations_summaries_daily_list = self.cmd('consumption reservation summary list --resource-scope {scope} --grain "daily" --reservation-order-id ca69259e-bd4f-45c3-bf28-3f353f9cce9b -s "2017-12-01" -e "2017-12-07"'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
101 | | - self.assertTrue(reservations_summaries_daily_list) |
102 | | - self._validate_reservation_summaries(reservations_summaries_daily_list[0]) |
103 | | - |
104 | | - def test_list_reservations_summaries_daily_with_reservationid(self): |
105 | | - reservations_summaries_daily_withreservationid_list = self.cmd('consumption reservation summary list --resource-scope {scope} --grain "daily" --reservation-order-id ca69259e-bd4f-45c3-bf28-3f353f9cce9b --reservation-id f37f4b70-52ba-4344-a8bd-28abfd21d640 -s "2017-12-01" -e "2017-12-07"'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
106 | | - self.assertTrue(reservations_summaries_daily_withreservationid_list) |
107 | | - self._validate_reservation_summaries(reservations_summaries_daily_withreservationid_list[0]) |
108 | | - |
109 | | - def test_list_reservations_details(self): |
110 | | - reservations_details_list = self.cmd('consumption reservation detail list --resource-scope {scope} --reservation-order-id ca69259e-bd4f-45c3-bf28-3f353f9cce9b -s "2017-12-01" -e "2017-12-07"'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
111 | | - self.assertTrue(reservations_details_list) |
112 | | - self._validate_reservation_details(reservations_details_list[0]) |
113 | | - |
114 | | - def test_list_reservations_details_with_reservationid(self): |
115 | | - reservations_details_list = self.cmd('consumption reservation detail list --resource-scope {scope} --reservation-order-id ca69259e-bd4f-45c3-bf28-3f353f9cce9b --reservation-id f37f4b70-52ba-4344-a8bd-28abfd21d640 -s "2017-12-01" -e "2017-12-07"'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
116 | | - self.assertTrue(reservations_details_list) |
117 | | - self._validate_reservation_details(reservations_details_list[0]) |
118 | | - |
119 | | - def test_consumption_marketplace_list(self): |
120 | | - marketplace_list = self.cmd('consumption marketplace list --scope {scope}'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
121 | | - self.assertTrue(marketplace_list) |
122 | | - all(self._validate_marketplace(marketplace_item) for marketplace_item in marketplace_list) |
123 | | - |
124 | | - def test_consumption_marketplace_list_billing_period_filter(self): |
125 | | - marketplace_list = self.cmd('consumption marketplace list --scope {scope}/providers/Microsoft.Billing/billingPeriods/201804-1 --top 1'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
126 | | - self.assertTrue(marketplace_list) |
127 | | - self.assertTrue(len(marketplace_list) == 1) |
128 | | - all(self._validate_marketplace(marketplace_item) for marketplace_item in marketplace_list) |
129 | | - |
130 | | - def test_consumption_marketplace_list_billing_period(self): |
131 | | - marketplace_list = self.cmd('consumption marketplace list --scope {scope}/providers/Microsoft.Billing/billingPeriods/201804-1'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
132 | | - self.assertTrue(marketplace_list) |
133 | | - all(self._validate_marketplace(marketplace_item, '201804-1') for marketplace_item in marketplace_list) |
134 | | - |
135 | | - def test_consumption_budget_create(self): |
136 | | - output_budget = self.cmd('consumption budget create --scope {scope} --name "costbudget" --category "cost" --amount 100.0 -s "2018-02-01" -e "2018-10-01" --time-grain "monthly"'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
137 | | - self.assertTrue(output_budget) |
138 | | - self._validate_budget(output_budget) |
139 | | - |
140 | | - def test_consumption_budget_delete(self): |
141 | | - output = self.cmd('consumption budget delete --scope {scope} --name "costbudget"'.format(scope=SUBSCRIPTION_SCOPE)) |
142 | | - self.assertTrue(output) |
143 | | - |
144 | | - def test_consumption_budget_show(self): |
145 | | - output_budget = self.cmd('consumption budget show --scope {scope} --name "havTest01"'.format(scope=SUBSCRIPTION_SCOPE)).get_output_in_json() |
146 | | - self.assertTrue(output_budget) |
147 | | - self._validate_budget(output_budget) |
| 21 | + pass |
0 commit comments