feat: Migrate Arbiter and Modpack Version Checker to monorepo
WHAT WAS DONE: - Migrated Arbiter (discord-oauth-arbiter) code to services/arbiter/ - Migrated Modpack Version Checker code to services/modpack-version-checker/ - Created .env.example for Arbiter with all required environment variables - Moved systemd service file to services/arbiter/deploy/ - Organized directory structure per Gemini monorepo recommendations WHY: - Consolidate all service code in one repository - Prepare for Gemini code review (Panel v1.12 compatibility check) - Enable service-prefixed Git tagging (arbiter-v2.1.0, modpack-v1.0.0) - Support npm workspaces for shared dependencies SERVICES MIGRATED: 1. Arbiter (Discord OAuth bot) - Originally written by Gemini + Claude - Full source code from ops-manual docs/implementation/ - Created comprehensive .env.example - Ready for Panel v1.12 compatibility verification 2. Modpack Version Checker (Python CLI tool) - Full source code from ops-manual docs/tasks/ - Written for Panel v1.11, needs Gemini review for v1.12 - Never had code review before STILL TODO: - Whitelist Manager - Pull from Billing VPS (38.68.14.188) - Currently deployed and running - Needs Panel v1.12 API compatibility fix (Task #86) - Requires SSH access to pull code NEXT STEPS: - Gemini code review for Panel v1.12 API compatibility - Create package.json for each service - Test npm workspaces integration - Deploy after verification FILES: - services/arbiter/ (25 new files, full application) - services/modpack-version-checker/ (21 new files, full application) Signed-off-by: The Golden Chronicler <claude@firefrostgaming.com>
This commit is contained in:
0
services/modpack-version-checker/tests/__init__.py
Normal file
0
services/modpack-version-checker/tests/__init__.py
Normal file
11
services/modpack-version-checker/tests/conftest.py
Normal file
11
services/modpack-version-checker/tests/conftest.py
Normal file
@@ -0,0 +1,11 @@
|
||||
"""Shared pytest fixtures."""
|
||||
|
||||
import pytest
|
||||
|
||||
from modpack_checker.database import Database
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db(tmp_path):
|
||||
"""In-memory-equivalent SQLite database backed by a temp directory."""
|
||||
return Database(str(tmp_path / "test.db"))
|
||||
339
services/modpack-version-checker/tests/test_cli.py
Normal file
339
services/modpack-version-checker/tests/test_cli.py
Normal file
@@ -0,0 +1,339 @@
|
||||
"""Tests for cli.py using Click's test runner."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import responses as responses_lib
|
||||
from click.testing import CliRunner
|
||||
|
||||
from modpack_checker.cli import cli
|
||||
from modpack_checker.curseforge import CurseForgeNotFoundError
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def runner():
|
||||
return CliRunner()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_cfg(tmp_path):
|
||||
"""Return a Config-like mock backed by a real temp database."""
|
||||
cfg = MagicMock()
|
||||
cfg.curseforge_api_key = "test-api-key"
|
||||
cfg.database_path = str(tmp_path / "test.db")
|
||||
cfg.discord_webhook_url = None
|
||||
cfg.notification_on_update = True
|
||||
cfg.check_interval_hours = 6
|
||||
return cfg
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Root / help
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_help(runner):
|
||||
result = runner.invoke(cli, ["--help"])
|
||||
assert result.exit_code == 0
|
||||
assert "Modpack Version Checker" in result.output
|
||||
|
||||
|
||||
def test_version(runner):
|
||||
result = runner.invoke(cli, ["--version"])
|
||||
assert result.exit_code == 0
|
||||
assert "1.0.0" in result.output
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# config show
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_config_show(runner, mock_cfg):
|
||||
mock_cfg.curseforge_api_key = "abcd1234efgh5678"
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["config", "show"])
|
||||
assert result.exit_code == 0
|
||||
assert "abcd" in result.output # first 4 chars
|
||||
assert "5678" in result.output # last 4 chars
|
||||
|
||||
|
||||
def test_config_show_no_key(runner, mock_cfg):
|
||||
mock_cfg.curseforge_api_key = ""
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["config", "show"])
|
||||
assert result.exit_code == 0
|
||||
assert "Not configured" in result.output
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# list
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_list_empty(runner, mock_cfg):
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["list"])
|
||||
assert result.exit_code == 0
|
||||
assert "empty" in result.output.lower()
|
||||
|
||||
|
||||
def test_list_with_modpacks(runner, mock_cfg, tmp_path):
|
||||
from modpack_checker.database import Database
|
||||
db = Database(str(tmp_path / "test.db"))
|
||||
db.add_modpack(111, "Pack Alpha")
|
||||
db.add_modpack(222, "Pack Beta")
|
||||
|
||||
mock_cfg.database_path = str(tmp_path / "test.db")
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["list"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "Pack Alpha" in result.output
|
||||
assert "Pack Beta" in result.output
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# add
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_add_requires_api_key(runner, mock_cfg):
|
||||
mock_cfg.curseforge_api_key = ""
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["add", "12345"])
|
||||
assert result.exit_code == 1
|
||||
assert "API key" in result.output
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_add_success(runner, mock_cfg):
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
"https://api.curseforge.com/v1/mods/12345",
|
||||
json={"data": {"id": 12345, "name": "Test Modpack", "latestFiles": []}},
|
||||
status=200,
|
||||
)
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["add", "12345"])
|
||||
assert result.exit_code == 0
|
||||
assert "Test Modpack" in result.output
|
||||
assert "tracking" in result.output.lower()
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_add_not_found(runner, mock_cfg):
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
"https://api.curseforge.com/v1/mods/99999",
|
||||
status=404,
|
||||
)
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["add", "99999"])
|
||||
assert result.exit_code == 1
|
||||
assert "99999" in result.output
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_add_duplicate_shows_warning(runner, mock_cfg, tmp_path):
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
"https://api.curseforge.com/v1/mods/12345",
|
||||
json={"data": {"id": 12345, "name": "Test Modpack", "latestFiles": []}},
|
||||
status=200,
|
||||
)
|
||||
from modpack_checker.database import Database
|
||||
db = Database(str(tmp_path / "test.db"))
|
||||
db.add_modpack(12345, "Test Modpack")
|
||||
|
||||
mock_cfg.database_path = str(tmp_path / "test.db")
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["add", "12345"])
|
||||
assert "already tracked" in result.output.lower()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# remove
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_remove_not_in_list(runner, mock_cfg):
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["remove", "99999"], input="y\n")
|
||||
assert result.exit_code == 1
|
||||
assert "not in your watch list" in result.output
|
||||
|
||||
|
||||
def test_remove_success(runner, mock_cfg, tmp_path):
|
||||
from modpack_checker.database import Database
|
||||
db = Database(str(tmp_path / "test.db"))
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
|
||||
mock_cfg.database_path = str(tmp_path / "test.db")
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["remove", "12345"], input="y\n")
|
||||
assert result.exit_code == 0
|
||||
assert "Removed" in result.output
|
||||
|
||||
|
||||
def test_remove_aborted(runner, mock_cfg, tmp_path):
|
||||
from modpack_checker.database import Database
|
||||
db = Database(str(tmp_path / "test.db"))
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
|
||||
mock_cfg.database_path = str(tmp_path / "test.db")
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["remove", "12345"], input="n\n")
|
||||
# Aborted — pack should still exist
|
||||
assert db.get_modpack(12345) is not None
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# check
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_check_empty_list(runner, mock_cfg):
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["check"])
|
||||
assert result.exit_code == 0
|
||||
assert "No modpacks" in result.output
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_check_up_to_date(runner, mock_cfg, tmp_path):
|
||||
from modpack_checker.database import Database
|
||||
db = Database(str(tmp_path / "test.db"))
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
db.update_version(12345, "1.0.0")
|
||||
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
"https://api.curseforge.com/v1/mods/12345",
|
||||
json={
|
||||
"data": {
|
||||
"id": 12345,
|
||||
"name": "Test Pack",
|
||||
"latestFiles": [
|
||||
{
|
||||
"id": 1,
|
||||
"displayName": "1.0.0",
|
||||
"fileName": "pack-1.0.0.zip",
|
||||
"fileDate": "2026-01-01T00:00:00Z",
|
||||
}
|
||||
],
|
||||
}
|
||||
},
|
||||
status=200,
|
||||
)
|
||||
|
||||
mock_cfg.database_path = str(tmp_path / "test.db")
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["check", "--no-notify"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "up to date" in result.output.lower()
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_check_update_available(runner, mock_cfg, tmp_path):
|
||||
from modpack_checker.database import Database
|
||||
db = Database(str(tmp_path / "test.db"))
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
db.update_version(12345, "1.0.0")
|
||||
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
"https://api.curseforge.com/v1/mods/12345",
|
||||
json={
|
||||
"data": {
|
||||
"id": 12345,
|
||||
"name": "Test Pack",
|
||||
"latestFiles": [
|
||||
{
|
||||
"id": 2,
|
||||
"displayName": "1.1.0",
|
||||
"fileName": "pack-1.1.0.zip",
|
||||
"fileDate": "2026-02-01T00:00:00Z",
|
||||
}
|
||||
],
|
||||
}
|
||||
},
|
||||
status=200,
|
||||
)
|
||||
|
||||
mock_cfg.database_path = str(tmp_path / "test.db")
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["check", "--no-notify"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "1.1.0" in result.output
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# status
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_status_not_found(runner, mock_cfg):
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["status", "99999"])
|
||||
assert result.exit_code == 1
|
||||
assert "not in your watch list" in result.output
|
||||
|
||||
|
||||
def test_status_shows_info(runner, mock_cfg, tmp_path):
|
||||
from modpack_checker.database import Database
|
||||
db = Database(str(tmp_path / "test.db"))
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
db.update_version(12345, "2.0.0")
|
||||
|
||||
mock_cfg.database_path = str(tmp_path / "test.db")
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["status", "12345"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "Test Pack" in result.output
|
||||
assert "2.0.0" in result.output
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# notifications command
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_notifications_disable(runner, mock_cfg, tmp_path):
|
||||
from modpack_checker.database import Database
|
||||
db = Database(str(tmp_path / "test.db"))
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
|
||||
mock_cfg.database_path = str(tmp_path / "test.db")
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["notifications", "12345", "--disable"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "disabled" in result.output
|
||||
assert db.get_modpack(12345).notification_enabled is False
|
||||
|
||||
|
||||
def test_notifications_enable(runner, mock_cfg, tmp_path):
|
||||
from modpack_checker.database import Database
|
||||
db = Database(str(tmp_path / "test.db"))
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
db.toggle_notifications(12345, False)
|
||||
|
||||
mock_cfg.database_path = str(tmp_path / "test.db")
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["notifications", "12345", "--enable"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "enabled" in result.output
|
||||
assert db.get_modpack(12345).notification_enabled is True
|
||||
|
||||
|
||||
def test_notifications_missing_modpack(runner, mock_cfg):
|
||||
with patch("modpack_checker.cli.Config.load", return_value=mock_cfg):
|
||||
result = runner.invoke(cli, ["notifications", "99999", "--enable"])
|
||||
assert result.exit_code == 1
|
||||
72
services/modpack-version-checker/tests/test_config.py
Normal file
72
services/modpack-version-checker/tests/test_config.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""Tests for config.py."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from modpack_checker.config import Config
|
||||
|
||||
|
||||
def test_default_values():
|
||||
cfg = Config()
|
||||
assert cfg.curseforge_api_key == ""
|
||||
assert cfg.discord_webhook_url is None
|
||||
assert cfg.check_interval_hours == 6
|
||||
assert cfg.notification_on_update is True
|
||||
|
||||
|
||||
def test_is_configured_without_key():
|
||||
assert Config().is_configured() is False
|
||||
|
||||
|
||||
def test_is_configured_with_key():
|
||||
assert Config(curseforge_api_key="abc123").is_configured() is True
|
||||
|
||||
|
||||
def test_save_and_load_round_trip(tmp_path):
|
||||
config_dir = tmp_path / ".config" / "modpack-checker"
|
||||
config_file = config_dir / "config.json"
|
||||
|
||||
with patch("modpack_checker.config.CONFIG_DIR", config_dir), \
|
||||
patch("modpack_checker.config.CONFIG_FILE", config_file):
|
||||
original = Config(
|
||||
curseforge_api_key="test-key-xyz",
|
||||
check_interval_hours=12,
|
||||
notification_on_update=False,
|
||||
)
|
||||
original.save()
|
||||
|
||||
loaded = Config.load()
|
||||
|
||||
assert loaded.curseforge_api_key == "test-key-xyz"
|
||||
assert loaded.check_interval_hours == 12
|
||||
assert loaded.notification_on_update is False
|
||||
|
||||
|
||||
def test_load_returns_defaults_when_file_missing(tmp_path):
|
||||
config_file = tmp_path / "nonexistent.json"
|
||||
with patch("modpack_checker.config.CONFIG_FILE", config_file):
|
||||
cfg = Config.load()
|
||||
assert cfg.curseforge_api_key == ""
|
||||
|
||||
|
||||
def test_load_returns_defaults_on_corrupted_file(tmp_path):
|
||||
config_dir = tmp_path / ".config" / "modpack-checker"
|
||||
config_dir.mkdir(parents=True)
|
||||
config_file = config_dir / "config.json"
|
||||
config_file.write_text("{ this is not valid json }")
|
||||
|
||||
with patch("modpack_checker.config.CONFIG_DIR", config_dir), \
|
||||
patch("modpack_checker.config.CONFIG_FILE", config_file):
|
||||
cfg = Config.load()
|
||||
|
||||
assert cfg.curseforge_api_key == ""
|
||||
|
||||
|
||||
def test_interval_bounds():
|
||||
with pytest.raises(Exception):
|
||||
Config(check_interval_hours=0)
|
||||
with pytest.raises(Exception):
|
||||
Config(check_interval_hours=169)
|
||||
227
services/modpack-version-checker/tests/test_curseforge.py
Normal file
227
services/modpack-version-checker/tests/test_curseforge.py
Normal file
@@ -0,0 +1,227 @@
|
||||
"""Tests for curseforge.py."""
|
||||
|
||||
import pytest
|
||||
import responses as responses_lib
|
||||
|
||||
from modpack_checker.curseforge import (
|
||||
CurseForgeAuthError,
|
||||
CurseForgeClient,
|
||||
CurseForgeError,
|
||||
CurseForgeNotFoundError,
|
||||
CurseForgeRateLimitError,
|
||||
)
|
||||
|
||||
BASE = "https://api.curseforge.com"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
return CurseForgeClient("test-api-key", timeout=5)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# get_mod
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_mod_success(client):
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
f"{BASE}/v1/mods/123456",
|
||||
json={"data": {"id": 123456, "name": "Test Pack", "latestFiles": []}},
|
||||
status=200,
|
||||
)
|
||||
mod = client.get_mod(123456)
|
||||
assert mod["name"] == "Test Pack"
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_mod_not_found(client):
|
||||
responses_lib.add(responses_lib.GET, f"{BASE}/v1/mods/999", status=404)
|
||||
with pytest.raises(CurseForgeNotFoundError):
|
||||
client.get_mod(999)
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_mod_invalid_key_401(client):
|
||||
responses_lib.add(responses_lib.GET, f"{BASE}/v1/mods/123", status=401)
|
||||
with pytest.raises(CurseForgeAuthError, match="Invalid API key"):
|
||||
client.get_mod(123)
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_mod_forbidden_403(client):
|
||||
responses_lib.add(responses_lib.GET, f"{BASE}/v1/mods/123", status=403)
|
||||
with pytest.raises(CurseForgeAuthError, match="permission"):
|
||||
client.get_mod(123)
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_mod_rate_limit_429(client):
|
||||
responses_lib.add(responses_lib.GET, f"{BASE}/v1/mods/123", status=429)
|
||||
with pytest.raises(CurseForgeRateLimitError):
|
||||
client.get_mod(123)
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_mod_server_error(client):
|
||||
# responses library doesn't retry by default in tests; just test the exception
|
||||
responses_lib.add(responses_lib.GET, f"{BASE}/v1/mods/123", status=500)
|
||||
responses_lib.add(responses_lib.GET, f"{BASE}/v1/mods/123", status=500)
|
||||
responses_lib.add(responses_lib.GET, f"{BASE}/v1/mods/123", status=500)
|
||||
responses_lib.add(responses_lib.GET, f"{BASE}/v1/mods/123", status=500)
|
||||
with pytest.raises(CurseForgeError):
|
||||
client.get_mod(123)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# get_mod_name
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_mod_name(client):
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
f"{BASE}/v1/mods/100",
|
||||
json={"data": {"id": 100, "name": "All The Mods 9", "latestFiles": []}},
|
||||
status=200,
|
||||
)
|
||||
assert client.get_mod_name(100) == "All The Mods 9"
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_mod_name_fallback(client):
|
||||
"""If 'name' key is missing, return generic fallback."""
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
f"{BASE}/v1/mods/100",
|
||||
json={"data": {"id": 100, "latestFiles": []}},
|
||||
status=200,
|
||||
)
|
||||
assert client.get_mod_name(100) == "Modpack 100"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# get_latest_file
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_latest_file_uses_latest_files(client):
|
||||
"""get_latest_file should prefer the latestFiles field (fast path)."""
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
f"{BASE}/v1/mods/200",
|
||||
json={
|
||||
"data": {
|
||||
"id": 200,
|
||||
"name": "Pack",
|
||||
"latestFiles": [
|
||||
{
|
||||
"id": 9001,
|
||||
"displayName": "Pack 2.0.0",
|
||||
"fileName": "pack-2.0.0.zip",
|
||||
"fileDate": "2026-01-15T00:00:00Z",
|
||||
},
|
||||
{
|
||||
"id": 9000,
|
||||
"displayName": "Pack 1.0.0",
|
||||
"fileName": "pack-1.0.0.zip",
|
||||
"fileDate": "2025-12-01T00:00:00Z",
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
status=200,
|
||||
)
|
||||
file_obj = client.get_latest_file(200)
|
||||
assert file_obj["displayName"] == "Pack 2.0.0"
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_latest_file_fallback_files_endpoint(client):
|
||||
"""Falls back to the /files endpoint when latestFiles is empty."""
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
f"{BASE}/v1/mods/300",
|
||||
json={"data": {"id": 300, "name": "Pack", "latestFiles": []}},
|
||||
status=200,
|
||||
)
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
f"{BASE}/v1/mods/300/files",
|
||||
json={
|
||||
"data": [
|
||||
{"id": 8000, "displayName": "Pack 3.0.0", "fileName": "pack-3.0.0.zip"}
|
||||
]
|
||||
},
|
||||
status=200,
|
||||
)
|
||||
file_obj = client.get_latest_file(300)
|
||||
assert file_obj["displayName"] == "Pack 3.0.0"
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_get_latest_file_no_files_returns_none(client):
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
f"{BASE}/v1/mods/400",
|
||||
json={"data": {"id": 400, "name": "Pack", "latestFiles": []}},
|
||||
status=200,
|
||||
)
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
f"{BASE}/v1/mods/400/files",
|
||||
json={"data": []},
|
||||
status=200,
|
||||
)
|
||||
assert client.get_latest_file(400) is None
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# extract_version
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_extract_version_prefers_display_name(client):
|
||||
file_obj = {"displayName": "ATM9 1.2.3", "fileName": "atm9-1.2.3.zip", "id": 1}
|
||||
assert client.extract_version(file_obj) == "ATM9 1.2.3"
|
||||
|
||||
|
||||
def test_extract_version_falls_back_to_filename(client):
|
||||
file_obj = {"displayName": "", "fileName": "pack-1.0.0.zip", "id": 1}
|
||||
assert client.extract_version(file_obj) == "pack-1.0.0.zip"
|
||||
|
||||
|
||||
def test_extract_version_last_resort_file_id(client):
|
||||
file_obj = {"displayName": "", "fileName": "", "id": 9999}
|
||||
assert client.extract_version(file_obj) == "File ID 9999"
|
||||
|
||||
|
||||
def test_extract_version_strips_whitespace(client):
|
||||
file_obj = {"displayName": " Pack 1.0 ", "fileName": "pack.zip", "id": 1}
|
||||
assert client.extract_version(file_obj) == "Pack 1.0"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# validate_api_key
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_validate_api_key_success(client):
|
||||
responses_lib.add(
|
||||
responses_lib.GET,
|
||||
f"{BASE}/v1/games/432",
|
||||
json={"data": {"id": 432, "name": "Minecraft"}},
|
||||
status=200,
|
||||
)
|
||||
assert client.validate_api_key() is True
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_validate_api_key_failure(client):
|
||||
responses_lib.add(responses_lib.GET, f"{BASE}/v1/games/432", status=401)
|
||||
assert client.validate_api_key() is False
|
||||
174
services/modpack-version-checker/tests/test_database.py
Normal file
174
services/modpack-version-checker/tests/test_database.py
Normal file
@@ -0,0 +1,174 @@
|
||||
"""Tests for database.py."""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from modpack_checker.database import Database
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# add_modpack
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_add_modpack_returns_correct_fields(db):
|
||||
mp = db.add_modpack(12345, "Test Pack")
|
||||
assert mp.curseforge_id == 12345
|
||||
assert mp.name == "Test Pack"
|
||||
assert mp.current_version is None
|
||||
assert mp.last_checked is None
|
||||
assert mp.notification_enabled is True
|
||||
|
||||
|
||||
def test_add_modpack_duplicate_raises(db):
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
with pytest.raises(ValueError, match="already being tracked"):
|
||||
db.add_modpack(12345, "Test Pack Again")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# remove_modpack
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_remove_modpack_returns_true(db):
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
assert db.remove_modpack(12345) is True
|
||||
|
||||
|
||||
def test_remove_modpack_missing_returns_false(db):
|
||||
assert db.remove_modpack(99999) is False
|
||||
|
||||
|
||||
def test_remove_modpack_deletes_record(db):
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
db.remove_modpack(12345)
|
||||
assert db.get_modpack(12345) is None
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# get_modpack
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_get_modpack_found(db):
|
||||
db.add_modpack(111, "Pack A")
|
||||
mp = db.get_modpack(111)
|
||||
assert mp is not None
|
||||
assert mp.name == "Pack A"
|
||||
|
||||
|
||||
def test_get_modpack_not_found(db):
|
||||
assert db.get_modpack(999) is None
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# get_all_modpacks
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_get_all_modpacks_empty(db):
|
||||
assert db.get_all_modpacks() == []
|
||||
|
||||
|
||||
def test_get_all_modpacks_multiple(db):
|
||||
db.add_modpack(1, "Pack A")
|
||||
db.add_modpack(2, "Pack B")
|
||||
db.add_modpack(3, "Pack C")
|
||||
modpacks = db.get_all_modpacks()
|
||||
assert len(modpacks) == 3
|
||||
ids = {mp.curseforge_id for mp in modpacks}
|
||||
assert ids == {1, 2, 3}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# update_version
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_update_version_sets_fields(db):
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
db.update_version(12345, "1.2.3", notification_sent=True)
|
||||
mp = db.get_modpack(12345)
|
||||
assert mp.current_version == "1.2.3"
|
||||
assert mp.last_checked is not None
|
||||
|
||||
|
||||
def test_update_version_nonexistent_raises(db):
|
||||
with pytest.raises(ValueError, match="not found"):
|
||||
db.update_version(99999, "1.0.0")
|
||||
|
||||
|
||||
def test_update_version_multiple_times(db):
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
db.update_version(12345, "1.0.0")
|
||||
db.update_version(12345, "1.1.0")
|
||||
mp = db.get_modpack(12345)
|
||||
assert mp.current_version == "1.1.0"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# get_check_history
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_check_history_newest_first(db):
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
db.update_version(12345, "1.0.0", notification_sent=False)
|
||||
db.update_version(12345, "1.1.0", notification_sent=True)
|
||||
history = db.get_check_history(12345, limit=10)
|
||||
assert len(history) == 2
|
||||
assert history[0].version_found == "1.1.0"
|
||||
assert history[0].notification_sent is True
|
||||
assert history[1].version_found == "1.0.0"
|
||||
|
||||
|
||||
def test_check_history_limit(db):
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
for i in range(5):
|
||||
db.update_version(12345, f"1.{i}.0")
|
||||
history = db.get_check_history(12345, limit=3)
|
||||
assert len(history) == 3
|
||||
|
||||
|
||||
def test_check_history_missing_modpack(db):
|
||||
assert db.get_check_history(99999) == []
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# toggle_notifications
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_toggle_notifications_disable(db):
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
result = db.toggle_notifications(12345, False)
|
||||
assert result is True
|
||||
mp = db.get_modpack(12345)
|
||||
assert mp.notification_enabled is False
|
||||
|
||||
|
||||
def test_toggle_notifications_re_enable(db):
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
db.toggle_notifications(12345, False)
|
||||
db.toggle_notifications(12345, True)
|
||||
assert db.get_modpack(12345).notification_enabled is True
|
||||
|
||||
|
||||
def test_toggle_notifications_missing(db):
|
||||
assert db.toggle_notifications(99999, True) is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# cascade delete
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_remove_modpack_also_removes_history(db):
|
||||
db.add_modpack(12345, "Test Pack")
|
||||
db.update_version(12345, "1.0.0")
|
||||
db.update_version(12345, "1.1.0")
|
||||
db.remove_modpack(12345)
|
||||
# History should be gone (cascade delete)
|
||||
assert db.get_check_history(12345) == []
|
||||
83
services/modpack-version-checker/tests/test_notifier.py
Normal file
83
services/modpack-version-checker/tests/test_notifier.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""Tests for notifier.py."""
|
||||
|
||||
import pytest
|
||||
import responses as responses_lib
|
||||
|
||||
from modpack_checker.notifier import DiscordNotifier, NotificationError
|
||||
|
||||
WEBHOOK_URL = "https://discord.com/api/webhooks/123456/abcdef"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def notifier():
|
||||
return DiscordNotifier(WEBHOOK_URL, timeout=5)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# send_update
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_send_update_success(notifier):
|
||||
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=204)
|
||||
# Should not raise
|
||||
notifier.send_update("Test Pack", 12345, "1.0.0", "1.1.0")
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_send_update_initial_version(notifier):
|
||||
"""old_version=None should be handled gracefully."""
|
||||
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=204)
|
||||
notifier.send_update("Test Pack", 12345, None, "1.0.0")
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_send_update_bad_response_raises(notifier):
|
||||
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=400, body="Bad Request")
|
||||
with pytest.raises(NotificationError, match="HTTP 400"):
|
||||
notifier.send_update("Test Pack", 12345, "1.0.0", "1.1.0")
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_send_update_unauthorized_raises(notifier):
|
||||
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=401)
|
||||
with pytest.raises(NotificationError):
|
||||
notifier.send_update("Test Pack", 12345, "1.0.0", "1.1.0")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# test
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_test_webhook_success(notifier):
|
||||
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=204)
|
||||
notifier.test() # Should not raise
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_test_webhook_failure_raises(notifier):
|
||||
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=404)
|
||||
with pytest.raises(NotificationError):
|
||||
notifier.test()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# embed structure
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@responses_lib.activate
|
||||
def test_send_update_embed_contains_modpack_name(notifier):
|
||||
"""Verify the correct embed payload is sent to Discord."""
|
||||
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=204)
|
||||
notifier.send_update("All The Mods 9", 238222, "0.2.0", "0.3.0")
|
||||
|
||||
assert len(responses_lib.calls) == 1
|
||||
raw_body = responses_lib.calls[0].request.body
|
||||
payload = raw_body.decode("utf-8") if isinstance(raw_body, bytes) else raw_body
|
||||
assert "All The Mods 9" in payload
|
||||
assert "238222" in payload
|
||||
assert "0.3.0" in payload
|
||||
Reference in New Issue
Block a user