Coverage for tests/e2e/test_admin.py : 99%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2from __future__ import annotations
4# -- stdlib --
5# -- third party --
6import gevent
8# -- own --
9from .mock import Environ, EventTap
10from game.base import EventHandler
13# -- code --
14class GameEnded(Exception):
15 pass
18def wait():
19 gevent.idle(-100)
20 gevent.sleep(0.01)
21 gevent.idle(-100)
24class TestAdmin(object):
25 def testKick(self):
26 env = Environ()
27 t = EventTap()
29 _ = env.server_core()
30 proton = env.client_core()
31 naughty = env.client_core()
32 proton.auth.login("Proton")
33 naughty.auth.login("Naughty")
35 wait()
37 assert proton.auth.uid == 2
38 assert naughty.auth.uid
40 t.tap(proton, naughty)
42 naughty.admin.kick(proton.auth.uid)
43 wait()
45 assert proton.events.server_dropped not in t
46 assert naughty.events.server_dropped not in t
48 proton.admin.kick(naughty.auth.uid)
49 wait()
51 assert proton.events.server_dropped not in t
52 assert naughty.events.server_dropped in t
54 def testKillGame(self):
55 env = Environ()
56 t = EventTap()
58 s = env.server_core()
59 proton = env.client_core()
60 naughty = env.client_core()
61 t.tap(proton, naughty)
63 proton.auth.login("Proton")
64 naughty.auth.login("Naughty")
66 wait()
68 assert proton.auth.uid == 2
69 assert naughty.auth.uid
71 naughty.admin.kick(proton.auth.uid)
73 wait()
75 class Halt(EventHandler):
76 def handle(self, evt: str, arg):
77 gevent.sleep(10000)
79 naughty.room.create('Boom!', 'THBattleNewbie', {})
80 wait()
81 g = t[naughty.events.game_joined]
82 g.event_observer = Halt(g)
83 gid = naughty.game.gid_of(g)
84 wait()
85 assert s.room.get(gid)
86 proton.admin.kill_game(gid)
87 wait()
88 assert not s.room.get(gid)
90 def testSystemCommands(self):
91 env = Environ()
93 _ = env.server_core()
94 proton = env.client_core()
95 proton.auth.login("Proton")
97 wait()
99 proton.admin.clearzombies()
100 proton.admin.stacktrace()
101 proton.admin.migrate()
103 wait()