1
0
mirror of synced 2024-11-24 14:30:11 +01:00
bemaniutils/bemani/tests/test_GameData.py
2019-12-08 21:43:49 +00:00

33 lines
1.6 KiB
Python

# vim: set fileencoding=utf-8
import unittest
from unittest.mock import Mock
from bemani.data.mysql.game import GameData
from bemani.tests.helpers import FakeCursor
class TestGameData(unittest.TestCase):
def test_put_time_sensitive_settings(self) -> None:
game = GameData({}, None)
# Verify that we catch incorrect input order
with self.assertRaises(Exception) as context:
game.put_time_sensitive_settings('game', 1, 'work', {'start_time': 12345, 'end_time': 12340})
self.assertTrue('Start time is greater than end time!' in str(context.exception))
# Verify that we catch events spanning no time
with self.assertRaises(Exception) as context:
game.put_time_sensitive_settings('game', 1, 'work', {'start_time': 12345, 'end_time': 12345})
self.assertTrue('This setting spans zero seconds!' in str(context.exception))
# Verify that we ignore finding ourselves before updating
game.execute = Mock(return_value=FakeCursor([{'start_time': 12345, 'end_time': 12346}]))
game.put_time_sensitive_settings('game', 1, 'work', {'start_time': 12345, 'end_time': 12346})
# Verify that we catch events overlapping other events in the DB
game.execute = Mock(return_value=FakeCursor([{'start_time': 12345, 'end_time': 12350}]))
with self.assertRaises(Exception) as context:
game.put_time_sensitive_settings('game', 1, 'work', {'start_time': 12347, 'end_time': 12355})
self.assertTrue('This event overlaps an existing one with start time 12345 and end time 12350' in str(context.exception))