Skip to content

Commit

Permalink
Adopt upstream unit tests session.TestCreateClient (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-keller authored Feb 28, 2025
1 parent 7009ebe commit 295cc41
Show file tree
Hide file tree
Showing 3 changed files with 560 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/boto_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,54 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import contextlib
import os
import random
import shutil
import tempfile
import time
from unittest import mock # noqa: F401

import botocore.loaders
from botocore.compat import parse_qs, urlparse

import aiobotocore.session

_LOADER = botocore.loaders.Loader()


def create_session(**kwargs):
# Create a Session object. By default,
# the _LOADER object is used as the loader
# so that we reused the same models across tests.
session = aiobotocore.session.AioSession(**kwargs)
session.register_component('data_loader', _LOADER)
session.set_config_variable('credentials_file', 'noexist/foo/botocore')
return session


@contextlib.contextmanager
def temporary_file(mode):
"""This is a cross platform temporary file creation.
tempfile.NamedTemporary file on windows creates a secure temp file
that can't be read by other processes and can't be opened a second time.
For tests, we generally *want* them to be read multiple times.
The test fixture writes the temp file contents, the test reads the
temp file.
"""
temporary_directory = tempfile.mkdtemp()
basename = f'tmpfile-{int(time.time())}-{random.randint(1, 1000)}'
full_filename = os.path.join(temporary_directory, basename)
open(full_filename, 'w').close()
try:
with open(full_filename, mode) as f:
yield f
finally:
shutil.rmtree(temporary_directory)


def _urlparse(url):
if isinstance(url, bytes):
Expand Down
8 changes: 8 additions & 0 deletions tests/boto_tests/unit/cfg/foo_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[default]
aws_access_key_id = foo
aws_secret_access_key = bar
foo_region = us-west-1

[profile "foo"]
aws_access_key_id = fie
aws_secret_access_key = baz
Loading

0 comments on commit 295cc41

Please sign in to comment.