Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split create_basic_client into two methods #14673

Merged
merged 26 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a8a078f
Update azure_testcase.py
lmazuel Oct 21, 2020
52c9b1c
updated test_table(_async) to verify changes to azure_testcase work n…
seankane-msft Oct 21, 2020
2ba457e
removed the positional *args in favor of pushing towards kwargs
seankane-msft Oct 21, 2020
4ab4cd3
added private _get_real_credential with kwarg for is_async
seankane-msft Oct 21, 2020
cd97f09
added the async fake credential that was copied from schema registry,…
seankane-msft Oct 21, 2020
07eb9de
breaking the fake async credential into its own file and importing it…
seankane-msft Oct 21, 2020
7e110aa
fixing up comments based on laurent/adams review
seankane-msft Oct 22, 2020
65bea77
removing the second boolean for is_real, using self.is_live instead w…
seankane-msft Oct 22, 2020
4360a14
updating credential to be self.xxx_cred, caught in the tables live tests
seankane-msft Oct 27, 2020
dd71477
fixed a create_credential in test table async that did not use kwargs…
seankane-msft Oct 27, 2020
f8e9a4f
Update azure_testcase.py
lmazuel Oct 21, 2020
a2e467a
updated test_table(_async) to verify changes to azure_testcase work n…
seankane-msft Oct 21, 2020
b7bd954
removed the positional *args in favor of pushing towards kwargs
seankane-msft Oct 21, 2020
5cfc599
added private _get_real_credential with kwarg for is_async
seankane-msft Oct 21, 2020
fa30004
added the async fake credential that was copied from schema registry,…
seankane-msft Oct 21, 2020
2a034ab
breaking the fake async credential into its own file and importing it…
seankane-msft Oct 21, 2020
56c60da
fixing up comments based on laurent/adams review
seankane-msft Oct 22, 2020
61592b5
removing the second boolean for is_real, using self.is_live instead w…
seankane-msft Oct 22, 2020
0a72499
updating credential to be self.xxx_cred, caught in the tables live tests
seankane-msft Oct 27, 2020
c9b74d8
fixed a create_credential in test table async that did not use kwargs…
seankane-msft Oct 27, 2020
1b79c34
changing a word to force check-enforcer to re-evaulate CI
seankane-msft Nov 2, 2020
9b68e71
changing a word to force check-enforcer to re-evaulate CI
seankane-msft Nov 2, 2020
69c5dee
Merge remote-tracking branch 'origin/master' into async_cred_test
lmazuel Nov 3, 2020
208b6a3
Clarify async protocol
lmazuel Nov 3, 2020
ac5ce2f
adding a logging message to warn about create_basic_client and use ge…
seankane-msft Nov 3, 2020
ec9b9f0
fixing up the syntax of the logger
seankane-msft Nov 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,75 +34,13 @@

class SchemaRegistryAsyncTests(AzureTestCase):

class AsyncFakeCredential(object):
async def get_token(self, *scopes, **kwargs):
return AccessToken('fake_token', 2527537086)

async def close(self):
pass

def create_basic_client(self, client_class, **kwargs):
# This is the patch for creating client using aio identity

tenant_id = os.environ.get("AZURE_TENANT_ID", None)
client_id = os.environ.get("AZURE_CLIENT_ID", None)
secret = os.environ.get("AZURE_CLIENT_SECRET", None)

if tenant_id and client_id and secret and self.is_live:
if _is_autorest_v3(client_class):
# Create azure-identity class
from azure.identity.aio import ClientSecretCredential
credentials = ClientSecretCredential(
tenant_id=tenant_id,
client_id=client_id,
client_secret=secret
)
else:
# Create msrestazure class
from msrestazure.azure_active_directory import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
tenant=tenant_id,
client_id=client_id,
secret=secret
)
else:
if _is_autorest_v3(client_class):
credentials = self.AsyncFakeCredential()
#credentials = self.settings.get_azure_core_credentials()
else:
credentials = self.settings.get_credentials()

# Real client creation
# FIXME decide what is the final argument for that
# if self.is_playback():
# kwargs.setdefault("polling_interval", 0)
if _is_autorest_v3(client_class):
kwargs.setdefault("logging_enable", True)
client = client_class(
credential=credentials,
**kwargs
)
else:
client = client_class(
credentials=credentials,
**kwargs
)

if self.is_playback():
try:
client._config.polling_interval = 0 # FIXME in azure-mgmt-core, make this a kwargs
except AttributeError:
pass

if hasattr(client, "config"): # Autorest v2
if self.is_playback():
client.config.long_running_operation_timeout = 0
client.config.enable_http_logger = True
return client
def create_client(self, endpoint):
credential = self.get_credential(SchemaRegistryClient, is_async=True)
return self.create_client_from_credential(SchemaRegistryClient, credential, endpoint=endpoint, is_async=True)

