mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-08 08:28:24 -04:00
Merge pull request #2693 from alphagov/test-isolation-fix
Test isolation fix
This commit is contained in:
@@ -40,12 +40,12 @@ alembic==1.3.2
|
|||||||
amqp==1.4.9
|
amqp==1.4.9
|
||||||
anyjson==0.3.3
|
anyjson==0.3.3
|
||||||
attrs==19.3.0
|
attrs==19.3.0
|
||||||
awscli==1.16.305
|
awscli==1.16.310
|
||||||
bcrypt==3.1.7
|
bcrypt==3.1.7
|
||||||
billiard==3.3.0.23
|
billiard==3.3.0.23
|
||||||
bleach==3.1.0
|
bleach==3.1.0
|
||||||
boto3==1.10.38
|
boto3==1.10.38
|
||||||
botocore==1.13.41
|
botocore==1.13.46
|
||||||
certifi==2019.11.28
|
certifi==2019.11.28
|
||||||
chardet==3.0.4
|
chardet==3.0.4
|
||||||
Click==7.0
|
Click==7.0
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
-r requirements.txt
|
-r requirements.txt
|
||||||
flake8==3.7.9
|
flake8==3.7.9
|
||||||
moto==1.3.14
|
moto==1.3.14
|
||||||
pytest==5.2.4
|
pytest==5.3.2
|
||||||
pytest-env==0.6.2
|
pytest-env==0.6.2
|
||||||
pytest-mock==1.11.2
|
pytest-mock==2.0.0
|
||||||
pytest-cov==2.8.1
|
pytest-cov==2.8.1
|
||||||
pytest-xdist==1.30.0
|
pytest-xdist==1.31.0
|
||||||
freezegun==0.3.12
|
freezegun==0.3.12
|
||||||
requests-mock==1.7.0
|
requests-mock==1.7.0
|
||||||
# optional requirements for jsonschema
|
# optional requirements for jsonschema
|
||||||
|
|||||||
@@ -26,13 +26,12 @@ def cloudfoundry_config(postgres_config):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def cloudfoundry_environ(monkeypatch, cloudfoundry_config):
|
def cloudfoundry_environ(os_environ, cloudfoundry_config):
|
||||||
monkeypatch.setenv('VCAP_SERVICES', json.dumps(cloudfoundry_config))
|
os.environ['VCAP_SERVICES'] = json.dumps(cloudfoundry_config)
|
||||||
monkeypatch.setenv('VCAP_APPLICATION', '{"space_name": "🚀🌌"}')
|
os.environ['VCAP_APPLICATION'] = '{"space_name": "🚀🌌"}'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
def test_extract_cloudfoundry_config_populates_other_vars(cloudfoundry_environ):
|
||||||
def test_extract_cloudfoundry_config_populates_other_vars():
|
|
||||||
extract_cloudfoundry_config()
|
extract_cloudfoundry_config()
|
||||||
|
|
||||||
assert os.environ['SQLALCHEMY_DATABASE_URI'] == 'postgres uri'
|
assert os.environ['SQLALCHEMY_DATABASE_URI'] == 'postgres uri'
|
||||||
@@ -40,8 +39,7 @@ def test_extract_cloudfoundry_config_populates_other_vars():
|
|||||||
assert os.environ['NOTIFY_LOG_PATH'] == '/home/vcap/logs/app.log'
|
assert os.environ['NOTIFY_LOG_PATH'] == '/home/vcap/logs/app.log'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config, cloudfoundry_environ):
|
||||||
def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config):
|
|
||||||
cloudfoundry_config['foo'] = {'credentials': {'foo': 'foo'}}
|
cloudfoundry_config['foo'] = {'credentials': {'foo': 'foo'}}
|
||||||
cloudfoundry_config['user-provided'].append({
|
cloudfoundry_config['user-provided'].append({
|
||||||
'name': 'bar', 'credentials': {'bar': 'bar'}
|
'name': 'bar', 'credentials': {'bar': 'bar'}
|
||||||
|
|||||||
@@ -21,14 +21,17 @@ def reload_config():
|
|||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
os.environ = old_env
|
os.environ.clear()
|
||||||
|
for k, v in old_env.items():
|
||||||
|
os.environ[k] = v
|
||||||
|
|
||||||
importlib.reload(config)
|
importlib.reload(config)
|
||||||
|
|
||||||
|
|
||||||
def test_load_cloudfoundry_config_if_available(monkeypatch, reload_config):
|
def test_load_cloudfoundry_config_if_available(reload_config):
|
||||||
os.environ['ADMIN_BASE_URL'] = 'env'
|
os.environ['ADMIN_BASE_URL'] = 'env'
|
||||||
monkeypatch.setenv('VCAP_SERVICES', 'some json blob')
|
os.environ['VCAP_SERVICES'] = 'some json blob'
|
||||||
monkeypatch.setenv('VCAP_APPLICATION', 'some json blob')
|
os.environ['VCAP_APPLICATION'] = 'some json blob'
|
||||||
|
|
||||||
with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config', side_effect=cf_conf) as cf_config:
|
with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config', side_effect=cf_conf) as cf_config:
|
||||||
# reload config so that its module level code (ie: all of it) is re-instantiated
|
# reload config so that its module level code (ie: all of it) is re-instantiated
|
||||||
@@ -40,10 +43,9 @@ def test_load_cloudfoundry_config_if_available(monkeypatch, reload_config):
|
|||||||
assert config.Config.ADMIN_BASE_URL == 'cf'
|
assert config.Config.ADMIN_BASE_URL == 'cf'
|
||||||
|
|
||||||
|
|
||||||
def test_load_config_if_cloudfoundry_not_available(monkeypatch, reload_config):
|
def test_load_config_if_cloudfoundry_not_available(reload_config):
|
||||||
os.environ['ADMIN_BASE_URL'] = 'env'
|
os.environ['ADMIN_BASE_URL'] = 'env'
|
||||||
|
os.environ.pop('VCAP_SERVICES', None)
|
||||||
monkeypatch.delenv('VCAP_SERVICES', raising=False)
|
|
||||||
|
|
||||||
with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config') as cf_config:
|
with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config') as cf_config:
|
||||||
# reload config so that its module level code (ie: all of it) is re-instantiated
|
# reload config so that its module level code (ie: all of it) is re-instantiated
|
||||||
|
|||||||
@@ -130,15 +130,14 @@ def os_environ():
|
|||||||
"""
|
"""
|
||||||
# for use whenever you expect code to edit environment variables
|
# for use whenever you expect code to edit environment variables
|
||||||
old_env = os.environ.copy()
|
old_env = os.environ.copy()
|
||||||
|
os.environ.clear()
|
||||||
|
|
||||||
class EnvironDict(dict):
|
|
||||||
def __setitem__(self, key, value):
|
|
||||||
assert type(value) == str
|
|
||||||
super().__setitem__(key, value)
|
|
||||||
|
|
||||||
os.environ = EnvironDict()
|
|
||||||
yield
|
yield
|
||||||
os.environ = old_env
|
|
||||||
|
# clear afterwards in case anything extra was added to the environment during the test
|
||||||
|
os.environ.clear()
|
||||||
|
for k, v in old_env.items():
|
||||||
|
os.environ[k] = v
|
||||||
|
|
||||||
|
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
|
|||||||
Reference in New Issue
Block a user