Skip to content

Commit f7e5acb

Browse files
authored
Merge pull request #1234 from jakob-keller/tests
Improve test suite
2 parents e7d6ddf + 5aaa45a commit f7e5acb

34 files changed

+600
-386
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cov cover coverage: pre-commit
1919
mototest:
2020
docker pull alpine
2121
docker pull lambci/lambda:python3.8
22-
python -Wd -X tracemalloc=5 -X faulthandler -m pytest -vv -m moto -n auto --cov-report term --cov-report html --cov-report xml --cov=aiobotocore --cov=tests --log-cli-level=DEBUG $(FLAGS) aiobotocore tests
22+
python -Wd -X tracemalloc=5 -X faulthandler -m pytest -vv -m "not localonly" -n auto --cov-report term --cov-report html --cov-report xml --cov=aiobotocore --cov=tests --log-cli-level=DEBUG $(FLAGS) aiobotocore tests
2323
@echo "open file://`pwd`/htmlcov/index.html"
2424

2525
clean:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ include = ["aiobotocore*"]
5959
asyncio_mode = "auto"
6060
cache_dir = "/tmp/pytest_aiobotocore_cache"
6161
markers = [
62-
"moto",
62+
"localonly",
6363
"config_kwargs",
6464
"patch_attributes",
6565
]

tests/boto_tests/unit/__init__.py

Whitespace-only changes.

tests/boto_tests/test_credentials.py renamed to tests/boto_tests/unit/test_credentials.py

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,14 @@
4444
AioSSOProvider,
4545
)
4646
from aiobotocore.session import AioSession
47-
48-
from .helpers import StubbedSession
47+
from tests.boto_tests.helpers import StubbedSession
4948

5049

5150
def random_chars(num_chars):
5251
return binascii.hexlify(os.urandom(int(num_chars / 2))).decode('ascii')
5352

5453

5554
# From class TestCredentials(BaseEnvVar):
56-
@pytest.mark.moto
5755
@pytest.mark.parametrize(
5856
"access,secret", [('foo\xe2\x80\x99', 'bar\xe2\x80\x99'), ('foo', 'bar')]
5957
)
@@ -127,8 +125,6 @@ async def load():
127125
return _f
128126

129127

