test_get_api_v1_dashboard.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf -*-
  2. import datetime
  3. import mock
  4. from q3stats.testing import BaseQ3StatsWebAppTestCase
  5. from q3stats.web_app.blueprints.api_v1.views import dashboard as views_mod
  6. class Test_GetAPIv1Dashboard(BaseQ3StatsWebAppTestCase):
  7. def test_ok(self):
  8. fake_days = [datetime.date(2017, 2, 16), datetime.date(2017, 2, 15)]
  9. fake_fotm = [
  10. ['tomekwojcik', 20],
  11. ['Player 1', 10]
  12. ]
  13. fake_eotm = [
  14. ['Player 1', 20],
  15. ['tomekwojcik', 10]
  16. ]
  17. def fake_get_top_players(session, agg_by='kills'):
  18. if agg_by == 'suicides':
  19. return fake_eotm
  20. return fake_fotm
  21. with mock.patch.object(views_mod.queries, 'get_game_dates',
  22. return_value=fake_days):
  23. with mock.patch.object(views_mod.queries, 'get_top_players',
  24. side_effect=fake_get_top_players):
  25. with self.app.test_request_context():
  26. rsp = self.client.get('/api/v1/dashboard')
  27. assert rsp.status_code == 200
  28. views_mod.queries.get_game_dates.assert_called_with(
  29. mock.ANY
  30. )
  31. views_mod.queries.get_top_players.assert_any_call(
  32. mock.ANY
  33. )
  34. views_mod.queries.get_top_players.assert_any_call(
  35. mock.ANY, agg_by='suicides'
  36. )
  37. assert rsp.json['day'] == '2017-02-16'
  38. assert rsp.json['fotm'] == fake_fotm
  39. assert rsp.json['eotm'] == fake_eotm