# Coverage for tests/e2e/test_admin.py : 99%

## 68 statements 67 run 1 missing 0 excluded 0 partial

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 -*-

2 from __future__ import annotations

3

4# -- stdlib --

5# -- third party --

6 import gevent

7

8# -- own --

9 from .mock import Environ, EventTap

10 from game.base import EventHandler

11

12

13# -- code --

14 class GameEnded(Exception):

15 pass

16

17

18 def wait():

19 gevent.idle(-100)

20 gevent.sleep(0.01)

21 gevent.idle(-100)

22

23

24 class TestAdmin(object):

25 def testKick(self):

26 env = Environ()

27 t = EventTap()

28

29 _ = env.server_core()

30 proton = env.client_core()

31 naughty = env.client_core()

32 proton.auth.login("Proton")

33 naughty.auth.login("Naughty")

34

35 wait()

36

37 assert proton.auth.uid == 2

38 assert naughty.auth.uid

39

40 t.tap(proton, naughty)

41

42 naughty.admin.kick(proton.auth.uid)

43 wait()

44

45 assert proton.events.server_dropped not in t

46 assert naughty.events.server_dropped not in t

47

48 proton.admin.kick(naughty.auth.uid)

49 wait()

50

51 assert proton.events.server_dropped not in t

52 assert naughty.events.server_dropped in t

53

54 def testKillGame(self):

55 env = Environ()

56 t = EventTap()

57

58 s = env.server_core()

59 proton = env.client_core()

60 naughty = env.client_core()

61 t.tap(proton, naughty)

62

63 proton.auth.login("Proton")

64 naughty.auth.login("Naughty")

65

66 wait()

67

68 assert proton.auth.uid == 2

69 assert naughty.auth.uid

70

71 naughty.admin.kick(proton.auth.uid)

72

73 wait()

74

75 class Halt(EventHandler):

76 def handle(self, evt: str, arg):

77 gevent.sleep(10000)

78

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)

89

90 def testSystemCommands(self):

91 env = Environ()

92

93 _ = env.server_core()

94 proton = env.client_core()

95 proton.auth.login("Proton")

96

97 wait()

98

99 proton.admin.clearzombies()

100 proton.admin.stacktrace()

101 proton.admin.migrate()

102

103 wait()