Skip to content

Commit

Permalink
fix(tests): Adapt to moto 5
Browse files Browse the repository at this point in the history
Signed-off-by: Ferenc Géczi <[email protected]>
  • Loading branch information
Ferenc- committed Jan 29, 2024
1 parent 715edda commit 7027702
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
9 changes: 7 additions & 2 deletions tests/apps/flask_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

try:
import boto3
from moto import mock_sqs
# TODO: Remove branching when we drop support for Python 3.7
import sys
if sys.version_info >= (3, 8):
from moto import mock_aws
else:
from moto import mock_sqs as mock_aws
except ImportError:
# Doesn't matter. We won't call routes using boto3
# in test sets that don't install/test for it.
Expand Down Expand Up @@ -174,7 +179,7 @@ def boto3_sqs():
os.environ['AWS_SECURITY_TOKEN'] = 'testing'
os.environ['AWS_SESSION_TOKEN'] = 'testing'

with mock_sqs():
with mock_aws():
boto3_client = boto3.client('sqs', region_name='us-east-1')
response = boto3_client.create_queue(
QueueName='SQS_QUEUE_NAME',
Expand Down
6 changes: 3 additions & 3 deletions tests/clients/boto3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ If you would like to run this test server manually from an ipython console:
import os
import urllib3
from moto import mock_sqs
from moto import mock_aws
import tests.apps.flask_app
from tests.helpers import testenv
from instana.singletons import tracer
Expand All @@ -16,7 +16,7 @@ os.environ['AWS_SECRET_ACCESS_KEY'] = 'testing'
os.environ['AWS_SECURITY_TOKEN'] = 'testing'
os.environ['AWS_SESSION_TOKEN'] = 'testing'
@mock_sqs
@mock_aws
def test_app_boto3_sqs():
with tracer.start_active_span('wsgi') as scope:
scope.span.set_tag('span.kind', 'entry')
Expand All @@ -26,4 +26,4 @@ def test_app_boto3_sqs():
scope.span.set_tag('http.status_code', 200)
response = http_client.request('GET', testenv["wsgi_server"] + '/boto3/sqs')
```
```
9 changes: 7 additions & 2 deletions tests/clients/boto3/test_boto3_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import boto3
import pytest

from moto import mock_lambda
# TODO: Remove branching when we drop support for Python 3.7
import sys
if sys.version_info >= (3, 8):
from moto import mock_aws
else:
from moto import mock_sqs as mock_aws

from instana.singletons import tracer
from ...helpers import get_first_span_by_filter
Expand All @@ -24,7 +29,7 @@ def aws_credentials():

@pytest.fixture(scope='function')
def aws_lambda(aws_credentials):
with mock_lambda():
with mock_aws():
yield boto3.client('lambda', region_name='us-east-1')


Expand Down
9 changes: 7 additions & 2 deletions tests/clients/boto3/test_boto3_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import boto3
import pytest

from moto import mock_s3
# TODO: Remove branching when we drop support for Python 3.7
import sys
if sys.version_info >= (3, 8):
from moto import mock_aws
else:
from moto import mock_s3 as mock_aws

from instana.singletons import tracer
from ...helpers import get_first_span_by_filter
Expand All @@ -34,7 +39,7 @@ def aws_credentials():

@pytest.fixture(scope='function')
def s3(aws_credentials):
with mock_s3():
with mock_aws():
yield boto3.client('s3', region_name='us-east-1')


Expand Down
11 changes: 8 additions & 3 deletions tests/clients/boto3/test_boto3_secretsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import boto3
import pytest

from moto import mock_secretsmanager
# TODO: Remove branching when we drop support for Python 3.7
import sys
if sys.version_info >= (3, 8):
from moto import mock_aws
else:
from moto import mock_secretsmanager as mock_aws

from instana.singletons import tracer
from ...helpers import get_first_span_by_filter
Expand All @@ -30,7 +35,7 @@ def aws_credentials():

@pytest.fixture(scope='function')
def secretsmanager(aws_credentials):
with mock_secretsmanager():
with mock_aws():
yield boto3.client('secretsmanager', region_name='us-east-1')


Expand Down Expand Up @@ -80,4 +85,4 @@ def test_get_secret_value(secretsmanager):

assert boto_span.data['http']['status'] == 200
assert boto_span.data['http']['method'] == 'POST'
assert boto_span.data['http']['url'] == 'https://secretsmanager.us-east-1.amazonaws.com:443/GetSecretValue'
assert boto_span.data['http']['url'] == 'https://secretsmanager.us-east-1.amazonaws.com:443/GetSecretValue'
11 changes: 8 additions & 3 deletions tests/clients/boto3/test_boto3_ses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import boto3
import pytest

from moto import mock_ses
# TODO: Remove branching when we drop support for Python 3.7
import sys
if sys.version_info >= (3, 8):
from moto import mock_aws
else:
from moto import mock_ses as mock_aws

from instana.singletons import tracer
from ...helpers import get_first_span_by_filter
Expand All @@ -30,7 +35,7 @@ def aws_credentials():

@pytest.fixture(scope='function')
def ses(aws_credentials):
with mock_ses():
with mock_aws():
yield boto3.client('ses', region_name='us-east-1')


Expand Down Expand Up @@ -71,4 +76,4 @@ def test_verify_email(ses):

assert boto_span.data['http']['status'] == 200
assert boto_span.data['http']['method'] == 'POST'
assert boto_span.data['http']['url'] == 'https://email.us-east-1.amazonaws.com:443/VerifyEmailIdentity'
assert boto_span.data['http']['url'] == 'https://email.us-east-1.amazonaws.com:443/VerifyEmailIdentity'
11 changes: 8 additions & 3 deletions tests/clients/boto3/test_boto3_sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import pytest
import urllib3

from moto import mock_sqs
# TODO: Remove branching when we drop support for Python 3.7
import sys
if sys.version_info >= (3, 8):
from moto import mock_aws
else:
from moto import mock_sqs as mock_aws

import tests.apps.flask_app
from instana.singletons import tracer
Expand Down Expand Up @@ -38,7 +43,7 @@ def http_client():

@pytest.fixture(scope='function')
def sqs(aws_credentials):
with mock_sqs():
with mock_aws():
yield boto3.client('sqs', region_name='us-east-1')


Expand Down Expand Up @@ -113,7 +118,7 @@ def test_send_message(sqs):
assert boto_span.data['http']['url'] == 'https://sqs.us-east-1.amazonaws.com:443/SendMessage'


@mock_sqs
@mock_aws
def test_app_boto3_sqs(http_client):
with tracer.start_active_span('test'):
response = http_client.request('GET', testenv["wsgi_server"] + '/boto3/sqs')
Expand Down

0 comments on commit 7027702

Please sign in to comment.