Unify strategy controls and refresh logged-in accounts automatically
This commit is contained in:
@@ -147,7 +147,7 @@ class AccountGuiTests(unittest.TestCase):
|
||||
saved = json.loads((selected.state / "settings.json").read_text(encoding="utf-8"))
|
||||
self.assertEqual(saved["policy"]["keep_money"], expected)
|
||||
self.assertEqual(selected.engine.policy.keep_money, expected)
|
||||
self.assertFalse(selected.execute.isChecked())
|
||||
self.assertFalse(selected.strategy_toggle.isChecked())
|
||||
finally:
|
||||
hub.close()
|
||||
|
||||
@@ -160,7 +160,7 @@ class AccountGuiTests(unittest.TestCase):
|
||||
try:
|
||||
self.wait(windows)
|
||||
self.assertEqual([action.text().split("(")[0] for action in hub.menuBar().actions()],
|
||||
["账号", "监控", "策略配置", "帮助"])
|
||||
["账号", "策略", "策略配置", "帮助"])
|
||||
for window in windows:
|
||||
self.assertIsNone(window.findChild(W.QMenuBar))
|
||||
labels = {button.text() for button in hub.findChildren(W.QPushButton)}
|
||||
@@ -250,7 +250,7 @@ class AccountGuiTests(unittest.TestCase):
|
||||
window.resume_session()
|
||||
self.wait([window])
|
||||
self.assertEqual(window.session_store.load(key).reqid, 1)
|
||||
self.assertFalse(window.execute.isChecked())
|
||||
self.assertFalse(window.strategy_toggle.isChecked())
|
||||
self.assertTrue(window.engine.demo)
|
||||
finally:
|
||||
window.close()
|
||||
@@ -277,10 +277,10 @@ class AccountGuiTests(unittest.TestCase):
|
||||
self.assertFalse(first.monsters.group_items)
|
||||
self.assertTrue(all(item.parent() is None for item in first.monsters.monster_items.values()))
|
||||
self.assertEqual(first.saved_sessions.count(), 1)
|
||||
first.start_monitor.setChecked(True)
|
||||
first.monitoring = True
|
||||
hub.tabs.setCurrentWidget(second)
|
||||
self.assertTrue(first.monitoring)
|
||||
hub.monitor_all()
|
||||
self.assertTrue(all(window.monitoring for window in windows))
|
||||
for window in windows:
|
||||
window.engine.last_heartbeat = time.monotonic()
|
||||
window.next_poll = 0
|
||||
@@ -291,7 +291,7 @@ class AccountGuiTests(unittest.TestCase):
|
||||
self.assertEqual(second.engine.client.session.token, "test-token-account-b")
|
||||
self.assertEqual(first.engine.snapshot.raw["master"]["id"], 101)
|
||||
self.assertEqual(second.engine.snapshot.raw["master"]["id"], 202)
|
||||
first.execute.setChecked(True)
|
||||
first.set_strategy_checked(True)
|
||||
before = len(calls)
|
||||
hub.tabs.setCurrentWidget(first)
|
||||
first.tabs.setCurrentWidget(first.egg_page)
|
||||
@@ -324,10 +324,90 @@ class AccountGuiTests(unittest.TestCase):
|
||||
self.wait(restarted)
|
||||
self.assertEqual({window.engine.snapshot.raw["master"]["id"] for window in restarted}, {101, 202},
|
||||
"\n".join(window.log.toPlainText() for window in restarted))
|
||||
self.assertTrue(all(not window.engine.demo and not window.execute.isChecked() and not window.monitoring for window in restarted))
|
||||
self.assertTrue(all(not window.engine.demo and not window.strategy_toggle.isChecked() and window.monitoring for window in restarted))
|
||||
finally:
|
||||
restored.close()
|
||||
|
||||
def test_login_refreshes_automatically_and_strategy_menu_only_controls_execution(self):
|
||||
with workspace_temp() as folder:
|
||||
hub = AccountsWindow(folder)
|
||||
hub.add_profile()
|
||||
windows = list(hub.windows.values())
|
||||
calls = []
|
||||
for window in windows:
|
||||
window.timer.stop()
|
||||
try:
|
||||
self.wait(windows)
|
||||
for number, window in enumerate(windows, 1):
|
||||
self.connect(window, f"account-{number}", number, number, calls)
|
||||
self.assertTrue(window.monitoring)
|
||||
self.assertFalse(window.strategy_toggle.isChecked())
|
||||
window.engine.last_heartbeat = time.monotonic()
|
||||
window.schedule()
|
||||
self.wait(windows)
|
||||
self.assertTrue(calls)
|
||||
self.assertTrue(all(url.endswith("masterService/masterQueryDetail") for _, url, _ in calls))
|
||||
for window in windows:
|
||||
window.ranch_enabled.setChecked(False)
|
||||
window.daily_enabled.setChecked(True)
|
||||
# Exercise real Qt menu actions with synthetic worker results.
|
||||
observed = []
|
||||
from contextlib import ExitStack
|
||||
with ExitStack() as stack:
|
||||
for window in windows:
|
||||
def poll(current=window, **kwargs):
|
||||
observed.append((current, current.engine.auto))
|
||||
return current.engine.snapshot, [], "synthetic refresh"
|
||||
stack.enter_context(patch.object(window.engine, "poll", side_effect=poll))
|
||||
menu = next(action.menu() for action in hub.menuBar().actions() if action.text() == "策略(&R)")
|
||||
menu.actions()[0].trigger()
|
||||
self.wait(windows)
|
||||
self.assertEqual(len(observed), 2)
|
||||
self.assertTrue(all(enabled for _, enabled in observed))
|
||||
self.assertTrue(all(w.strategy_toggle.text() == "关闭策略" for w in windows))
|
||||
# A manual refresh never executes, even with strategies on.
|
||||
windows[0].refresh()
|
||||
self.wait(windows)
|
||||
self.assertFalse(observed[-1][1])
|
||||
menu.actions()[1].trigger()
|
||||
self.assertTrue(all(w.monitoring and not w.strategy_toggle.isChecked() for w in windows))
|
||||
observed.clear()
|
||||
for window in windows:
|
||||
window.next_poll = 0
|
||||
window.schedule()
|
||||
self.wait(windows)
|
||||
self.assertEqual(len(observed), 2)
|
||||
self.assertFalse(any(enabled for _, enabled in observed))
|
||||
windows[0].demo()
|
||||
self.wait(windows)
|
||||
self.assertFalse(windows[0].monitoring)
|
||||
self.assertTrue(windows[1].monitoring)
|
||||
finally:
|
||||
hub.close()
|
||||
|
||||
def test_incomplete_policy_keeps_logged_in_account_refreshing_without_actions(self):
|
||||
with workspace_temp() as folder:
|
||||
window = gui.Window(folder)
|
||||
window.timer.stop()
|
||||
calls = []
|
||||
try:
|
||||
self.wait([window])
|
||||
self.connect(window, "account-a", 1, 101, calls)
|
||||
window.reserved_types.setText("incomplete-input")
|
||||
window.strategy_toggle.click()
|
||||
self.assertFalse(window.strategy_toggle.isChecked())
|
||||
self.assertTrue(window.monitoring)
|
||||
window.engine.last_heartbeat = time.monotonic()
|
||||
window.next_poll = 0
|
||||
window.schedule()
|
||||
self.wait([window])
|
||||
self.assertTrue(window.monitoring)
|
||||
self.assertFalse(window.engine.auto)
|
||||
self.assertTrue(calls)
|
||||
self.assertTrue(all(url.endswith("masterService/masterQueryDetail") for _, url, _ in calls))
|
||||
finally:
|
||||
window.close()
|
||||
|
||||
def test_role_switch_restores_own_strategy_and_heartbeat_uses_normal_api(self):
|
||||
with workspace_temp() as folder:
|
||||
window = gui.Window(folder)
|
||||
@@ -346,6 +426,7 @@ class AccountGuiTests(unittest.TestCase):
|
||||
self.assertEqual(window.strategy.currentData(), "gold")
|
||||
self.assertEqual(window.saved_sessions.count(), 2)
|
||||
window.engine.last_heartbeat = 0
|
||||
window.next_poll = float("inf")
|
||||
window.schedule()
|
||||
self.wait([window])
|
||||
self.assertTrue(calls[-1][1].endswith("heartBeatService/keepAlive"))
|
||||
|
||||
Reference in New Issue
Block a user