Skip to content

Commit

Permalink
Add remainder of test recordings.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Oct 24, 2016
1 parent 6dd83a5 commit 36cfee2
Show file tree
Hide file tree
Showing 24 changed files with 3,117 additions and 203 deletions.
2 changes: 1 addition & 1 deletion azure-keyvault/azure/keyvault/key_vault_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,5 @@ def get_pending_certificate_signing_request(self, vault_base_url, certificate_na

try:
KeyVaultClient.__doc__ = _KeyVaultClient.__doc__
except AttributeError:
except (AttributeError, TypeError):
pass
104 changes: 8 additions & 96 deletions azure-mgmt/tests/keyvault_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
#--------------------------------------------------------------------------
import json
import os.path
import re
import time

import azure.mgmt.resource
from azure.mgmt.keyvault import KeyVaultManagementClient
from azure.mgmt.keyvault.models import \
(VaultCreateOrUpdateParameters, VaultProperties, Sku, AccessPolicyEntry, Permissions)
from azure.keyvault import KeyVaultClient, KeyVaultAuthentication, HttpBearerChallenge

from azure.common.exceptions import (
Expand All @@ -25,7 +30,6 @@
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())


class HttpStatusCode(object):
OK = 200
Created = 201
Expand Down Expand Up @@ -54,85 +58,11 @@ def mock_key_vault_auth_base(self, request):
import tests.mgmt_settings_real as real_settings
self.settings = real_settings

self.resource_client = self.create_mgmt_client(
azure.mgmt.resource.ResourceManagementClient
)
self.client = self.create_keyvault_client()

# Every test uses a different resource group name calculated from its
# qualified test name.
#
# When running all tests serially, this allows us to delete
# the resource group in teardown without waiting for the delete to
# complete. The next test in line will use a different resource group,
# so it won't have any trouble creating its resource group even if the
# previous test resource group hasn't finished deleting.
#
# When running tests individually, if you try to run the same test
# multiple times in a row, it's possible that the delete in the previous
# teardown hasn't completed yet (because we don't wait), and that
# would make resource group creation fail.
# To avoid that, we also delete the resource group in the
# setup, and we wait for that delete to complete.
self.group_name = self.get_resource_name(
self.qualified_test_name.replace('.', '_')
)
self.region = 'westus'

if not self.is_playback():
self.delete_resource_group(wait_timeout=600)

def tearDown(self):
if not self.is_playback():
self.delete_resource_group(wait_timeout=None)
return super(AzureKeyVaultTestCase, self).tearDown()

def create_basic_client(self, client_class, **kwargs):
# Whatever the client, if credentials is None, fail
with self.assertRaises(ValueError):
client = client_class(
credentials=None,
**kwargs
)
# Whatever the client, if accept_language is not str, fail
with self.assertRaises(TypeError):
client = client_class(
credentials=self.settings.get_credentials(),
accept_language=42,
**kwargs
)

# Real client creation
client = client_class(
credentials=self.settings.get_credentials(),
**kwargs
)
if self.is_playback():
client.config.long_running_operation_timeout = 0
return client

def create_mgmt_client(self, client_class, **kwargs):
# Whatever the client, if subscription_id is None, fail
with self.assertRaises(ValueError):
self.create_basic_client(
client_class,
subscription_id=None,
**kwargs
)
# Whatever the client, if subscription_id is not a string, fail
with self.assertRaises(TypeError):
self.create_basic_client(
client_class,
subscription_id=42,
**kwargs
)

return self.create_basic_client(
client_class,
subscription_id=self.settings.SUBSCRIPTION_ID,
**kwargs
)

def create_keyvault_client(self):

def _auth_callback(server, resource, scope):
Expand All @@ -146,6 +76,9 @@ def _auth_callback(server, resource, scope):

def _scrub_sensitive_request_info(self, request):
request = super(AzureKeyVaultTestCase, self)._scrub_sensitive_request_info(request)
# prevents URI mismatch between Python 2 and 3 if request URI has extra / chars
request.uri = re.sub('//', '/', request.uri)
request.uri = re.sub('/', '//', request.uri, count=1)
# do not record token requests
if '/oauth2/token' in request.uri:
request = None
Expand All @@ -167,24 +100,3 @@ def _scrub(self, val):
}
val = self._scrub_using_dict(val, real_to_fake_dict)
return val

def create_resource_group(self):
pass
#result = self.resource_client.resource_groups.create_or_update(
# self.group_name,
# {
# 'location': self.region
# }
#)

def delete_resource_group(self, wait_timeout):
pass
#azure_poller = self.resource_client.resource_groups.delete(self.group_name)
#if wait_timeout:
# try:
# azure_poller.wait(wait_timeout)
# if azure_poller.done():
# return
# self.assertTrue(False, 'Timed out waiting for resource group to be deleted.')
# except CloudError:
# pass
Loading

0 comments on commit 36cfee2

Please sign in to comment.