test_teams.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # coding: utf-8
  2. import pytest
  3. from synergine2.config import Config
  4. from opencombat.exception import NotFoundException
  5. from opencombat.strategy.team.model import TeamModel
  6. from opencombat.strategy.team.stash import TeamStash
  7. from opencombat.strategy.unit.model import UnitModel
  8. from opencombat.strategy.unit.stash import UnitStash
  9. @pytest.fixture
  10. def unit_stash(
  11. config: Config,
  12. ) -> UnitStash:
  13. return UnitStash(
  14. config,
  15. 'tests/fixtures/units.xml',
  16. )
  17. def test_units_stash__ok__instantiate(
  18. config: Config,
  19. unit_stash: UnitStash,
  20. ):
  21. TeamStash(
  22. config,
  23. 'opencombat/strategy/teams.xml',
  24. unit_stash=unit_stash,
  25. )
  26. def test_team_stash__ok__get_teams(
  27. config: Config,
  28. unit_stash: UnitStash,
  29. ):
  30. stash = TeamStash(
  31. config,
  32. 'tests/fixtures/teams.xml',
  33. unit_stash=unit_stash,
  34. )
  35. assert stash.teams
  36. assert 2 == len(stash.teams)
  37. assert isinstance(stash.teams[0], TeamModel)
  38. assert isinstance(stash.teams[1], TeamModel)
  39. assert 'std_team' == stash.teams[0].id
  40. assert 'Standard team' == stash.teams[0].name
  41. assert 'URSS' == stash.teams[0].country
  42. assert stash.teams[0].units
  43. assert 4 == len(stash.teams[0].units)
  44. assert isinstance(stash.teams[0].units[0], UnitModel)
  45. assert 'std_soldier' == stash.teams[0].units[0].id
  46. assert 'std_soldier' == stash.teams[0].units[1].id
  47. assert 'std_soldier' == stash.teams[0].units[2].id
  48. assert 'std_soldier' == stash.teams[0].units[3].id
  49. assert 'std_team' == stash.teams[1].id
  50. assert 'Standard team' == stash.teams[1].name
  51. assert 'DE' == stash.teams[1].country
  52. assert stash.teams[0].units
  53. assert 4 == len(stash.teams[1].units)
  54. assert isinstance(stash.teams[1].units[0], UnitModel)
  55. assert 'std_soldier' == stash.teams[1].units[0].id
  56. assert 'std_soldier' == stash.teams[1].units[1].id
  57. assert 'std_soldier' == stash.teams[1].units[2].id
  58. assert 'std_soldier' == stash.teams[1].units[3].id
  59. def test_teams_stash__ok__get_unit(
  60. config: Config,
  61. unit_stash: UnitStash,
  62. ):
  63. stash = TeamStash(
  64. config,
  65. 'tests/fixtures/teams.xml',
  66. unit_stash=unit_stash,
  67. )
  68. assert stash.get_team('std_team', 'URSS')
  69. def test_teams_stash__error__get_team_wrong_country(
  70. config: Config,
  71. unit_stash: UnitStash,
  72. ):
  73. stash = TeamStash(
  74. config,
  75. 'tests/fixtures/teams.xml',
  76. unit_stash=unit_stash,
  77. )
  78. with pytest.raises(NotFoundException):
  79. stash.get_team('std_team', 'UNKNOWN')
  80. def test_teams_stash__error__get_team_wrong_id(
  81. config: Config,
  82. unit_stash: UnitStash,
  83. ):
  84. stash = TeamStash(
  85. config,
  86. 'tests/fixtures/teams.xml',
  87. unit_stash=unit_stash,
  88. )
  89. with pytest.raises(NotFoundException):
  90. stash.get_team('unknown', 'URSS')