Fix Mock 4.0.3 compatibility - Unpatch only once during teardown (#3541)
* #3535 - Unpatch only once during teardown * EnvVar patching - Fix Python2 bug * Allow latest version of mock-library
This commit is contained in:
parent
d8097b24dc
commit
d7b8419791
5 changed files with 83 additions and 8 deletions
34
tests/test_core/test_environ_patching.py
Normal file
34
tests/test_core/test_environ_patching.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import os
|
||||
import sure # noqa
|
||||
from moto import mock_ec2, mock_s3
|
||||
|
||||
KEY = "AWS_ACCESS_KEY_ID"
|
||||
|
||||
|
||||
def test_aws_keys_are_patched():
|
||||
with mock_ec2():
|
||||
patched_value = os.environ[KEY]
|
||||
patched_value.should.equal("foobar_key")
|
||||
|
||||
|
||||
def test_aws_keys_can_be_none():
|
||||
"""
|
||||
Verify that the os.environ[KEY] can be None
|
||||
Patching the None-value shouldn't be an issue
|
||||
"""
|
||||
original = os.environ.get(KEY, "value-set-by-user")
|
||||
# Delete the original value by the user
|
||||
try:
|
||||
del os.environ[KEY]
|
||||
except KeyError:
|
||||
pass # Value might not be set on this system in the first place
|
||||
try:
|
||||
# Verify that the os.environ[KEY] is patched
|
||||
with mock_s3():
|
||||
patched_value = os.environ[KEY]
|
||||
patched_value.should.equal("foobar_key")
|
||||
# Verify that the os.environ[KEY] is unpatched, and reverts to None
|
||||
assert os.environ.get(KEY) is None
|
||||
finally:
|
||||
# Reset the value original - don't want to change the users system
|
||||
os.environ[KEY] = original
|
||||
18
tests/test_s3/test_s3_classdecorator.py
Normal file
18
tests/test_s3/test_s3_classdecorator.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import unittest
|
||||
|
||||
import boto3
|
||||
from moto import mock_s3
|
||||
|
||||
|
||||
@mock_s3
|
||||
class ClassDecoratorTest(unittest.TestCase):
|
||||
"""
|
||||
https://github.com/spulec/moto/issues/3535
|
||||
An update to the mock-package introduced a failure during teardown.
|
||||
This test is in place to catch any similar failures with our mocking approach
|
||||
"""
|
||||
|
||||
def test_instantiation_succeeds(self):
|
||||
s3 = boto3.client("s3", region_name="us-east-1")
|
||||
|
||||
assert s3 is not None
|
||||
Loading…
Add table
Add a link
Reference in a new issue