# Coverage for tests/e2e/test_item.py : 100%

## 46 statements 46 run 0 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

11

12# -- code --

13 class GameEnded(Exception):

14 pass

15

16

17 def wait():

18 gevent.idle(-100)

19 gevent.sleep(0.01)

20 gevent.idle(-100)

21

22

23 class TestItem(object):

24 def testEuropean(self):

25 env = Environ()

26 t = EventTap()

27

28 s = env.server_core()

29 a, b, c, d = [env.client_core() for _ in range(4)]

30 t.tap(a, b, c, d)

31

32 a.auth.login("Alice")

33 b.auth.login("Bob")

34 c.auth.login("Cirno")

35 d.auth.login("Daiyousei")

36 wait()

37

38 # Can't use non-existent item

39 a.room.create('Boom', 'THBattleDummy4', {}); wait()

40 gid = a.game.gid_of(t[a.events.game_joined])

41 b.room.join(gid)

42 c.room.join(gid)

43 d.room.join(gid)

44 a.room.use_item('whatever-blah-blah'); wait()

45 assert t.take(a.events.server_error) == 'invalid_item_sku'

46

47 # Can't use item not applicable to chosen mode

48 a.room.use_item('imperial-role:attacker'); wait()

49 assert t.take(a.events.server_error) == 'incorrect_game_mode'

50

51 # Can't use item which do not own

52 s.backend.items[a.auth.uid] = {'european': 0}

53 a.room.use_item('european'); wait()

54 assert t.take(a.events.server_error) == 'item_not_found'

55

56 # Happy path

57 s.backend.items[a.auth.uid] = {'european': 1}

58 a.room.use_item('european'); wait()

59 assert t.take(a.events.server_info) == 'use_item_success'

60

61 # 2nd use should conflict

62 s.backend.items[b.auth.uid] = {'european': 1}

63 b.room.use_item('european'); wait()

64 assert t.take(b.events.server_error) == 'european_conflict'

65

66 # Should consume item when game started

67 a.room.get_ready()

68 b.room.get_ready()

69 c.room.get_ready()

70 d.room.get_ready()

71 wait()

72 assert s.backend.items[a.auth.uid]['european'] == 0

73 assert s.backend.items[b.auth.uid]['european'] == 1