Skip to content

Commit adff6be

Browse files
committed
fix(tests): Adapt to moto 5
Signed-off-by: Ferenc Géczi <ferenc.geczi@ibm.com>
1 parent 715edda commit adff6be

File tree

7 files changed

+48
-18
lines changed

7 files changed

+48
-18
lines changed

tests/apps/flask_app/app.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313

1414
try:
1515
import boto3
16-
from moto import mock_sqs
16+
# TODO: Remove branching when we drop support for Python 3.7
17+
import sys
18+
if sys.version_info >= (3, 8):
19+
from moto import mock_aws
20+
else:
21+
from moto import mock_sqs as mock_aws
1722
except ImportError:
1823
# Doesn't matter. We won't call routes using boto3
1924
# in test sets that don't install/test for it.
@@ -174,7 +179,7 @@ def boto3_sqs():
174179
os.environ['AWS_SECURITY_TOKEN'] = 'testing'
175180
os.environ['AWS_SESSION_TOKEN'] = 'testing'
176181

177-
with mock_sqs():
182+
with mock_aws():
178183
boto3_client = boto3.client('sqs', region_name='us-east-1')
179184
response = boto3_client.create_queue(
180185
QueueName='SQS_QUEUE_NAME',

tests/clients/boto3/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ If you would like to run this test server manually from an ipython console:
44
import os
55
import urllib3
66
7-
from moto import mock_sqs
7+
from moto import mock_aws
88
import tests.apps.flask_app
99
from tests.helpers import testenv
1010
from instana.singletons import tracer
@@ -16,7 +16,7 @@ os.environ['AWS_SECRET_ACCESS_KEY'] = 'testing'
1616
os.environ['AWS_SECURITY_TOKEN'] = 'testing'
1717
os.environ['AWS_SESSION_TOKEN'] = 'testing'
1818
19-
@mock_sqs
19+
@mock_aws
2020
def test_app_boto3_sqs():
2121
with tracer.start_active_span('wsgi') as scope:
2222
scope.span.set_tag('span.kind', 'entry')
@@ -26,4 +26,4 @@ def test_app_boto3_sqs():
2626
scope.span.set_tag('http.status_code', 200)
2727
response = http_client.request('GET', testenv["wsgi_server"] + '/boto3/sqs')
2828
29-
```
29+
```

tests/clients/boto3/test_boto3_lambda.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import boto3
88
import pytest
99

10-
from moto import mock_lambda
10+
# TODO: Remove branching when we drop support for Python 3.7
11+
import sys
12+
if sys.version_info >= (3, 8):
13+
from moto import mock_aws
14+
else:
15+
from moto import mock_sqs as mock_aws
1116

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

2530
@pytest.fixture(scope='function')
2631
def aws_lambda(aws_credentials):
27-
with mock_lambda():
32+
with mock_aws():
2833
yield boto3.client('lambda', region_name='us-east-1')
2934

3035

tests/clients/boto3/test_boto3_s3.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import boto3
88
import pytest
99

10-
from moto import mock_s3
10+
# TODO: Remove branching when we drop support for Python 3.7
11+
import sys
12+
if sys.version_info >= (3, 8):
13+
from moto import mock_aws
14+
else:
15+
from moto import mock_s3 as mock_aws
1116

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

3540
@pytest.fixture(scope='function')
3641
def s3(aws_credentials):
37-
with mock_s3():
42+
with mock_aws():
3843
yield boto3.client('s3', region_name='us-east-1')
3944

4045

tests/clients/boto3/test_boto3_secretsmanager.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import boto3
88
import pytest
99

10-
from moto import mock_secretsmanager
10+
# TODO: Remove branching when we drop support for Python 3.7
11+
import sys
12+
if sys.version_info >= (3, 8):
13+
from moto import mock_aws
14+
else:
15+
from moto import mock_secretsmanager as mock_aws
1116

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

3136
@pytest.fixture(scope='function')
3237
def secretsmanager(aws_credentials):
33-
with mock_secretsmanager():
38+
with mock_aws():
3439
yield boto3.client('secretsmanager', region_name='us-east-1')
3540

3641

@@ -80,4 +85,4 @@ def test_get_secret_value(secretsmanager):
8085

8186
assert boto_span.data['http']['status'] == 200
8287
assert boto_span.data['http']['method'] == 'POST'
83-
assert boto_span.data['http']['url'] == 'https://secretsmanager.us-east-1.amazonaws.com:443/GetSecretValue'
88+
assert boto_span.data['http']['url'] == 'https://secretsmanager.us-east-1.amazonaws.com:443/GetSecretValue'

tests/clients/boto3/test_boto3_ses.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import boto3
88
import pytest
99

10-
from moto import mock_ses
10+
# TODO: Remove branching when we drop support for Python 3.7
11+
import sys
12+
if sys.version_info >= (3, 8):
13+
from moto import mock_aws
14+
else:
15+
from moto import mock_ses as mock_aws
1116

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

3136
@pytest.fixture(scope='function')
3237
def ses(aws_credentials):
33-
with mock_ses():
38+
with mock_aws():
3439
yield boto3.client('ses', region_name='us-east-1')
3540

3641

@@ -71,4 +76,4 @@ def test_verify_email(ses):
7176

7277
assert boto_span.data['http']['status'] == 200
7378
assert boto_span.data['http']['method'] == 'POST'
74-
assert boto_span.data['http']['url'] == 'https://email.us-east-1.amazonaws.com:443/VerifyEmailIdentity'
79+
assert boto_span.data['http']['url'] == 'https://email.us-east-1.amazonaws.com:443/VerifyEmailIdentity'

tests/clients/boto3/test_boto3_sqs.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
import pytest
99
import urllib3
1010

11-
from moto import mock_sqs
11+
# TODO: Remove branching when we drop support for Python 3.7
12+
import sys
13+
if sys.version_info >= (3, 8):
14+
from moto import mock_aws
15+
else:
16+
from moto import mock_sqs as mock_aws
1217

1318
import tests.apps.flask_app
1419
from instana.singletons import tracer
@@ -38,7 +43,7 @@ def http_client():
3843

3944
@pytest.fixture(scope='function')
4045
def sqs(aws_credentials):
41-
with mock_sqs():
46+
with mock_aws():
4247
yield boto3.client('sqs', region_name='us-east-1')
4348

4449

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

115120

116-
@mock_sqs
121+
@mock_aws
117122
def test_app_boto3_sqs(http_client):
118123
with tracer.start_active_span('test'):
119124
response = http_client.request('GET', testenv["wsgi_server"] + '/boto3/sqs')

0 commit comments

Comments
 (0)