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

Test preparer region config loader (and DeleteAfter fixes) #12924

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion sdk/eventhub/azure-eventhub/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from uamqp import ReceiveClient
from uamqp.authentication import SASTokenAuth

from devtools_testutils import get_region_override

# Ignore async tests for Python < 3.5
collect_ignore = []
Expand All @@ -32,7 +33,7 @@
NAMESPACE_PREFIX = "eh-ns"
EVENTHUB_PREFIX = "eh"
EVENTHUB_DEFAULT_AUTH_RULE_NAME = 'RootManageSharedAccessKey'
LOCATION = "westus"
LOCATION = get_region_override("westus")


def pytest_addoption(parser):
Expand Down
4 changes: 2 additions & 2 deletions sdk/servicebus/azure-servicebus/tests/servicebus_preparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from azure_devtools.scenario_tests.exceptions import AzureTestError

from devtools_testutils import (
ResourceGroupPreparer, AzureMgmtPreparer, FakeResource
ResourceGroupPreparer, AzureMgmtPreparer, FakeResource, get_region_override
)

from devtools_testutils.resource_testcase import RESOURCE_GROUP_PARAM
Expand All @@ -27,7 +27,7 @@ class ServiceBusNamespacePreparer(AzureMgmtPreparer):
def __init__(self,
name_prefix='',
use_cache=False,
sku='Standard', location='westus',
sku='Standard', location=get_region_override('westus'),
parameter_name=SERVICEBUS_NAMESPACE_PARAM,
resource_group_parameter_name=RESOURCE_GROUP_PARAM,
disable_recording=True, playback_fake_resource=None,
Expand Down
4 changes: 2 additions & 2 deletions tools/azure-sdk-tools/devtools_testutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .mgmt_testcase import (AzureMgmtTestCase, AzureMgmtPreparer)
from .azure_testcase import AzureTestCase, is_live
from .azure_testcase import AzureTestCase, is_live, get_region_override
from .resource_testcase import (FakeResource, ResourceGroupPreparer, RandomNameResourceGroupPreparer, CachedResourceGroupPreparer)
from .storage_testcase import (FakeStorageAccount, StorageAccountPreparer)
from .keyvault_preparer import KeyVaultPreparer
Expand All @@ -8,7 +8,7 @@
'AzureMgmtTestCase', 'AzureMgmtPreparer',
'FakeResource', 'ResourceGroupPreparer',
'FakeStorageAccount', 'StorageAccountPreparer',
'AzureTestCase', 'is_live',
'AzureTestCase', 'is_live', 'get_region_override',
'KeyVaultPreparer', 'RandomNameResourceGroupPreparer',
'CachedResourceGroupPreparer'
]
7 changes: 7 additions & 0 deletions tools/azure-sdk-tools/devtools_testutils/azure_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def is_live():
return is_live._cache


def get_region_override(default='westus'):
region = os.environ.get('RESOURCE_REGION', None) or default
if not region:
raise ValueError('Region should not be None; set a non-empty-string region to either the RESOURCE_REGION environment variable or the default parameter to this function.')
return region


def _is_autorest_v3(client_class):
""" IS this client a autorestv3/track2 one?.
Could be refined later if necessary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create_resource(self, name, **kwargs):
parameters = {'location': self.location}
if self.delete_after_tag_timedelta:
expiry = datetime.datetime.utcnow() + self.delete_after_tag_timedelta
parameters['tags'] = {'DeleteAfter': expiry.isoformat()}
parameters['tags'] = {'DeleteAfter': expiry.replace(microsecond=0).isoformat()}
try:
self.resource = self.client.resource_groups.create_or_update(
name, parameters
Expand Down