test_get_api_v1_charts_player_game.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 charts as views_mod
  7. class Test_GetAPIv1ChartsPlayerGame(BaseQ3StatsWebAppTestCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(Test_GetAPIv1ChartsPlayerGame, cls).setUpClass()
  11. with utils.db_session(cls._config) as session:
  12. game_dt = datetime.datetime(2017, 2, 15, 20, 21, 0)
  13. game = Game(
  14. uuid='game',
  15. map='Q3DM7',
  16. date=game_dt.date(),
  17. time=game_dt.time(),
  18. fraglimit=20,
  19. attrs={}
  20. )
  21. game.scores.extend([
  22. Score(
  23. player='tomekwojcik',
  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. items={},
  35. powerups={}
  36. ),
  37. Score(
  38. player='Player 1',
  39. score=10,
  40. kills=11,
  41. deaths=20,
  42. suicides=1,
  43. net=10,
  44. damage_taken=123,
  45. damage_given=456,
  46. total_health=123,
  47. total_armor=456,
  48. weapons={},
  49. items={},
  50. powerups={}
  51. ),
  52. ])
  53. session.add(game)
  54. session.commit()
  55. def test_not_found_player(self):
  56. with self.app.test_request_context():
  57. rsp = self.client.get(
  58. '/api/v1/charts/player/%s/game/%s' % ('spam', 'game')
  59. )
  60. assert rsp.status_code == 404
  61. def test_not_found_game(self):
  62. with self.app.test_request_context():
  63. rsp = self.client.get(
  64. '/api/v1/charts/player/%s/game/%s' % ('tomekwojcik', 'spam')
  65. )
  66. assert rsp.status_code == 404
  67. def test_ok(self):
  68. with self.app.test_request_context():
  69. rsp = self.client.get(
  70. '/api/v1/charts/player/%s/game/%s' % ('tomekwojcik', 'game')
  71. )
  72. assert rsp.status_code == 200
  73. assert rsp.json['score'] == [
  74. ['Frags', 21],
  75. ['Deaths', 10],
  76. ['Suicides', 1]
  77. ]
  78. assert rsp.json['damage'] == [
  79. ['Taken', 123],
  80. ['Given', 456]
  81. ]
  82. assert rsp.json['totals'] == [
  83. ['Armor', 456],
  84. ['Health', 123]
  85. ]