Skip to content

Fix config test: ignore all env vars in test environment #10835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from unittest import mock

import pretend
Expand Down Expand Up @@ -157,17 +159,17 @@ def test_maybe_set_compound(monkeypatch, environ, base, name, envvar, expected):


@pytest.mark.parametrize(
("settings", "environment", "other_settings"),
("settings", "environment"),
[
(None, config.Environment.production, {}),
({}, config.Environment.production, {}),
({"my settings": "the settings value"}, config.Environment.production, {}),
(None, config.Environment.development, {}),
({}, config.Environment.development, {}),
({"my settings": "the settings value"}, config.Environment.development, {}),
(None, config.Environment.production),
({}, config.Environment.production),
({"my settings": "the settings value"}, config.Environment.production),
(None, config.Environment.development),
({}, config.Environment.development),
({"my settings": "the settings value"}, config.Environment.development),
],
)
def test_configure(monkeypatch, settings, environment, other_settings):
def test_configure(monkeypatch, settings, environment):
json_renderer_obj = pretend.stub()
json_renderer_cls = pretend.call_recorder(lambda **kw: json_renderer_obj)
monkeypatch.setattr(renderers, "JSON", json_renderer_cls)
Expand All @@ -176,8 +178,17 @@ def test_configure(monkeypatch, settings, environment, other_settings):
xmlrpc_renderer_cls = pretend.call_recorder(lambda **kw: xmlrpc_renderer_obj)
monkeypatch.setattr(config, "XMLRPCRenderer", xmlrpc_renderer_cls)

if environment == config.Environment.development:
monkeypatch.setenv("WAREHOUSE_ENV", "development")
# Ignore all environment variables in the test environment, except for WAREHOUSE_ENV
monkeypatch.setattr(
os,
"environ",
{
"WAREHOUSE_ENV": {
config.Environment.development: "development",
config.Environment.production: "production",
}[environment],
},
)

class FakeRegistry(dict):
def __init__(self):
Expand All @@ -190,7 +201,7 @@ def __init__(self):
"warehouse.xmlrpc.client.ratelimit_string": "3600 per hour",
}

configurator_settings = other_settings.copy()
configurator_settings = dict()
configurator_obj = pretend.stub(
registry=FakeRegistry(),
set_root_factory=pretend.call_recorder(lambda rf: None),
Expand Down Expand Up @@ -225,7 +236,7 @@ def __init__(self):
)
monkeypatch.setattr(config, "transaction", transaction)

result = config.configure(settings=settings)
result = config.configure(settings=settings.copy() if settings else None)

expected_settings = {
"warehouse.env": environment,
Expand Down