Skip to content

Commit

Permalink
Merge pull request #1234 from jakob-keller/tests
Browse files Browse the repository at this point in the history
Improve test suite
  • Loading branch information
jakob-keller authored Dec 16, 2024
2 parents e7d6ddf + 5aaa45a commit f7e5acb
Show file tree
Hide file tree
Showing 34 changed files with 600 additions and 386 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cov cover coverage: pre-commit
mototest:
docker pull alpine
docker pull lambci/lambda:python3.8
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
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
@echo "open file://`pwd`/htmlcov/index.html"

clean:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ include = ["aiobotocore*"]
asyncio_mode = "auto"
cache_dir = "/tmp/pytest_aiobotocore_cache"
markers = [
"moto",
"localonly",
"config_kwargs",
"patch_attributes",
]
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@
AioSSOProvider,
)
from aiobotocore.session import AioSession

from .helpers import StubbedSession
from tests.boto_tests.helpers import StubbedSession


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


# From class TestCredentials(BaseEnvVar):
@pytest.mark.moto
@pytest.mark.parametrize(
"access,secret", [('foo\xe2\x80\x99', 'bar\xe2\x80\x99'), ('foo', 'bar')]
)
Expand Down Expand Up @@ -127,8 +125,6 @@ async def load():
return _f


