2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
import unittest
|
|
|
|
from unittest.mock import Mock
|
|
|
|
|
2021-08-19 21:20:13 +02:00
|
|
|
from bemani.common import GameConstants
|
2019-12-08 22:43:49 +01:00
|
|
|
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:
|
2021-08-20 06:43:59 +02:00
|
|
|
game = GameData(Mock(), None)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that we catch incorrect input order
|
|
|
|
with self.assertRaises(Exception) as context:
|
2022-10-15 20:56:30 +02:00
|
|
|
game.put_time_sensitive_settings(
|
|
|
|
GameConstants.BISHI_BASHI,
|
|
|
|
1,
|
|
|
|
"work",
|
|
|
|
{"start_time": 12345, "end_time": 12340},
|
|
|
|
)
|
|
|
|
self.assertTrue(
|
|
|
|
"Start time is greater than end time!" in str(context.exception)
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that we catch events spanning no time
|
|
|
|
with self.assertRaises(Exception) as context:
|
2022-10-15 20:56:30 +02:00
|
|
|
game.put_time_sensitive_settings(
|
|
|
|
GameConstants.BISHI_BASHI,
|
|
|
|
1,
|
|
|
|
"work",
|
|
|
|
{"start_time": 12345, "end_time": 12345},
|
|
|
|
)
|
|
|
|
self.assertTrue("This setting spans zero seconds!" in str(context.exception))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that we ignore finding ourselves before updating
|
2022-10-15 20:56:30 +02:00
|
|
|
game.execute = Mock(return_value=FakeCursor([{"start_time": 12345, "end_time": 12346}])) # type: ignore
|
|
|
|
game.put_time_sensitive_settings(
|
|
|
|
GameConstants.BISHI_BASHI,
|
|
|
|
1,
|
|
|
|
"work",
|
|
|
|
{"start_time": 12345, "end_time": 12346},
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that we catch events overlapping other events in the DB
|
2022-10-15 20:56:30 +02:00
|
|
|
game.execute = Mock(return_value=FakeCursor([{"start_time": 12345, "end_time": 12350}])) # type: ignore
|
2019-12-08 22:43:49 +01:00
|
|
|
with self.assertRaises(Exception) as context:
|
2022-10-15 20:56:30 +02:00
|
|
|
game.put_time_sensitive_settings(
|
|
|
|
GameConstants.BISHI_BASHI,
|
|
|
|
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)
|
|
|
|
)
|