Hide keyboard shortcuts

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 

3 

4# -- stdlib -- 

5import logging 

6 

7# -- third party -- 

8import gevent 

9 

10# -- own -- 

11from .mock import Environ, EventTap 

12 

13 

14# -- code -- 

15class GameEnded(Exception): 

16 pass 

17 

18 

19log = logging.getLogger('UnitTest') 

20 

21 

22def wait(): 

23 gevent.idle(-100) 

24 gevent.sleep(0.01) 

25 gevent.idle(-100) 

26 

27 

28class TestInvite(object): 

29 def testInvite(self): 

30 env = Environ() 

31 t = EventTap() 

32 

33 _ = env.server_core() 

34 a, b, c, d, e = [env.client_core() for _ in range(5)] 

35 t.tap(a, b, c, d, e) 

36 

37 a.auth.login("Alice") 

38 b.auth.login("Bob") 

39 c.auth.login("Cirno") 

40 d.auth.login("Daiyousei") 

41 e.auth.login("Eirin") 

42 wait() 

43 

44 assert a.auth.uid > 0 

45 assert b.auth.uid > 0 

46 assert c.auth.uid > 0 

47 assert d.auth.uid > 0 

48 assert e.auth.uid > 0 

49 

50 # Onlookers should not be able to join invite only rooms 

51 a.room.create("TestInvite", "THBattleDummy4", {'invite': True}); wait() 

52 gid = a.game.gid_of(t.take(a.events.game_joined)) 

53 b.room.join(gid); wait() 

54 assert t.take(b.events.server_error) == 'not_invited' 

55 assert b.events.game_joined not in t 

56 

57 # Happy path 

58 [a.room.invite(i.auth.uid) for i in (b, c, d)]; wait() 

59 [i.room.join(gid) for i in (b, c, d)]; wait() 

60 assert b.events.game_joined in t 

61 assert c.events.game_joined in t 

62 assert d.events.game_joined in t 

63 

64 # Kick happy path 

65 t.clear() 

66 a.room.kick(d.auth.uid); wait() 

67 assert d.events.game_left not in t 

68 b.room.kick(d.auth.uid); wait() 

69 assert d.events.game_left in t 

70 

71 # Banned player can't join again 

72 t.clear() 

73 d.room.join(gid); wait() 

74 assert t.take(d.events.server_error) == 'banned' 

75 

76 # Ban votes fades away with player left game 

77 t.clear() 

78 b.room.leave(); wait() 

79 d.room.join(gid); wait() 

80 assert t.take(d.events.server_error) == 'not_invited' 

81 c.room.invite(d.auth.uid); wait() 

82 d.room.join(gid); wait() 

83 assert d.events.game_joined in t