64 lines
2.5 KiB
Python
64 lines
2.5 KiB
Python
import tempfile
|
|
import unittest
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
|
from rotation_worker import (
|
|
ACTIVE,
|
|
HIDDEN_ROTATION,
|
|
VIOLATION_HIDDEN,
|
|
RotationConfig,
|
|
account_publish_limit,
|
|
apply_exhibition_cap,
|
|
hide_violation,
|
|
load_config,
|
|
restore_permanent,
|
|
)
|
|
|
|
|
|
class RotationWorkerTest(unittest.TestCase):
|
|
def test_account_publish_limit_changes_after_first_day(self):
|
|
now = 2_000_000_000
|
|
self.assertEqual(account_publish_limit({"id": "a", "createdAt": now}, now), 5)
|
|
self.assertEqual(account_publish_limit({"id": "a", "createdAt": now - 25 * 60 * 60 * 1000}, now), 10)
|
|
|
|
def test_exhibition_cap_hides_old_excess_objects(self):
|
|
state = {
|
|
"assets": [],
|
|
"placed": [
|
|
{"id": "old", "assetId": "a", "x": 1, "y": 1, "publishedAt": 10},
|
|
{"id": "new", "assetId": "b", "x": 2, "y": 2, "publishedAt": 20},
|
|
],
|
|
"dynamicSummons": [],
|
|
"objectVotes": {},
|
|
}
|
|
summary = apply_exhibition_cap(state, RotationConfig(display_limit=1, newest_slots=1, revival_slots=0), seed=1, now=30)
|
|
self.assertEqual(summary["active"], 1)
|
|
self.assertEqual(state["placed"][1]["status"], ACTIVE)
|
|
self.assertEqual(state["placed"][0]["status"], HIDDEN_ROTATION)
|
|
|
|
def test_display_limit_caps_slot_total(self):
|
|
config = RotationConfig(display_limit=3, newest_slots=5, revival_slots=5)
|
|
self.assertEqual(config.newest_slots + config.revival_slots, 3)
|
|
|
|
def test_violation_hide_and_restore(self):
|
|
state = {"placed": [{"id": "obj", "assetId": "a"}], "dynamicSummons": []}
|
|
self.assertEqual(hide_violation(state, ["obj"], now=1), ["obj"])
|
|
self.assertEqual(state["placed"][0]["status"], VIOLATION_HIDDEN)
|
|
self.assertEqual(restore_permanent(state, ["obj"], now=2), ["obj"])
|
|
self.assertEqual(state["placed"][0]["status"], HIDDEN_ROTATION)
|
|
|
|
def test_load_config_from_json_with_override(self):
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
path = Path(temp) / "policy.json"
|
|
path.write_text('{"display_limit": 40, "newest_slots": 30}', encoding="utf-8")
|
|
config = load_config(path, {"revival_slots": 7})
|
|
self.assertEqual(config.display_limit, 40)
|
|
self.assertEqual(config.newest_slots, 30)
|
|
self.assertEqual(config.revival_slots, 7)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|