test_get_api_v1_player_game.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # -*- coding: utf -*-
  2. import datetime
  3. from q3stats.lib.scripts import utils
  4. from q3stats.models import Game, Score
  5. from q3stats.testing import BaseQ3StatsWebAppTestCase
  6. from q3stats.web_app.blueprints.api_v1.views import players as views_mod
  7. class Test_GetAPIv1Players(BaseQ3StatsWebAppTestCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(Test_GetAPIv1Players, cls).setUpClass()
  11. with utils.db_session(cls._config) as session:
  12. game1_dt = datetime.datetime(2017, 2, 21, 18, 30)
  13. game1 = Game(
  14. uuid='game1',
  15. map='Q3DM7',
  16. date=game1_dt.date(),
  17. time=game1_dt.time(),
  18. fraglimit=20,
  19. attrs={}
  20. )
  21. game1.scores.extend([
  22. Score(
  23. player='Player 1',
  24. score=20,
  25. kills=21,
  26. deaths=10,
  27. suicides=1,
  28. net=11,
  29. damage_taken=123,
  30. damage_given=456,
  31. total_health=123,
  32. total_armor=456,
  33. weapons={
  34. 'RL': {
  35. 'hits': 10,
  36. 'kills': 5,
  37. 'shots': 20
  38. }
  39. },
  40. items={
  41. 'YA': 1
  42. },
  43. powerups={
  44. 'Quad': [3, 40000]
  45. }
  46. ),
  47. Score(
  48. player='Player 2',
  49. score=10,
  50. kills=11,
  51. deaths=20,
  52. suicides=1,
  53. net=10,
  54. damage_taken=123,
  55. damage_given=456,
  56. total_health=123,
  57. total_armor=456,
  58. weapons={},
  59. items={},
  60. powerups={}
  61. ),
  62. ])
  63. session.add(game1)
  64. session.commit()
  65. def test_not_found_game(self):
  66. with self.app.test_request_context():
  67. rsp = self.client.get('/api/v1/players/Player 1/game/spam')
  68. assert rsp.status_code == 404
  69. def test_not_found_player(self):
  70. with self.app.test_request_context():
  71. rsp = self.client.get('/api/v1/players/spam/game/game1')
  72. assert rsp.status_code == 404
  73. def test_ok(self):
  74. with self.app.test_request_context():
  75. rsp = self.client.get('/api/v1/players/Player 1/game/game1')
  76. assert rsp.status_code == 200
  77. assert rsp.json['game'] == 'game1'
  78. assert rsp.json['player'] == 'Player 1'
  79. assert rsp.json['map'] == 'Q3DM7'
  80. assert rsp.json['items'] == {'YA': 1}
  81. assert rsp.json['weapons'] == {
  82. 'RL': {
  83. 'hits': 10,
  84. 'kills': 5,
  85. 'shots': 20,
  86. 'accuracy': '50.00%'
  87. }
  88. }
  89. assert rsp.json['powerups'] == {
  90. 'Quad': [3, '40.000']
  91. }