q3stats/tests_web_app/test_get_api_v1_charts_play...

103 lines
2.9 KiB
Python

# -*- coding: utf -*-
import datetime
from q3stats.lib.scripts import utils
from q3stats.models import Game, Score
from q3stats.testing import BaseQ3StatsWebAppTestCase
from q3stats.web_app.blueprints.api_v1.views import charts as views_mod
class Test_GetAPIv1ChartsPlayerGame(BaseQ3StatsWebAppTestCase):
@classmethod
def setUpClass(cls):
super(Test_GetAPIv1ChartsPlayerGame, cls).setUpClass()
with utils.db_session(cls._config) as session:
game_dt = datetime.datetime(2017, 2, 15, 20, 21, 0)
game = Game(
uuid='game',
map='Q3DM7',
date=game_dt.date(),
time=game_dt.time(),
fraglimit=20,
attrs={}
)
game.scores.extend([
Score(
player='tomekwojcik',
score=20,
kills=21,
deaths=10,
suicides=1,
net=11,
damage_taken=123,
damage_given=456,
total_health=123,
total_armor=456,
weapons={},
items={},
powerups={}
),
Score(
player='Player 1',
score=10,
kills=11,
deaths=20,
suicides=1,
net=10,
damage_taken=123,
damage_given=456,
total_health=123,
total_armor=456,
weapons={},
items={},
powerups={}
),
])
session.add(game)
session.commit()
def test_not_found_player(self):
with self.app.test_request_context():
rsp = self.client.get(
'/api/v1/charts/player/%s/game/%s' % ('spam', 'game')
)
assert rsp.status_code == 404
def test_not_found_game(self):
with self.app.test_request_context():
rsp = self.client.get(
'/api/v1/charts/player/%s/game/%s' % ('tomekwojcik', 'spam')
)
assert rsp.status_code == 404
def test_ok(self):
with self.app.test_request_context():
rsp = self.client.get(
'/api/v1/charts/player/%s/game/%s' % ('tomekwojcik', 'game')
)
assert rsp.status_code == 200
assert rsp.json['score'] == [
['Frags', 21],
['Deaths', 10],
['Suicides', 1]
]
assert rsp.json['damage'] == [
['Taken', 123],
['Given', 456]
]
assert rsp.json['totals'] == [
['Armor', 456],
['Health', 123]
]