Skip to content

Commit

Permalink
Adding tests for generate recommendations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Prasanna-Padmanabhan committed Oct 31, 2017
1 parent aa46713 commit 0b5098d
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
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
68 changes: 68 additions & 0 deletions azure-mgmt-advisor/tests/test_mgmt_advisor.py
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()

0 comments on commit 0b5098d

Please sign in to comment.