@SchemaRegistryPreparer()
async def test_schema_basic_async(self, schemaregistry_endpoint, schemaregistry_group, **kwargs):
client = self.create_basic_client(SchemaRegistryClient, endpoint=schemaregistry_endpoint)
client = self.create_client(schemaregistry_endpoint)
async with client:
schema_name = self.get_resource_name('test-schema-basic-async')
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
Expand Down Expand Up @@ -135,7 +73,7 @@ async def test_schema_basic_async(self, schemaregistry_endpoint, schemaregistry_

@SchemaRegistryPreparer()
async def test_schema_update_async(self, schemaregistry_endpoint, schemaregistry_group, **kwargs):
client = self.create_basic_client(SchemaRegistryClient, endpoint=schemaregistry_endpoint)
client = self.create_client(schemaregistry_endpoint)
async with client:
schema_name = self.get_resource_name('test-schema-update-async')
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
Expand Down Expand Up @@ -170,7 +108,7 @@ async def test_schema_update_async(self, schemaregistry_endpoint, schemaregistry

@SchemaRegistryPreparer()
async def test_schema_same_twice_async(self, schemaregistry_endpoint, schemaregistry_group, **kwargs):
client = self.create_basic_client(SchemaRegistryClient, endpoint=schemaregistry_endpoint)
client = self.create_client(schemaregistry_endpoint)
schema_name = self.get_resource_name('test-schema-twice-async')
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"age","type":["int","null"]},{"name":"city","type":["string","null"]}]}"""
serialization_type = "Avro"
Expand All @@ -193,7 +131,7 @@ async def test_schema_negative_wrong_credential_async(self, schemaregistry_endpo

@SchemaRegistryPreparer()
async def test_schema_negative_wrong_endpoint_async(self, schemaregistry_endpoint, schemaregistry_group, **kwargs):
client = self.create_basic_client(SchemaRegistryClient, endpoint="nonexist.servicebus.windows.net")
client = self.create_client("nonexist.servicebus.windows.net")
async with client:
schema_name = self.get_resource_name('test-schema-nonexist-async')
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
Expand All @@ -204,7 +142,7 @@ async def test_schema_negative_wrong_endpoint_async(self, schemaregistry_endpoin

@SchemaRegistryPreparer()
async def test_schema_negative_no_schema_async(self, schemaregistry_endpoint, schemaregistry_group, **kwargs):
client = self.create_basic_client(SchemaRegistryClient, endpoint=schemaregistry_endpoint)
client = self.create_client(schemaregistry_endpoint)
async with client:
with pytest.raises(HttpResponseError):
await client.get_schema('a')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@

class SchemaRegistryTests(AzureTestCase):

def create_client(self, endpoint):
credential = self.get_credential(SchemaRegistryClient)
return self.create_client_from_credential(SchemaRegistryClient, credential, endpoint=endpoint)

@SchemaRegistryPreparer()
def test_schema_basic(self, schemaregistry_endpoint, schemaregistry_group, **kwargs):
client = self.create_basic_client(SchemaRegistryClient, endpoint=schemaregistry_endpoint)
client = self.create_client(schemaregistry_endpoint)
schema_name = self.get_resource_name('test-schema-basic')
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
serialization_type = "Avro"
Expand Down Expand Up @@ -63,7 +67,7 @@ def test_schema_basic(self, schemaregistry_endpoint, schemaregistry_group, **kwa

@SchemaRegistryPreparer()
def test_schema_update(self, schemaregistry_endpoint, schemaregistry_group, **kwargs):
client = self.create_basic_client(SchemaRegistryClient, endpoint=schemaregistry_endpoint)
client = self.create_client(schemaregistry_endpoint)
schema_name = self.get_resource_name('test-schema-update')
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
serialization_type = "Avro"
Expand Down Expand Up @@ -96,7 +100,7 @@ def test_schema_update(self, schemaregistry_endpoint, schemaregistry_group, **kw

@SchemaRegistryPreparer()
def test_schema_same_twice(self, schemaregistry_endpoint, schemaregistry_group, **kwargs):
client = self.create_basic_client(SchemaRegistryClient, endpoint=schemaregistry_endpoint)
client = self.create_client(schemaregistry_endpoint)
schema_name = self.get_resource_name('test-schema-twice')
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"age","type":["int","null"]},{"name":"city","type":["string","null"]}]}"""
serialization_type = "Avro"
Expand All @@ -116,7 +120,7 @@ def test_schema_negative_wrong_credential(self, schemaregistry_endpoint, schemar

@SchemaRegistryPreparer()
def test_schema_negative_wrong_endpoint(self, schemaregistry_endpoint, schemaregistry_group, **kwargs):
client = self.create_basic_client(SchemaRegistryClient, endpoint="nonexist.servicebus.windows.net")
client = self.create_client("nonexist.servicebus.windows.net")
schema_name = self.get_resource_name('test-schema-nonexist')
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
serialization_type = "Avro"
Expand All @@ -125,7 +129,7 @@ def test_schema_negative_wrong_endpoint(self, schemaregistry_endpoint, schemareg

@SchemaRegistryPreparer()
def test_schema_negative_no_schema(self, schemaregistry_endpoint, schemaregistry_group, **kwargs):
client = self.create_basic_client(SchemaRegistryClient, endpoint=schemaregistry_endpoint)
client = self.create_client(schemaregistry_endpoint)
with pytest.raises(HttpResponseError):
client.get_schema('a')

Expand Down
Loading