diff --git a/azure-common/testutils/create_credentials_file.py b/azure-common/testutils/create_credentials_file.py deleted file mode 100644 index 4b5e96c8f750..000000000000 --- a/azure-common/testutils/create_credentials_file.py +++ /dev/null @@ -1,123 +0,0 @@ -#------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -#-------------------------------------------------------------------------- - -# This script creates the credentials_real.json file in the tests folder -# which is required when running live tests. - -# You should create a new user with global admin rights in your AAD -# and pass that to this script, along with the password and subscription id. -# If you've just created the user, make sure to login using the portal first -# before using this script, because Azure requires you to create a new -# password on first login. - -import argparse -import json -import os.path -import requests -import getpass - -try: - input = raw_input -except: - pass - - -def get_token(username, password): - # the client id we can borrow from azure xplat cli - client_id = '04b07795-8ddb-461a-bbee-02f9e1bf7b46' - grant_type = 'password' - resource = 'https://management.core.windows.net/' - token_url = 'https://login.windows.net/common/oauth2/token' - - payload = { - 'grant_type': grant_type, - 'client_id': client_id, - 'username': username, - 'password': password, - 'resource': resource, - } - response = requests.post(token_url, data=payload).json() - return response['access_token'] - - -front_url = "https://management.azure.com" -front_api_version = "2014-01-01" - -def get_tenant_ids(auth_header): - response = requests.get( - "{}/tenants?api-version={}".format(front_url, front_api_version), - headers={ - 'Authorization': auth_header, - } - ).json() - - ids = [item['tenantId'] for item in response['value']] - return ids - - -def get_subscription_ids(auth_header): - response = requests.get( - "{}/subscriptions?api-version={}".format(front_url, front_api_version), - headers={ - 'Authorization': auth_header, - } - ).json() - - ids = [item['subscriptionId'] for item in response['value']] - return ids - - -def choose_subscription(auth_header): - # TODO: this doesn't work, we'll need ADAL for this - # tenants = get_tenant_ids(auth_header) - # print('tenants: {}'.format(tenants)) - - # subs = get_subscription_ids(auth_header) - # print('subs: {}'.format(subs)) - - # for now just ask the user to type it - return input('Enter subscription id:') - - -def write_credentials_file(sub_id, token): - folder = os.path.dirname(__file__) - path = os.path.join(folder, 'credentials_real.json') - credentials = { - 'subscriptionid': sub_id, - 'authorization_header': 'Bearer {}'.format(token), - } - - with open(path, 'w') as f: - f.write(json.dumps(credentials)) - - return path - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('-u', '--user', help='User name. Ex: username@mylogin.onmicrosoft.com') - parser.add_argument('-p', '--password', help='User password') - parser.add_argument('-s', '--subscription', help='Subscription id. Ex: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee') - args = parser.parse_args() - - username = args.user - password = args.password - sub_id = args.subscription - - if not username: - username = input('Enter username:') - - if not password: - password = getpass.getpass('Enter password:') - - token = get_token(username, password) - - if not sub_id: - auth_header = 'Bearer {}'.format(token) - sub_id = choose_subscription(auth_header) - - creds_path = write_credentials_file(sub_id, token) - print('Credentials written to {}'.format(creds_path)) diff --git a/azure-mgmt-billing/tests/test_mgmt_billing.py b/azure-mgmt-billing/tests/test_mgmt_billing.py index 606c42cd905a..5b7cd1b4d15d 100644 --- a/azure-mgmt-billing/tests/test_mgmt_billing.py +++ b/azure-mgmt-billing/tests/test_mgmt_billing.py @@ -8,7 +8,6 @@ import unittest import azure.mgmt.billing -from testutils.common_recordingtestcase import record from devtools_testutils import AzureMgmtTestCase class MgmtBillingTest(AzureMgmtTestCase): @@ -25,7 +24,7 @@ def _validate_invoice(self, invoice, url_generated=False): self.assertIsNotNone(invoice.download_url.expiry_time) else: self.assertIsNone(invoice.download_url) - + def _validate_billing_period(self, billing_period): self.assertIsNotNone(billing_period) self.assertIsNotNone(billing_period.id) @@ -44,41 +43,41 @@ def test_billing_enrollment_accounts_list(self): def test_billing_invoice_latest(self): output = self.billing_client.invoices.get_latest() self._validate_invoice(output, url_generated=True) - + def test_billing_invoice_list_get(self): output = list(self.billing_client.invoices.list()) self.assertTrue(len(output) > 0) self._validate_invoice(output[0], url_generated=False) invoice = self.billing_client.invoices.get(output[0].name) self._validate_invoice(invoice, url_generated=True) - + def test_billing_invoice_list_generate_url(self): output = list(self.billing_client.invoices.list(expand='downloadUrl')) self.assertTrue(len(output) > 0) self._validate_invoice(output[0], url_generated=True) - + def test_billing_invoice_list_top(self): output = list(self.billing_client.invoices.list(expand='downloadUrl', top=1)) self.assertEqual(1, len(output)) self._validate_invoice(output[0], url_generated=True) - + def test_billing_invoice_list_filter(self): output = list(self.billing_client.invoices.list(filter='invoicePeriodEndDate gt 2017-02-01')) self.assertTrue(len(output) > 0) self._validate_invoice(output[0], url_generated=False) - + def test_billing_period_list_get(self): output = list(self.billing_client.billing_periods.list()) self.assertTrue(len(output) > 0) self._validate_billing_period(output[0]) billing_period = self.billing_client.billing_periods.get(output[0].name) self._validate_billing_period(billing_period) - + def test_billing_period_list_top(self): output = list(self.billing_client.billing_periods.list(top=1)) self.assertEqual(1, len(output)) self._validate_billing_period(output[0]) - + def test_billing_period_list_filter(self): output = list(self.billing_client.billing_periods.list(filter='billingPeriodEndDate gt 2017-02-01')) self.assertTrue(len(output) > 0) diff --git a/azure-mgmt-network/tests/test_mgmt_network.py b/azure-mgmt-network/tests/test_mgmt_network.py index 4c5dba8c58b4..09bcd780055e 100644 --- a/azure-mgmt-network/tests/test_mgmt_network.py +++ b/azure-mgmt-network/tests/test_mgmt_network.py @@ -8,7 +8,6 @@ import unittest import azure.mgmt.network.models -from testutils.common_recordingtestcase import record from devtools_testutils import ( AzureMgmtTestCase, ResourceGroupPreparer, @@ -70,7 +69,7 @@ def test_network_interface_card(self, resource_group, location): resource_group.name, nic_info.name ) - + nics = list(self.network_client.network_interfaces.list( resource_group.name )) @@ -637,7 +636,7 @@ def test_express_route_circuit(self, resource_group, location): 'AzurePublicPeering', { "peering_type": "AzurePublicPeering", - "peer_asn": 100, + "peer_asn": 100, "primary_peer_address_prefix": "192.168.1.0/30", "secondary_peer_address_prefix": "192.168.2.0/30", "vlan_id": 200, diff --git a/azure-mgmt-subscription/tests/test_mgmt_subscription.py b/azure-mgmt-subscription/tests/test_mgmt_subscription.py index c1046fec2f39..677dc183e539 100644 --- a/azure-mgmt-subscription/tests/test_mgmt_subscription.py +++ b/azure-mgmt-subscription/tests/test_mgmt_subscription.py @@ -9,7 +9,6 @@ import azure.mgmt.billing import azure.mgmt.subscription -from testutils.common_recordingtestcase import record from devtools_testutils import AzureMgmtTestCase class MgmtSubscriptionTest(AzureMgmtTestCase):