forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for generate recommendations.
- Loading branch information
1 parent
aa46713
commit 0b5098d
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
azure-mgmt-advisor/tests/recordings/test_mgmt_advisor.test_generate_recommendations.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: [application/json] | ||
Accept-Encoding: ['gzip, deflate'] | ||
Connection: [keep-alive] | ||
Content-Length: ['0'] | ||
Content-Type: [application/json; charset=utf-8] | ||
User-Agent: [python/3.6.3 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.18 | ||
msrest_azure/0.4.15 azure-mgmt-advisor/0.1.0 Azure-SDK-For-Python] | ||
accept-language: [en-US] | ||
method: POST | ||
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Advisor/generateRecommendations?api-version=2017-04-19-alpha | ||
response: | ||
body: {string: ''} | ||
headers: | ||
cache-control: [no-cache] | ||
content-length: ['0'] | ||
date: ['Tue, 31 Oct 2017 00:15:48 GMT'] | ||
expires: ['-1'] | ||
location: ['https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Advisor/generateRecommendations/5058f75c-23aa-403f-ab97-1c8a53fcf329?api-version=2017-04-19-alpha'] | ||
pragma: [no-cache] | ||
server: [Microsoft-HTTPAPI/2.0] | ||
strict-transport-security: [max-age=31536000; includeSubDomains] | ||
x-content-type-options: [nosniff] | ||
x-ms-ratelimit-remaining-subscription-writes: ['1199'] | ||
status: {code: 202, message: Accepted} | ||
- request: | ||
body: null | ||
headers: | ||
Accept: [application/json] | ||
Accept-Encoding: ['gzip, deflate'] | ||
Connection: [keep-alive] | ||
Content-Type: [application/json; charset=utf-8] | ||
User-Agent: [python/3.6.3 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.18 | ||
msrest_azure/0.4.15 azure-mgmt-advisor/0.1.0 Azure-SDK-For-Python] | ||
accept-language: [en-US] | ||
method: GET | ||
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Advisor/generateRecommendations/00000000-0000-0000-0000-000000000000?api-version=2017-04-19-alpha | ||
response: | ||
body: {string: ''} | ||
headers: | ||
cache-control: [no-cache] | ||
date: ['Tue, 31 Oct 2017 00:15:49 GMT'] | ||
expires: ['-1'] | ||
pragma: [no-cache] | ||
server: [Microsoft-HTTPAPI/2.0] | ||
strict-transport-security: [max-age=31536000; includeSubDomains] | ||
x-content-type-options: [nosniff] | ||
status: {code: 204, message: No Content} | ||
version: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# coding: utf-8 | ||
|
||
#------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
#-------------------------------------------------------------------------- | ||
import unittest | ||
import datetime | ||
import re | ||
import time | ||
import azure.mgmt.advisor | ||
|
||
from devtools_testutils import ( | ||
AzureMgmtTestCase, ResourceGroupPreparer, | ||
) | ||
|
||
|
||
class MgmtAdvisorTest(AzureMgmtTestCase): | ||
|
||
def setUp(self): | ||
super(MgmtAdvisorTest, self).setUp() | ||
self.client = self.create_mgmt_client( | ||
azure.mgmt.advisor.AdvisorManagementClient | ||
) | ||
|
||
def test_generate_recommendations(self): | ||
# trigger generate recommendations | ||
response = self.client.recommendations.generate(raw=True) | ||
|
||
# verify we got a Location header back | ||
self.assertTrue('Location' in response.headers) | ||
location = response.headers['Location'] | ||
|
||
# extract the operation ID from the Location header | ||
operation_id = re.findall("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", location) | ||
|
||
# verify it is valid | ||
self.assertNotEqual(operation_id, None) | ||
self.assertTrue(len(operation_id), 1) | ||
|
||
status_code = None | ||
max_attempts = 30 | ||
attempt = 0 | ||
|
||
# get generate status until we get back 204 or 30 seconds have passed | ||
while True: | ||
response = self.client.recommendations.get_generate_status( | ||
raw=True, | ||
operation_id = operation_id[0] | ||
) | ||
status_code = response.response.status_code | ||
if (status_code == 204 or attempt >= max_attempts): | ||
break | ||
else: | ||
time.sleep(60) | ||
|
||
print(attempt) | ||
self.assertEqual(status_code, 204) | ||
|
||
def test_list(self): | ||
response = self.client.recommendations.list() | ||
print(response) | ||
self.assertNotEqual(response, None) | ||
|
||
#------------------------------------------------------------------------------ | ||
if __name__ == '__main__': | ||
unittest.main() |