q3stats/tests_models/test_models_game.py

90 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
import datetime
import mock
from q3stats.models import Game, Score
class Test_GameModel(object):
def test_update_uuid(self):
now = datetime.datetime(2017, 2, 14, 20, 21, 0)
game = Game(
uuid=None,
map='Q3DM7',
date=now.date(),
time=now.time()
)
game.update_uuid()
assert game.uuid == '6d302193-6ccd-3515-bd60-11127208e702'
def test_to_json(self):
now = datetime.datetime(2017, 2, 14, 20, 21, 0)
game = Game(
id=10,
uuid='spam',
map='Q3DM7',
date=now.date(),
time=now.time(),
fraglimit=20,
attrs={
'type': 'FFA',
'team_game': False,
'duration': 583
}
)
result = game.to_json()
assert result['id'] == game.id
assert result['uuid'] == game.uuid
assert result['date'] == '2017-02-14'
assert result['time'] == '20:21:00'
assert result['attrs'] == game.attrs
assert result['scores'] is None
def test_to_json_recursive(self):
now = datetime.datetime(2017, 2, 14, 20, 21, 0)
game = Game(
id=10,
uuid='spam',
map='Q3DM7',
date=now.date(),
time=now.time(),
fraglimit=20,
attrs={
'type': 'FFA',
'team_game': False,
'duration': 583
}
)
score = 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={},
items={},
powerups={}
)
score.to_json = mock.Mock(return_value='spam')
game.scores.append(score)
result = game.to_json(recursive=True)
assert result['scores'] is not None
assert len(result['scores']) == 1
assert result['scores'][0] == 'spam'