Fix for moto not unmocking.
- Fixes #2575 - Also upgraded Travis CI to make use of Bionic instead of Xenial - This may also address concerns raised in #1793
This commit is contained in:
parent
6922606398
commit
bd777cad44
@ -1,4 +1,4 @@
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
language: python
|
||||
services:
|
||||
- docker
|
||||
|
@ -44,6 +44,7 @@ class BaseMockAWS(object):
|
||||
"AWS_ACCESS_KEY_ID": "foobar_key",
|
||||
"AWS_SECRET_ACCESS_KEY": "foobar_secret",
|
||||
}
|
||||
self.default_session_mock = mock.patch("boto3.DEFAULT_SESSION", None)
|
||||
self.env_variables_mocks = mock.patch.dict(os.environ, FAKE_KEYS)
|
||||
|
||||
if self.__class__.nested_count == 0:
|
||||
@ -62,6 +63,7 @@ class BaseMockAWS(object):
|
||||
self.stop()
|
||||
|
||||
def start(self, reset=True):
|
||||
self.default_session_mock.start()
|
||||
self.env_variables_mocks.start()
|
||||
|
||||
self.__class__.nested_count += 1
|
||||
@ -72,6 +74,7 @@ class BaseMockAWS(object):
|
||||
self.enable_patching()
|
||||
|
||||
def stop(self):
|
||||
self.default_session_mock.stop()
|
||||
self.env_variables_mocks.stop()
|
||||
self.__class__.nested_count -= 1
|
||||
|
||||
|
@ -1001,10 +1001,10 @@ def test_list_versions_by_function_for_nonexistent_function():
|
||||
@mock_lambda
|
||||
@mock_sqs
|
||||
def test_create_event_source_mapping():
|
||||
sqs = boto3.resource("sqs")
|
||||
sqs = boto3.resource("sqs", region_name="us-east-1")
|
||||
queue = sqs.create_queue(QueueName="test-sqs-queue1")
|
||||
|
||||
conn = boto3.client("lambda")
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python2.7",
|
||||
@ -1030,11 +1030,11 @@ def test_create_event_source_mapping():
|
||||
@mock_lambda
|
||||
@mock_sqs
|
||||
def test_invoke_function_from_sqs():
|
||||
logs_conn = boto3.client("logs")
|
||||
sqs = boto3.resource("sqs")
|
||||
logs_conn = boto3.client("logs", region_name="us-east-1")
|
||||
sqs = boto3.resource("sqs", region_name="us-east-1")
|
||||
queue = sqs.create_queue(QueueName="test-sqs-queue1")
|
||||
|
||||
conn = boto3.client("lambda")
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python2.7",
|
||||
@ -1054,7 +1054,7 @@ def test_invoke_function_from_sqs():
|
||||
assert response["EventSourceArn"] == queue.attributes["QueueArn"]
|
||||
assert response["State"] == "Enabled"
|
||||
|
||||
sqs_client = boto3.client("sqs")
|
||||
sqs_client = boto3.client("sqs", region_name="us-east-1")
|
||||
sqs_client.send_message(QueueUrl=queue.url, MessageBody="test")
|
||||
start = time.time()
|
||||
while (time.time() - start) < 30:
|
||||
@ -1081,8 +1081,8 @@ def test_invoke_function_from_sqs():
|
||||
@mock_lambda
|
||||
@mock_dynamodb2
|
||||
def test_invoke_function_from_dynamodb():
|
||||
logs_conn = boto3.client("logs")
|
||||
dynamodb = boto3.client("dynamodb")
|
||||
logs_conn = boto3.client("logs", region_name="us-east-1")
|
||||
dynamodb = boto3.client("dynamodb", region_name="us-east-1")
|
||||
table_name = "table_with_stream"
|
||||
table = dynamodb.create_table(
|
||||
TableName=table_name,
|
||||
@ -1094,7 +1094,7 @@ def test_invoke_function_from_dynamodb():
|
||||
},
|
||||
)
|
||||
|
||||
conn = boto3.client("lambda")
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python2.7",
|
||||
@ -1141,11 +1141,11 @@ def test_invoke_function_from_dynamodb():
|
||||
@mock_lambda
|
||||
@mock_sqs
|
||||
def test_invoke_function_from_sqs_exception():
|
||||
logs_conn = boto3.client("logs")
|
||||
sqs = boto3.resource("sqs")
|
||||
logs_conn = boto3.client("logs", region_name="us-east-1")
|
||||
sqs = boto3.resource("sqs", region_name="us-east-1")
|
||||
queue = sqs.create_queue(QueueName="test-sqs-queue1")
|
||||
|
||||
conn = boto3.client("lambda")
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python2.7",
|
||||
@ -1201,10 +1201,10 @@ def test_invoke_function_from_sqs_exception():
|
||||
@mock_lambda
|
||||
@mock_sqs
|
||||
def test_list_event_source_mappings():
|
||||
sqs = boto3.resource("sqs")
|
||||
sqs = boto3.resource("sqs", region_name="us-east-1")
|
||||
queue = sqs.create_queue(QueueName="test-sqs-queue1")
|
||||
|
||||
conn = boto3.client("lambda")
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python2.7",
|
||||
@ -1233,10 +1233,10 @@ def test_list_event_source_mappings():
|
||||
@mock_lambda
|
||||
@mock_sqs
|
||||
def test_get_event_source_mapping():
|
||||
sqs = boto3.resource("sqs")
|
||||
sqs = boto3.resource("sqs", region_name="us-east-1")
|
||||
queue = sqs.create_queue(QueueName="test-sqs-queue1")
|
||||
|
||||
conn = boto3.client("lambda")
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python2.7",
|
||||
@ -1263,10 +1263,10 @@ def test_get_event_source_mapping():
|
||||
@mock_lambda
|
||||
@mock_sqs
|
||||
def test_update_event_source_mapping():
|
||||
sqs = boto3.resource("sqs")
|
||||
sqs = boto3.resource("sqs", region_name="us-east-1")
|
||||
queue = sqs.create_queue(QueueName="test-sqs-queue1")
|
||||
|
||||
conn = boto3.client("lambda")
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func1 = conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python2.7",
|
||||
@ -1307,10 +1307,10 @@ def test_update_event_source_mapping():
|
||||
@mock_lambda
|
||||
@mock_sqs
|
||||
def test_delete_event_source_mapping():
|
||||
sqs = boto3.resource("sqs")
|
||||
sqs = boto3.resource("sqs", region_name="us-east-1")
|
||||
queue = sqs.create_queue(QueueName="test-sqs-queue1")
|
||||
|
||||
conn = boto3.client("lambda")
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func1 = conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python2.7",
|
||||
|
@ -3119,8 +3119,8 @@ def test_sorted_query_with_numerical_sort_key():
|
||||
# https://github.com/spulec/moto/issues/1874
|
||||
@mock_dynamodb2
|
||||
def test_item_size_is_under_400KB():
|
||||
dynamodb = boto3.resource("dynamodb")
|
||||
client = boto3.client("dynamodb")
|
||||
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
dynamodb.create_table(
|
||||
TableName="moto-test",
|
||||
@ -3172,7 +3172,7 @@ def assert_failure_due_to_item_size(func, **kwargs):
|
||||
@mock_dynamodb2
|
||||
# https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html#DDB-Query-request-KeyConditionExpression
|
||||
def test_hash_key_cannot_use_begins_with_operations():
|
||||
dynamodb = boto3.resource("dynamodb")
|
||||
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
|
||||
table = dynamodb.create_table(
|
||||
TableName="test-table",
|
||||
KeySchema=[{"AttributeName": "key", "KeyType": "HASH"}],
|
||||
@ -3201,7 +3201,7 @@ def test_hash_key_cannot_use_begins_with_operations():
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_update_supports_complex_expression_attribute_values():
|
||||
client = boto3.client("dynamodb")
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
client.create_table(
|
||||
AttributeDefinitions=[{"AttributeName": "SHA256", "AttributeType": "S"}],
|
||||
@ -3237,7 +3237,7 @@ def test_update_supports_complex_expression_attribute_values():
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_update_supports_list_append():
|
||||
client = boto3.client("dynamodb")
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
client.create_table(
|
||||
AttributeDefinitions=[{"AttributeName": "SHA256", "AttributeType": "S"}],
|
||||
@ -3272,7 +3272,7 @@ def test_update_supports_list_append():
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_update_catches_invalid_list_append_operation():
|
||||
client = boto3.client("dynamodb")
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
client.create_table(
|
||||
AttributeDefinitions=[{"AttributeName": "SHA256", "AttributeType": "S"}],
|
||||
|
@ -524,7 +524,7 @@ def _get_account_id():
|
||||
global account_id
|
||||
if account_id:
|
||||
return account_id
|
||||
sts = boto3.client("sts")
|
||||
sts = boto3.client("sts", region_name=region)
|
||||
identity = sts.get_caller_identity()
|
||||
account_id = identity["Account"]
|
||||
return account_id
|
||||
|
Loading…
Reference in New Issue
Block a user