Skip to content

Commit

Permalink
Blob test new migration (Azure#8215)
Browse files Browse the repository at this point in the history
* Test framework improvement

* Test update

* Rercordings

* CI configuration

* Missing pytest.ini
  • Loading branch information
lmazuel authored Oct 25, 2019
1 parent b5c2722 commit 86bf332
Show file tree
Hide file tree
Showing 1,294 changed files with 267,820 additions and 818,536 deletions.
2 changes: 2 additions & 0 deletions sdk/storage/azure-storage-blob/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
usefixtures = storage_account
26 changes: 26 additions & 0 deletions sdk/storage/azure-storage-blob/tests/asyncblobtestcase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# 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 asyncio
import functools
from testcase import StorageTestCase

LOGGING_FORMAT = '%(asctime)s %(name)-20s %(levelname)-5s %(message)s'

class AsyncBlobTestCase(StorageTestCase):
@staticmethod
def await_prepared_test(test_fn):
"""Synchronous wrapper for async test methods. Used to avoid making changes
upstream to AbstractPreparer (which doesn't await the functions it wraps)
"""

@functools.wraps(test_fn)
def run(test_class_instance, *args, **kwargs):
loop = asyncio.get_event_loop()
return loop.run_until_complete(test_fn(test_class_instance, **kwargs))

return run
68 changes: 68 additions & 0 deletions sdk/storage/azure-storage-blob/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# --------------------------------------------------------------------------
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# The MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the ""Software""), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
from devtools_testutils import ResourceGroupPreparer, StorageAccountPreparer, AzureMgmtTestCase
from azure_devtools.scenario_tests import create_random_name
from testcase import StorageTestCase

import pytest


@pytest.fixture(scope="session")
def storage_account():
test_case = AzureMgmtTestCase("__init__")
rg_preparer = ResourceGroupPreparer()
storage_preparer = StorageAccountPreparer(name_prefix='pyacrstorage')

# Set what the decorator is supposed to set for us
for prep in [rg_preparer, storage_preparer]:
prep.live_test = False
prep.test_class_instance = test_case

# Create
rg_name = create_random_name("pystorage", 24)
storage_name = create_random_name("pyacrstorage", 24)
try:
rg = rg_preparer.create_resource(rg_name)
StorageTestCase._RESOURCE_GROUP = rg['resource_group']
try:
storage_dict = storage_preparer.create_resource(
storage_name,
resource_group=rg['resource_group']
)
# Now the magic begins
StorageTestCase._STORAGE_ACCOUNT = storage_dict['storage_account']
StorageTestCase._STORAGE_KEY = storage_dict['storage_account_key']
yield
finally:
storage_preparer.remove_resource(
storage_name,
resource_group=rg['resource_group']
)
StorageTestCase._STORAGE_ACCOUNT = None
StorageTestCase._STORAGE_KEY = None
finally:
rg_preparer.remove_resource(rg_name)
StorageTestCase._RESOURCE_GROUP = None

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 86bf332

Please sign in to comment.