don't store non-strings to os.environ

in tests, we were replacing os.environ with a basic dict so that
we didn't overwrite the contents of the real environment during tests.
However, os.environ doesn't accept non-str values, so this commit
changes the fixture so that it asserts all values set are strings.
We needed to change how we store ip whitelist stuff in the env because
of this.
This commit is contained in:
Leo Hemsted
2017-07-11 15:41:44 +01:00
parent 2fde4b2c80
commit 7f883f1355
4 changed files with 11 additions and 4 deletions

View File

@@ -204,4 +204,4 @@ def test_redis_config():
def test_sms_inbound_config():
extract_cloudfoundry_config()
assert os.environ['SMS_INBOUND_WHITELIST'] == ['111.111.111.111', '100.100.100.100']
assert os.environ['SMS_INBOUND_WHITELIST'] == json.dumps(['111.111.111.111', '100.100.100.100'])

View File

@@ -90,7 +90,13 @@ def os_environ():
"""
# for use whenever you expect code to edit environment variables
old_env = os.environ.copy()
os.environ = {}
class EnvironDict(dict):
def __setitem__(self, key, value):
assert type(value) == str
super().__setitem__(key, value)
os.environ = EnvironDict()
yield
os.environ = old_env