81 lines
3.3 KiB
Python
81 lines
3.3 KiB
Python
"""The container entry point configures Red correctly."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from dogebot import start
|
|
|
|
|
|
def test_instance_config_leaves_connection_to_env(tmp_path: Path) -> None:
|
|
"""No password ends up in Red's config file."""
|
|
config = start.instance_config(tmp_path)
|
|
assert config["STORAGE_TYPE"] == "Postgres"
|
|
assert set(config["STORAGE_DETAILS"].values()) == {None}
|
|
assert config["DATA_PATH"] == str(tmp_path)
|
|
|
|
|
|
def test_write_instance_config_keeps_other_instances(tmp_path: Path) -> None:
|
|
"""Writing one instance doesn't drop the others."""
|
|
config_file = tmp_path / "Red-DiscordBot/config.json"
|
|
config_file.parent.mkdir()
|
|
config_file.write_text(json.dumps({"other": {"DATA_PATH": "/x"}}))
|
|
start.write_instance_config(config_file, "dogebot", tmp_path / "data")
|
|
instances = json.loads(config_file.read_text())
|
|
assert set(instances) == {"other", "dogebot"}
|
|
|
|
|
|
def test_install_bundled_cogs_replaces_old_copy(tmp_path: Path) -> None:
|
|
"""A cog is copied into Red's install path, replacing stale files."""
|
|
stale = tmp_path / "cogs/CogManager/cogs/dogesetup/old.py"
|
|
stale.parent.mkdir(parents=True)
|
|
stale.write_text("")
|
|
start.install_bundled_cogs(tmp_path)
|
|
assert not stale.exists()
|
|
|
|
|
|
def test_bundled_cogs_are_all_installed(tmp_path: Path) -> None:
|
|
"""Every cog shipped in the image's cogs folder lands in Red's path."""
|
|
targets = start.install_bundled_cogs(tmp_path)
|
|
assert sorted(t.name for t in targets) == ["dogesetup", "selftest"]
|
|
for target in targets:
|
|
assert (target / f"{target.name}.py").is_file()
|
|
assert (target / "info.json").is_file()
|
|
|
|
|
|
def test_redbot_args() -> None:
|
|
"""Red runs without prompts, loads dogesetup and gets every prefix."""
|
|
args = start.redbot_args("dogebot", ["d!", "!"])
|
|
assert args[:3] == ["redbot", "dogebot", "--no-prompt"]
|
|
assert args[args.index("--load-cogs") + 1] == "dogesetup"
|
|
assert args.count("--prefix") == 2
|
|
|
|
|
|
def test_co_owners_are_additive_without_replacing_primary_owner() -> None:
|
|
"""Red's co-owner flag retains the bot application's existing owner."""
|
|
args = start.redbot_args("dogebot", ["d!"], [219570185919528961, 123])
|
|
assert args[args.index("--co-owner") + 1 :] == [
|
|
"219570185919528961",
|
|
"123",
|
|
]
|
|
assert "--owner" not in args
|
|
assert "--co-owner" not in start.redbot_args("dogebot", ["d!"])
|
|
|
|
|
|
def test_record_python_on_fresh_instance(tmp_path: Path) -> None:
|
|
"""A fresh instance (nothing recorded, no lib) gets the version."""
|
|
assert start.should_record_python(None, [3, 11], tmp_path / "lib")
|
|
assert start.should_record_python([3, 7], [3, 11], tmp_path / "lib")
|
|
|
|
|
|
def test_record_python_skips_when_unchanged(tmp_path: Path) -> None:
|
|
"""Nothing to do when Red already saw this Python."""
|
|
assert not start.should_record_python([3, 11], [3, 11], tmp_path)
|
|
|
|
|
|
def test_record_python_leaves_real_upgrades_to_red(tmp_path: Path) -> None:
|
|
"""With requirements built for another Python, Red must clear them."""
|
|
lib = tmp_path / "lib"
|
|
lib.mkdir()
|
|
(lib / "somepackage").mkdir()
|
|
assert not start.should_record_python([3, 10], [3, 11], lib)
|