This commit is contained in:
2026-08-31 15:33:39 +08:00
parent 1b6f5a9f03
commit 027d7e06eb
21 changed files with 208 additions and 84 deletions

View File

@@ -0,0 +1,22 @@
from __future__ import annotations
import unittest
from unittest.mock import patch
from libs.market import market_allow_open, refresh_market
class MarketCacheTests(unittest.TestCase):
def test_refresh_updates_open_cache(self):
with patch("libs.market.get_json", return_value={"data": {"action": "UP"}}):
self.assertEqual(refresh_market("http://example"), "UP")
self.assertTrue(market_allow_open())
def test_refresh_failure_blocks_open(self):
with patch("libs.market.get_json", side_effect=OSError("offline")):
self.assertEqual(refresh_market("http://example"), "UNKNOWN")
self.assertFalse(market_allow_open())
if __name__ == "__main__":
unittest.main()