| 1 | from lib import env |
| 2 | |
| 3 | |
| 4 | def test_default_search_defaults_to_empty_string(monkeypatch, tmp_path): |
| 5 | # Ensure the env var is not set |
| 6 | monkeypatch.delenv("LAST30DAYS_DEFAULT_SEARCH", raising=False) |
| 7 | |
| 8 | # Avoid reading any real user config file by patching the resolved module path directly |
| 9 | monkeypatch.setattr(env, "CONFIG_FILE", tmp_path / "does-not-exist.env") |
| 10 | |
| 11 | cfg = env.get_config() |
| 12 | |
| 13 | assert "LAST30DAYS_DEFAULT_SEARCH" in cfg |
| 14 | assert cfg["LAST30DAYS_DEFAULT_SEARCH"] == "" |
| 15 | |
| 16 | |
| 17 | def test_default_search_read_from_environment(monkeypatch, tmp_path): |
| 18 | monkeypatch.setenv("LAST30DAYS_DEFAULT_SEARCH", "reddit,x,youtube") |
| 19 | monkeypatch.setattr(env, "CONFIG_FILE", tmp_path / "does-not-exist.env") |
| 20 | |
| 21 | cfg = env.get_config() |
| 22 | |
| 23 | assert cfg["LAST30DAYS_DEFAULT_SEARCH"] == "reddit,x,youtube" |
| 24 | |
| 25 | |
| 26 | def test_default_search_read_from_env_file(monkeypatch, tmp_path): |
| 27 | monkeypatch.delenv("LAST30DAYS_DEFAULT_SEARCH", raising=False) |
| 28 | env_file = tmp_path / "config.env" |
| 29 | env_file.write_text("LAST30DAYS_DEFAULT_SEARCH=reddit,hn\n") |
| 30 | monkeypatch.setattr(env, "CONFIG_FILE", env_file) |
| 31 | |
| 32 | cfg = env.get_config() |
| 33 | |
| 34 | assert cfg["LAST30DAYS_DEFAULT_SEARCH"] == "reddit,hn" |
| 35 |