test_get_api_v1_charts_day.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # -*- coding: utf -*-
  2. import mock
  3. from q3stats.testing import BaseQ3StatsWebAppTestCase
  4. from q3stats.web_app.blueprints.api_v1.views import charts as views_mod
  5. class Test_GetAPIv1ChartsDay(BaseQ3StatsWebAppTestCase):
  6. def test_invalid_day(self):
  7. with self.app.test_request_context():
  8. rsp = self.client.get('/api/v1/charts/day/spam')
  9. assert rsp.status_code == 400
  10. def test_ok(self):
  11. fake_data = (
  12. ['Q3DM7', 'Q3DM17'],
  13. [
  14. {
  15. 'data': [30, 30],
  16. 'name': 'tomekwojcik'
  17. },
  18. {
  19. 'data': [29, 29],
  20. 'name': 'Player 1'
  21. }
  22. ]
  23. )
  24. with mock.patch.object(views_mod.charts, 'get_day_chart',
  25. return_value=fake_data):
  26. with self.app.test_request_context():
  27. rsp = self.client.get('/api/v1/charts/day/2017-02-15')
  28. assert rsp.status_code == 200
  29. assert rsp.json['day'] == '2017-02-15'
  30. assert rsp.json['maps'] == fake_data[0]
  31. assert rsp.json['scores'] == fake_data[1]