2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
import unittest
|
|
|
|
from unittest.mock import Mock
|
|
|
|
from freezegun import freeze_time
|
|
|
|
|
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.network import NetworkData
|
|
|
|
from bemani.tests.helpers import FakeCursor
|
|
|
|
|
|
|
|
|
|
|
|
class TestNetworkData(unittest.TestCase):
|
|
|
|
def test_get_schedule_type(self) -> None:
|
2021-08-20 06:43:59 +02:00
|
|
|
network = NetworkData(Mock(), None)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
with freeze_time("2016-01-01 12:00"):
|
2019-12-08 22:43:49 +01:00
|
|
|
# Check daily schedule
|
|
|
|
self.assertEqual(
|
|
|
|
# 2016-01-01 -> 2016-01-02
|
|
|
|
(1451606400, 1451692800),
|
2022-10-15 20:56:30 +02:00
|
|
|
network.get_schedule_duration("daily"),
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Check weekly schedule (weeks start on monday in python lol)
|
|
|
|
self.assertEqual(
|
|
|
|
# 2015-12-27 -> 2916-01-03
|
|
|
|
(1451260800, 1451865600),
|
2022-10-15 20:56:30 +02:00
|
|
|
network.get_schedule_duration("weekly"),
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_should_schedule(self) -> None:
|
2021-08-20 06:43:59 +02:00
|
|
|
network = NetworkData(Mock(), None)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
with freeze_time("2016-01-01"):
|
2019-12-08 22:43:49 +01:00
|
|
|
# Check for should schedule if nothing in DB
|
2021-08-19 21:20:13 +02:00
|
|
|
network.execute = Mock(return_value=FakeCursor([])) # type: ignore
|
2022-10-15 20:56:30 +02:00
|
|
|
self.assertTrue(
|
|
|
|
network.should_schedule(GameConstants.BISHI_BASHI, 1, "work", "daily")
|
|
|
|
)
|
|
|
|
self.assertTrue(
|
|
|
|
network.should_schedule(GameConstants.BISHI_BASHI, 1, "work", "weekly")
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Check for don't schedule if DB time is our current time
|
2022-10-15 20:56:30 +02:00
|
|
|
network.execute = Mock(return_value=FakeCursor([{"year": 2016, "day": 1}])) # type: ignore
|
|
|
|
self.assertFalse(
|
|
|
|
network.should_schedule(GameConstants.BISHI_BASHI, 1, "work", "daily")
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
network.execute = Mock(return_value=FakeCursor([{"year": None, "day": 16797}])) # type: ignore
|
|
|
|
self.assertFalse(
|
|
|
|
network.should_schedule(GameConstants.BISHI_BASHI, 1, "work", "weekly")
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Check for do schedule if DB time is older than our current time
|
2022-10-15 20:56:30 +02:00
|
|
|
network.execute = Mock(return_value=FakeCursor([{"year": 2015, "day": 365}])) # type: ignore
|
|
|
|
self.assertTrue(
|
|
|
|
network.should_schedule(GameConstants.BISHI_BASHI, 1, "work", "daily")
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
network.execute = Mock(return_value=FakeCursor([{"year": None, "day": 16790}])) # type: ignore
|
|
|
|
self.assertTrue(
|
|
|
|
network.should_schedule(GameConstants.BISHI_BASHI, 1, "work", "weekly")
|
|
|
|
)
|