130-
@pytest.mark.moto
131-
@pytest.mark.asyncio
132128
async def test_assumerolefetcher_no_cache():
133129
response = {
134130
'Credentials': {
@@ -150,8 +146,6 @@ async def test_assumerolefetcher_no_cache():
150146
assert response == expected_response
151147

152148

153-
@pytest.mark.moto
154-
@pytest.mark.asyncio
155149
async def test_assumerolefetcher_cache_key_with_role_session_name():
156150
response = {
157151
'Credentials': {
@@ -180,8 +174,6 @@ async def test_assumerolefetcher_cache_key_with_role_session_name():
180174
assert cache[cache_key] == response
181175

182176

183-
@pytest.mark.moto
184-
@pytest.mark.asyncio
185177
async def test_assumerolefetcher_cache_in_cache_but_expired():
186178
response = {
187179
'Credentials': {
@@ -215,8 +207,6 @@ async def test_assumerolefetcher_cache_in_cache_but_expired():
215207
assert response == expected
216208

217209

218-
@pytest.mark.moto
219-
@pytest.mark.asyncio
220210
async def test_assumerolefetcher_mfa():
221211
response = {
222212
'Credentials': {
@@ -248,8 +238,6 @@ async def test_assumerolefetcher_mfa():
248238
assert call_kwargs['TokenCode'] == 'token-code'
249239

250240

251-
@pytest.mark.moto
252-
@pytest.mark.asyncio
253241
async def test_recursive_assume_role(assume_role_setup):
254242
self = assume_role_setup
255243

@@ -306,8 +294,6 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
306294
return mock.Mock(return_value=_Client(with_response))
307295

308296

309-
@pytest.mark.moto
310-
@pytest.mark.asyncio
311297
async def test_webidentfetcher_no_cache():
312298
response = {
313299
'Credentials': {
@@ -329,8 +315,6 @@ async def test_webidentfetcher_no_cache():
329315
assert response == expected_response
330316

331317

332-
@pytest.mark.moto
333-
@pytest.mark.asyncio
334318
async def test_credresolver_load_credentials_single_provider(
335319
credential_provider,
336320
):
@@ -347,8 +331,6 @@ async def test_credresolver_load_credentials_single_provider(
347331
assert creds.token == 'c'
348332

349333

350-
@pytest.mark.moto
351-
@pytest.mark.asyncio
352334
async def test_credresolver_no_providers(credential_provider):
353335
provider1 = credential_provider('provider1', 'CustomProvider1', None)
354336
resolver = credentials.AioCredentialResolver(providers=[provider1])
@@ -358,8 +340,6 @@ async def test_credresolver_no_providers(credential_provider):
358340

359341

360342
# From class TestCanonicalNameSourceProvider(BaseEnvVar):
361-
@pytest.mark.moto
362-
@pytest.mark.asyncio
363343
async def test_canonicalsourceprovider_source_creds(credential_provider):
364344
creds = credentials.AioCredentials('a', 'b', 'c')
365345
provider1 = credential_provider('provider1', 'CustomProvider1', creds)
@@ -372,8 +352,6 @@ async def test_canonicalsourceprovider_source_creds(credential_provider):
372352
assert result is creds
373353

374354

375-
@pytest.mark.moto
376-
@pytest.mark.asyncio
377355
async def test_canonicalsourceprovider_source_creds_case_insensitive(
378356
credential_provider,
379357
):
@@ -418,8 +396,6 @@ def _f(config=None):
418396
return _f
419397

420398

421-
@pytest.mark.moto
422-
@pytest.mark.asyncio
423399
async def test_assumerolecredprovider_assume_role_no_cache(
424400
credential_provider, assumerolecredprovider_config_loader
425401
):
@@ -461,8 +437,6 @@ async def test_assumerolecredprovider_assume_role_no_cache(
461437

462438

463439
# MFA
464-
@pytest.mark.moto
465-
@pytest.mark.asyncio
466440
async def test_assumerolecredprovider_mfa(
467441
credential_provider, assumerolecredprovider_config_loader
468442
):
@@ -520,8 +494,6 @@ async def test_assumerolecredprovider_mfa(
520494
assert call_kwargs['TokenCode'] == 'token-code'
521495

522496

523-
@pytest.mark.moto
524-
@pytest.mark.asyncio
525497
async def test_assumerolecredprovider_mfa_cannot_refresh_credentials(
526498
credential_provider, assumerolecredprovider_config_loader
527499
):
@@ -577,8 +549,6 @@ async def test_assumerolecredprovider_mfa_cannot_refresh_credentials(
577549

578550

579551
# From class TestAssumeRoleWithWebIdentityCredentialProvider
580-
@pytest.mark.moto
581-
@pytest.mark.asyncio
582552
async def test_assumerolewebidentprovider_no_cache():
583553
future = datetime.now(tzlocal()) + timedelta(hours=24)
584554

@@ -630,8 +600,6 @@ def full_url(url):
630600

631601

632602
# From class TestEnvVar(BaseEnvVar):
633-
@pytest.mark.moto
634-
@pytest.mark.asyncio
635603
async def test_envvarprovider_env_var_present():
636604
environ = {
637605
'AWS_ACCESS_KEY_ID': 'foo',
@@ -646,17 +614,13 @@ async def test_envvarprovider_env_var_present():
646614
assert creds.method == 'env'
647615

648616

649-
@pytest.mark.moto
650-
@pytest.mark.asyncio
651617
async def test_envvarprovider_env_var_absent():
652618
environ = {}
653619
provider = credentials.AioEnvProvider(environ)
654620
creds = await provider.load()
655621
assert creds is None
656622

657623

658-
@pytest.mark.moto
659-
@pytest.mark.asyncio
660624
async def test_envvarprovider_env_var_expiry():
661625
expiry_time = datetime.now(tzlocal()) - timedelta(hours=1)
662626
environ = {
@@ -691,8 +655,6 @@ def profile_config():
691655
return parser
692656

693657

694-
@pytest.mark.moto
695-
@pytest.mark.asyncio
696658
async def test_configprovider_file_exists(profile_config):
697659
provider = credentials.AioConfigProvider(
698660
'cli.cfg', 'default', profile_config
@@ -705,8 +667,6 @@ async def test_configprovider_file_exists(profile_config):
705667
assert creds.method == 'config-file'
706668

707669

708-
@pytest.mark.moto
709-
@pytest.mark.asyncio
710670
async def test_configprovider_file_missing_profile(profile_config):
711671
provider = credentials.AioConfigProvider(
712672
'cli.cfg', 'NOT-default', profile_config
@@ -716,8 +676,6 @@ async def test_configprovider_file_missing_profile(profile_config):
716676

717677

718678
# From class TestSharedCredentialsProvider(BaseEnvVar):
719-
@pytest.mark.moto
720-
@pytest.mark.asyncio
721679
async def test_sharedcredentials_file_exists():
722680
parser = mock.Mock()
723681
parser.return_value = {
@@ -740,8 +698,6 @@ async def test_sharedcredentials_file_exists():
740698
assert creds.method == 'shared-credentials-file'
741699

742700

743-
@pytest.mark.moto
744-
@pytest.mark.asyncio
745701
async def test_sharedcredentials_file_missing():
746702
parser = mock.Mock()
747703
parser.side_effect = botocore.exceptions.ConfigNotFound(path='foo')
@@ -754,8 +710,6 @@ async def test_sharedcredentials_file_missing():
754710

755711

756712
# From class TestBotoProvider(BaseEnvVar):
757-
@pytest.mark.moto
758-
@pytest.mark.asyncio
759713
async def test_botoprovider_file_exists():
760714
parser = mock.Mock()
761715
parser.return_value = {
@@ -774,8 +728,6 @@ async def test_botoprovider_file_exists():
774728
assert creds.method == 'boto-config'
775729

776730

777-
@pytest.mark.moto
778-
@pytest.mark.asyncio
779731
async def test_botoprovider_file_missing():
780732
parser = mock.Mock()
781733
parser.side_effect = botocore.exceptions.ConfigNotFound(path='foo')
@@ -786,8 +738,6 @@ async def test_botoprovider_file_missing():
786738

787739

788740
# From class TestOriginalEC2Provider(BaseEnvVar):
789-
@pytest.mark.moto
790-
@pytest.mark.asyncio
791741
async def test_originalec2provider_file_exists():
792742
envrion = {'AWS_CREDENTIAL_FILE': 'foo.cfg'}
793743
parser = mock.Mock()
@@ -807,8 +757,6 @@ async def test_originalec2provider_file_exists():
807757
assert creds.method == 'ec2-credentials-file'
808758

809759

810-
@pytest.mark.moto
811-
@pytest.mark.asyncio
812760
async def test_originalec2provider_file_missing():
813761
provider = credentials.AioOriginalEC2Provider(environ={})
814762
creds = await provider.load()
@@ -854,17 +802,13 @@ def fake_set_config_variable(self, logical_name, value):
854802
return _f
855803

856804

857-
@pytest.mark.moto
858-
@pytest.mark.asyncio
859805
async def test_createcredentialresolver(mock_session):
860806
session = mock_session()
861807

862808
resolver = credentials.create_credential_resolver(session)
863809
assert isinstance(resolver, credentials.AioCredentialResolver)
864810

865811

866-
@pytest.mark.moto
867-
@pytest.mark.asyncio
868812
async def test_get_credentials(mock_session):
869813
session = mock_session()
870814

@@ -1098,8 +1042,6 @@ def assume_role_setup(base_assume_role_test_setup):
10981042
yield self
10991043

11001044

1101-
@pytest.mark.moto
1102-
@pytest.mark.asyncio
11031045
async def test_sso_credential_fetcher_can_fetch_credentials(
11041046
ssl_credential_fetcher_setup,
11051047
):
@@ -1141,8 +1083,6 @@ async def test_sso_credential_fetcher_can_fetch_credentials(
11411083
self.assertEqual(self.cache[cache_key], expected_cached_credentials)
11421084

11431085

1144-
@pytest.mark.moto
1145-
@pytest.mark.asyncio
11461086
async def test_sso_cred_fetcher_raises_helpful_message_on_unauthorized_exception(
11471087
ssl_credential_fetcher_setup,
11481088
):
@@ -1246,8 +1186,6 @@ def _add_get_role_credentials_response(self):
12461186
)
12471187

12481188

1249-
@pytest.mark.moto
1250-
@pytest.mark.asyncio
12511189
async def test_load_sso_credentials_without_cache(sso_provider_setup):
12521190
self = sso_provider_setup
12531191
_add_get_role_credentials_response(self)
@@ -1259,8 +1197,6 @@ async def test_load_sso_credentials_without_cache(sso_provider_setup):
12591197
self.assertEqual(credentials.token, 'baz')
12601198

12611199

1262-
@pytest.mark.moto
1263-
@pytest.mark.asyncio
12641200
async def test_load_sso_credentials_with_cache(sso_provider_setup):
12651201
self = sso_provider_setup
12661202

@@ -1280,8 +1216,6 @@ async def test_load_sso_credentials_with_cache(sso_provider_setup):
12801216
self.assertEqual(credentials.token, 'cached-st')
12811217

12821218

1283-
@pytest.mark.moto
1284-
@pytest.mark.asyncio
12851219
async def test_load_sso_credentials_with_cache_expired(sso_provider_setup):
12861220
self = sso_provider_setup
12871221
cached_creds = {
@@ -1304,8 +1238,6 @@ async def test_load_sso_credentials_with_cache_expired(sso_provider_setup):
13041238
self.assertEqual(credentials.token, 'baz')
13051239

13061240

1307-
@pytest.mark.moto
1308-
@pytest.mark.asyncio
13091241
async def test_required_config_not_set(sso_provider_setup):
13101242
self = sso_provider_setup
13111243
del self.config['sso_start_url']

0 commit comments

Comments
 (0)