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()