@pytest.mark.moto
@pytest.mark.asyncio
async def test_assumerolefetcher_no_cache():
response = {
'Credentials': {
Expand All @@ -150,8 +146,6 @@ async def test_assumerolefetcher_no_cache():
assert response == expected_response


@pytest.mark.moto
@pytest.mark.asyncio
async def test_assumerolefetcher_cache_key_with_role_session_name():
response = {
'Credentials': {
Expand Down Expand Up @@ -180,8 +174,6 @@ async def test_assumerolefetcher_cache_key_with_role_session_name():
assert cache[cache_key] == response


@pytest.mark.moto
@pytest.mark.asyncio
async def test_assumerolefetcher_cache_in_cache_but_expired():
response = {
'Credentials': {
Expand Down Expand Up @@ -215,8 +207,6 @@ async def test_assumerolefetcher_cache_in_cache_but_expired():
assert response == expected


@pytest.mark.moto
@pytest.mark.asyncio
async def test_assumerolefetcher_mfa():
response = {
'Credentials': {
Expand Down Expand Up @@ -248,8 +238,6 @@ async def test_assumerolefetcher_mfa():
assert call_kwargs['TokenCode'] == 'token-code'


@pytest.mark.moto
@pytest.mark.asyncio
async def test_recursive_assume_role(assume_role_setup):
self = assume_role_setup

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


@pytest.mark.moto
@pytest.mark.asyncio
async def test_webidentfetcher_no_cache():
response = {
'Credentials': {
Expand All @@ -329,8 +315,6 @@ async def test_webidentfetcher_no_cache():
assert response == expected_response


@pytest.mark.moto
@pytest.mark.asyncio
async def test_credresolver_load_credentials_single_provider(
credential_provider,
):
Expand All @@ -347,8 +331,6 @@ async def test_credresolver_load_credentials_single_provider(
assert creds.token == 'c'


@pytest.mark.moto
@pytest.mark.asyncio
async def test_credresolver_no_providers(credential_provider):
provider1 = credential_provider('provider1', 'CustomProvider1', None)
resolver = credentials.AioCredentialResolver(providers=[provider1])
Expand All @@ -358,8 +340,6 @@ async def test_credresolver_no_providers(credential_provider):


# From class TestCanonicalNameSourceProvider(BaseEnvVar):
@pytest.mark.moto
@pytest.mark.asyncio
async def test_canonicalsourceprovider_source_creds(credential_provider):
creds = credentials.AioCredentials('a', 'b', 'c')
provider1 = credential_provider('provider1', 'CustomProvider1', creds)
Expand All @@ -372,8 +352,6 @@ async def test_canonicalsourceprovider_source_creds(credential_provider):
assert result is creds


@pytest.mark.moto
@pytest.mark.asyncio
async def test_canonicalsourceprovider_source_creds_case_insensitive(
credential_provider,
):
Expand Down Expand Up @@ -418,8 +396,6 @@ def _f(config=None):
return _f


@pytest.mark.moto
@pytest.mark.asyncio
async def test_assumerolecredprovider_assume_role_no_cache(
credential_provider, assumerolecredprovider_config_loader
):
Expand Down Expand Up @@ -461,8 +437,6 @@ async def test_assumerolecredprovider_assume_role_no_cache(


# MFA
@pytest.mark.moto
@pytest.mark.asyncio
async def test_assumerolecredprovider_mfa(
credential_provider, assumerolecredprovider_config_loader
):
Expand Down Expand Up @@ -520,8 +494,6 @@ async def test_assumerolecredprovider_mfa(
assert call_kwargs['TokenCode'] == 'token-code'


@pytest.mark.moto
@pytest.mark.asyncio
async def test_assumerolecredprovider_mfa_cannot_refresh_credentials(
credential_provider, assumerolecredprovider_config_loader
):
Expand Down Expand Up @@ -577,8 +549,6 @@ async def test_assumerolecredprovider_mfa_cannot_refresh_credentials(


# From class TestAssumeRoleWithWebIdentityCredentialProvider
@pytest.mark.moto
@pytest.mark.asyncio
async def test_assumerolewebidentprovider_no_cache():
future = datetime.now(tzlocal()) + timedelta(hours=24)

Expand Down Expand Up @@ -630,8 +600,6 @@ def full_url(url):


# From class TestEnvVar(BaseEnvVar):
@pytest.mark.moto
@pytest.mark.asyncio
async def test_envvarprovider_env_var_present():
environ = {
'AWS_ACCESS_KEY_ID': 'foo',
Expand All @@ -646,17 +614,13 @@ async def test_envvarprovider_env_var_present():
assert creds.method == 'env'


@pytest.mark.moto
@pytest.mark.asyncio
async def test_envvarprovider_env_var_absent():
environ = {}
provider = credentials.AioEnvProvider(environ)
creds = await provider.load()
assert creds is None


@pytest.mark.moto
@pytest.mark.asyncio
async def test_envvarprovider_env_var_expiry():
expiry_time = datetime.now(tzlocal()) - timedelta(hours=1)
environ = {
Expand Down Expand Up @@ -691,8 +655,6 @@ def profile_config():
return parser


@pytest.mark.moto
@pytest.mark.asyncio
async def test_configprovider_file_exists(profile_config):
provider = credentials.AioConfigProvider(
'cli.cfg', 'default', profile_config
Expand All @@ -705,8 +667,6 @@ async def test_configprovider_file_exists(profile_config):
assert creds.method == 'config-file'


@pytest.mark.moto
@pytest.mark.asyncio
async def test_configprovider_file_missing_profile(profile_config):
provider = credentials.AioConfigProvider(
'cli.cfg', 'NOT-default', profile_config
Expand All @@ -716,8 +676,6 @@ async def test_configprovider_file_missing_profile(profile_config):


# From class TestSharedCredentialsProvider(BaseEnvVar):
@pytest.mark.moto
@pytest.mark.asyncio
async def test_sharedcredentials_file_exists():
parser = mock.Mock()
parser.return_value = {
Expand All @@ -740,8 +698,6 @@ async def test_sharedcredentials_file_exists():
assert creds.method == 'shared-credentials-file'


@pytest.mark.moto
@pytest.mark.asyncio
async def test_sharedcredentials_file_missing():
parser = mock.Mock()
parser.side_effect = botocore.exceptions.ConfigNotFound(path='foo')
Expand All @@ -754,8 +710,6 @@ async def test_sharedcredentials_file_missing():


# From class TestBotoProvider(BaseEnvVar):
@pytest.mark.moto
@pytest.mark.asyncio
async def test_botoprovider_file_exists():
parser = mock.Mock()
parser.return_value = {
Expand All @@ -774,8 +728,6 @@ async def test_botoprovider_file_exists():
assert creds.method == 'boto-config'


@pytest.mark.moto
@pytest.mark.asyncio
async def test_botoprovider_file_missing():
parser = mock.Mock()
parser.side_effect = botocore.exceptions.ConfigNotFound(path='foo')
Expand All @@ -786,8 +738,6 @@ async def test_botoprovider_file_missing():


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


@pytest.mark.moto
@pytest.mark.asyncio
async def test_originalec2provider_file_missing():
provider = credentials.AioOriginalEC2Provider(environ={})
creds = await provider.load()
Expand Down Expand Up @@ -854,17 +802,13 @@ def fake_set_config_variable(self, logical_name, value):
return _f


@pytest.mark.moto
@pytest.mark.asyncio
async def test_createcredentialresolver(mock_session):
session = mock_session()

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


@pytest.mark.moto
@pytest.mark.asyncio
async def test_get_credentials(mock_session):
session = mock_session()

Expand Down Expand Up @@ -1098,8 +1042,6 @@ def assume_role_setup(base_assume_role_test_setup):
yield self


@pytest.mark.moto
@pytest.mark.asyncio
async def test_sso_credential_fetcher_can_fetch_credentials(
ssl_credential_fetcher_setup,
):
Expand Down Expand Up @@ -1141,8 +1083,6 @@ async def test_sso_credential_fetcher_can_fetch_credentials(
self.assertEqual(self.cache[cache_key], expected_cached_credentials)


@pytest.mark.moto
@pytest.mark.asyncio
async def test_sso_cred_fetcher_raises_helpful_message_on_unauthorized_exception(
ssl_credential_fetcher_setup,
):
Expand Down Expand Up @@ -1246,8 +1186,6 @@ def _add_get_role_credentials_response(self):
)


@pytest.mark.moto
@pytest.mark.asyncio
async def test_load_sso_credentials_without_cache(sso_provider_setup):
self = sso_provider_setup
_add_get_role_credentials_response(self)
Expand All @@ -1259,8 +1197,6 @@ async def test_load_sso_credentials_without_cache(sso_provider_setup):
self.assertEqual(credentials.token, 'baz')


@pytest.mark.moto
@pytest.mark.asyncio
async def test_load_sso_credentials_with_cache(sso_provider_setup):
self = sso_provider_setup

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


@pytest.mark.moto
@pytest.mark.asyncio
async def test_load_sso_credentials_with_cache_expired(sso_provider_setup):
self = sso_provider_setup
cached_creds = {
Expand All @@ -1304,8 +1238,6 @@ async def test_load_sso_credentials_with_cache_expired(sso_provider_setup):
self.assertEqual(credentials.token, 'baz')


@pytest.mark.moto
@pytest.mark.asyncio
async def test_required_config_not_set(sso_provider_setup):
self = sso_provider_setup
del self.config['sso_start_url']
Expand Down
Loading

0 comments on commit f7e5acb

Please sign in to comment.