q3stats/tests_web_app/test_get_api_v1_player_game.py

106 lines
3.2 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 players as views_mod
class Test_GetAPIv1Players(BaseQ3StatsWebAppTestCase):
@classmethod
def setUpClass(cls):
super(Test_GetAPIv1Players, cls).setUpClass()
with utils.db_session(cls._config) as session:
game1_dt = datetime.datetime(2017, 2, 21, 18, 30)
game1 = Game(
uuid='game1',
map='Q3DM7',
date=game1_dt.date(),
time=game1_dt.time(),
fraglimit=20,
attrs={}
)
game1.scores.extend([
Score(
player='Player 1',
score=20,
kills=21,
deaths=10,
suicides=1,
net=11,
damage_taken=123,
damage_given=456,
total_health=123,
total_armor=456,
weapons={
'RL': {
'hits': 10,
'kills': 5,
'shots': 20
}
},
items={
'YA': 1
},
powerups={
'Quad': [3, 40000]
}
),
Score(
player='Player 2',
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(game1)
session.commit()
def test_not_found_game(self):
with self.app.test_request_context():
rsp = self.client.get('/api/v1/players/Player 1/game/spam')
assert rsp.status_code == 404
def test_not_found_player(self):
with self.app.test_request_context():
rsp = self.client.get('/api/v1/players/spam/game/game1')
assert rsp.status_code == 404
def test_ok(self):
with self.app.test_request_context():
rsp = self.client.get('/api/v1/players/Player 1/game/game1')
assert rsp.status_code == 200
assert rsp.json['game'] == 'game1'
assert rsp.json['player'] == 'Player 1'
assert rsp.json['map'] == 'Q3DM7'
assert rsp.json['items'] == {'YA': 1}
assert rsp.json['weapons'] == {
'RL': {
'hits': 10,
'kills': 5,
'shots': 20,
'accuracy': '50.00%'
}
}
assert rsp.json['powerups'] == {
'Quad': [3, '40.000']
}