q3stats/tests_web_app/test_get_api_v1_dashboard.py

53 lines
1.7 KiB
Python

# -*- coding: utf -*-
import datetime
import mock
from q3stats.testing import BaseQ3StatsWebAppTestCase
from q3stats.web_app.blueprints.api_v1.views import dashboard as views_mod
class Test_GetAPIv1Dashboard(BaseQ3StatsWebAppTestCase):
def test_ok(self):
fake_days = [datetime.date(2017, 2, 16), datetime.date(2017, 2, 15)]
fake_fotm = [
['tomekwojcik', 20],
['Player 1', 10]
]
fake_eotm = [
['Player 1', 20],
['tomekwojcik', 10]
]
def fake_get_top_players(session, agg_by='kills'):
if agg_by == 'suicides':
return fake_eotm
return fake_fotm
with mock.patch.object(views_mod.queries, 'get_game_dates',
return_value=fake_days):
with mock.patch.object(views_mod.queries, 'get_top_players',
side_effect=fake_get_top_players):
with self.app.test_request_context():
rsp = self.client.get('/api/v1/dashboard')
assert rsp.status_code == 200
views_mod.queries.get_game_dates.assert_called_with(
mock.ANY
)
views_mod.queries.get_top_players.assert_any_call(
mock.ANY
)
views_mod.queries.get_top_players.assert_any_call(
mock.ANY, agg_by='suicides'
)
assert rsp.json['day'] == '2017-02-16'
assert rsp.json['fotm'] == fake_fotm
assert rsp.json['eotm'] == fake_eotm