Skip to content

Commit

Permalink
Config: Added tests and applied lining fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Biscgit committed Dec 18, 2024
1 parent 4c4612e commit 5bbafff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cernopendata/modules/globals/ext.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Global variables for Flask app."""

import json
import logging
import typing
Expand Down Expand Up @@ -59,7 +60,7 @@ def set_experiments(app):
# check config for custom setting
if exclude_experiments := app.config.get("EXCLUDE_EXPERIMENTS"):
if isinstance(exclude_experiments, str):
exclude_experiments = json.loads(exclude_experiments.replace("'", "\""))
exclude_experiments = json.loads(exclude_experiments.replace("'", '"'))

logger.info("Loaded experiments from string")

Expand Down
21 changes: 21 additions & 0 deletions tests/test_experiment_exclusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ def test_display_experiments_invalid_setting(app_param):
)


def test_display_experiments_json_strings(app_param):
"""Test display by setting a json-list structures, similar to how env vars work"""
cases = ["""["alice", "atlas"]""", """['alice', 'atlas']"""]
for case in cases:
expected_result = [
exp for exp in ALL_EXPERIMENTS if exp not in ["alice", "atlas"]
]

flask_app = app_param(exclude=case)

# query
about, body, footer = run_queries(flask_app)

# assert content
assert body == expected_result
assert footer == expected_result
assert set(about).difference(EXCLUDE_ABOUT) == set(expected_result).difference(
EXCLUDE_ABOUT
)


def test_display_experiments_empty_setting(app_param):
"""Test setting the configuration parameter to an empty value."""
# setup
Expand Down

0 comments on commit 5bbafff

Please sign in to comment.