Skip to content

Commit 295cc41

Browse files
authored
Adopt upstream unit tests session.TestCreateClient (#1309)
1 parent 7009ebe commit 295cc41

File tree

3 files changed

+560
-0
lines changed

3 files changed

+560
-0
lines changed

tests/boto_tests/__init__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,54 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313

14+
import contextlib
15+
import os
16+
import random
17+
import shutil
18+
import tempfile
19+
import time
20+
from unittest import mock # noqa: F401
21+
22+
import botocore.loaders
1423
from botocore.compat import parse_qs, urlparse
1524

25+
import aiobotocore.session
26+
27+
_LOADER = botocore.loaders.Loader()
28+
29+
30+
def create_session(**kwargs):
31+
# Create a Session object. By default,
32+
# the _LOADER object is used as the loader
33+
# so that we reused the same models across tests.
34+
session = aiobotocore.session.AioSession(**kwargs)
35+
session.register_component('data_loader', _LOADER)
36+
session.set_config_variable('credentials_file', 'noexist/foo/botocore')
37+
return session
38+
39+
40+
@contextlib.contextmanager
41+
def temporary_file(mode):
42+
"""This is a cross platform temporary file creation.
43+
44+
tempfile.NamedTemporary file on windows creates a secure temp file
45+
that can't be read by other processes and can't be opened a second time.
46+
47+
For tests, we generally *want* them to be read multiple times.
48+
The test fixture writes the temp file contents, the test reads the
49+
temp file.
50+
51+
"""
52+
temporary_directory = tempfile.mkdtemp()
53+
basename = f'tmpfile-{int(time.time())}-{random.randint(1, 1000)}'
54+
full_filename = os.path.join(temporary_directory, basename)
55+
open(full_filename, 'w').close()
56+
try:
57+
with open(full_filename, mode) as f:
58+
yield f
59+
finally:
60+
shutil.rmtree(temporary_directory)
61+
1662

1763
def _urlparse(url):
1864
if isinstance(url, bytes):

tests/boto_tests/unit/cfg/foo_config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[default]
2+
aws_access_key_id = foo
3+
aws_secret_access_key = bar
4+
foo_region = us-west-1
5+
6+
[profile "foo"]
7+
aws_access_key_id = fie
8+
aws_secret_access_key = baz

0 commit comments

Comments
 (0)