diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-16 17:17:13 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-16 17:17:13 +0100 |
| commit | 766251ed6dc1858b544aa1c50de72b93d10b84d4 (patch) | |
| tree | 3cdd0c2a14a6f8070fd96263ed2f424825c21ed7 /tests | |
| parent | 3f56d1bdacfc45dba573e73dc45ebcdc8f72e8f7 (diff) | |
| download | deck-it-766251ed6dc1858b544aa1c50de72b93d10b84d4.tar.gz deck-it-766251ed6dc1858b544aa1c50de72b93d10b84d4.zip | |
feat(xbox): Xbox Live reads, presentation flag and console commands
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_xbox.py | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/test_xbox.py b/tests/test_xbox.py index 010034d..2eeea8d 100644 --- a/tests/test_xbox.py +++ b/tests/test_xbox.py @@ -218,5 +218,109 @@ class Login(Base): self.assertIsNone(x.state()["login"]) +class Tick(Base): + def test_a_tick_reads_everything_and_marks_the_game(self): + x = self.xbox() + x.tick() + st = x.state() + self.assertEqual(st["profile"]["gamertag"], "Player") + self.assertEqual(st["consoles"][0]["id"], "CON1") + self.assertEqual(st["titles"][0]["minutes"], 185) + self.assertEqual(st["achievements"][0]["score"], 15) + self.assertEqual(st["friends"][0]["gamertag"], "amy") + self.assertEqual(st["playing"]["name"], "Some Game") + self.assertIsInstance(st["session"], int) + self.assertEqual(self.status.read_text(), "1") + + def test_slow_reads_wait_unless_the_title_changes(self): + x = self.xbox() + x.tick(), x.tick() + self.assertEqual(len(self.fake.urls("profile.xboxlive.com")), 1) + self.fake.answers["userpresence"] = {"state": "Online", "devices": [{"titles": [ + {"id": "99", "name": "Video App", "placement": "Full"}]}]} + x.tick() + self.assertEqual(len(self.fake.urls("profile.xboxlive.com")), 2) + + def test_an_app_is_not_playing_and_ends_the_session(self): + x = self.xbox() + x.tick() + self.fake.answers["userpresence"] = {"state": "Online", "devices": [{"titles": [ + {"id": "99", "name": "Video App", "placement": "Full"}]}]} + x.tick() + self.assertIsNone(x.state()["playing"]) + self.assertIsNone(x.state()["session"]) + self.assertEqual(self.status.read_text(), "0") + + def test_an_unknown_title_type_is_looked_up_once(self): + self.fake.answers["userpresence"] = {"state": "Online", "devices": [{"titles": [ + {"id": "555", "name": "New Game", "placement": "Full"}]}]} + x = self.xbox() + x.tick(), x.tick() + self.assertEqual(len(self.fake.urls("titleid(555)")), 1) + self.assertEqual(x.state()["playing"]["id"], "555") + + def test_network_down_keeps_the_data_as_stale(self): + x = self.xbox() + x.tick() + self.fake.fail["userpresence"] = OSError("no route") + x.tick() + st = x.state() + self.assertTrue(st["stale"]) + self.assertEqual(st["profile"]["gamertag"], "Player") + + def test_one_failing_part_keeps_the_rest(self): + x = self.xbox() + self.fake.fail["peoplehub"] = xb.HttpError(403, {}) + x.tick() + st = x.state() + self.assertFalse(st["stale"]) + self.assertEqual(st["friends"], []) + self.assertEqual(st["profile"]["gamertag"], "Player") + + def test_signed_out_clears_playing(self): + x = self.xbox() + x.tick() + self.fake.fail["/oauth2/v2.0/token"] = xb.HttpError(400, {"error": "invalid_grant"}) + x.auth = None + x.tick() + self.assertFalse(x.state()["signed_in"]) + self.assertEqual(self.status.read_text(), "0") + + def test_stop_writes_zero(self): + x = self.xbox() + x.tick() + x.stop() + self.assertEqual(self.status.read_text(), "0") + + +class Commands(Base): + def test_a_command_goes_to_xccs(self): + x = self.xbox() + x.tick() + x.command("vol_up", {"console": "CON1"}) + url, data, headers = self.fake.urls("/commands")[0] + self.assertEqual((data["type"], data["command"], data["linkedXboxId"]), ("Audio", "Volume", "CON1")) + self.assertEqual(data["parameters"], [{"direction": "Up", "amount": "1"}]) + self.assertEqual(headers["skillplatform"], "RemoteManagement") + + def test_unknown_console_is_refused(self): + x = self.xbox() + x.tick() + with self.assertRaises(xb.ModuleError): + x.command("wake", {"console": "OTHER"}) + + def test_an_xccs_error_becomes_the_message(self): + self.fake.answers["/commands"] = {"status": {"errorCode": "DeviceUnavailable", "errorMessage": "Console is off"}} + x = self.xbox() + x.tick() + with self.assertRaisesRegex(xb.ModuleError, "Console is off"): + x.command("off", {"console": "CON1"}) + + def test_make_lists_the_actions(self): + m = xb.make({"xbox": {"client_id": ""}}) + self.assertEqual(set(m.actions), {"login", *xb.COMMANDS}) + self.assertEqual(m.state(), {"offline": True, "unconfigured": True}) + + if __name__ == "__main__": unittest.main() |
