Coverage for tests/e2e/test_contest.py : 100%
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 --
5import logging
7# -- third party --
8import gevent
10# -- own --
11from .mock import Environ, EventTap
14# -- code --
15class GameEnded(Exception):
16 pass
19log = logging.getLogger('UnitTest')
22def wait():
23 gevent.idle(-100)
24 gevent.sleep(0.01)
25 gevent.idle(-100)
28class TestContest(object):
29 def testContest(self):
30 env = Environ()
31 t = EventTap()
33 s = env.server_core()
34 proton = env.client_core()
35 a, b, c, d, e = [env.client_core() for _ in range(5)]
36 t.tap(proton, a, b, c, d, e)
37 proton.auth.login("Proton")
38 a.auth.login("Alice")
39 b.auth.login("Bob")
40 c.auth.login("Cirno")
41 e.auth.login("Eirin")
42 wait()
44 assert proton.auth.uid == 2
45 assert a.auth.uid > 0
46 assert b.auth.uid > 0
47 assert c.auth.uid > 0
48 assert e.auth.uid > 0
50 # Wrong players count
51 proton.contest.setup("TestContest", "THBattle2v2", [a.auth.uid, b.auth.uid]); wait()
52 assert t.take(proton.events.server_error) == 'wrong_players_count'
53 assert a.events.game_joined not in t
54 assert b.events.game_joined not in t
56 # Happy path
57 # Alice wondering in lobby,
58 # Bob fighting with Cirno,
59 # Cirno rubberducking Bob fighting Cirno (haha),
60 # and Daiyousei not showing at the time.
61 b.room.create('Wow', 'THBattleNewbie', {}); wait()
62 s.observe.add_bigbrother(c.auth.uid)
63 b.room.get_ready()
64 c.observe.observe(b.auth.uid); wait()
65 assert b.events.game_started in t
66 assert c.events.game_started in t
67 t.clear()
68 proton.contest.setup("TestContest", "THBattleDummy4", [i.auth.uid for i in (a, b, c)] + [s.backend.uid_of('Daiyousei')]); wait()
69 assert a.events.game_joined in t
70 assert b.events.game_joined not in t
71 assert c.events.game_joined in t
72 assert d.events.game_joined not in t
73 assert e.events.game_joined not in t
75 # Daiyousei poped up, should be pulled into contest
76 d.auth.login('Daiyousei'); wait()
77 gevent.sleep(0.02)
78 assert d.events.game_joined in t
80 # Bob exits, should be pulled into contest too
81 b.room.leave(); wait()
82 gevent.sleep(0.02)
83 assert b.events.game_joined in t
85 # Onlookers should not be able to interfere
86 gid = a.game.gid_of(t[a.events.game_joined])
87 e.room.join(gid); wait()
88 assert t.take(e.events.server_error) == 'not_competitor'
90 # Start the contest
91 t.clear()
92 a.room.get_ready()
93 b.room.get_ready()
94 c.room.get_ready()
95 d.room.get_ready()
96 wait()