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

52 lines
2.1 KiB
Python

# vim: set fileencoding=utf-8
import unittest
from unittest.mock import Mock
from freezegun import freeze_time
from bemani.data.mysql.network import NetworkData
from bemani.tests.helpers import FakeCursor
class TestNetworkData(unittest.TestCase):
def test_get_schedule_type(self) -> None:
network = NetworkData({}, None)
with freeze_time('2016-01-01 12:00'):
# Check daily schedule
self.assertEqual(
# 2016-01-01 -> 2016-01-02
(1451606400, 1451692800),
network.get_schedule_duration('daily'),
)
# Check weekly schedule (weeks start on monday in python lol)
self.assertEqual(
# 2015-12-27 -> 2916-01-03
(1451260800, 1451865600),
network.get_schedule_duration('weekly'),
)
def test_should_schedule(self) -> None:
network = NetworkData({}, None)
with freeze_time('2016-01-01'):
# Check for should schedule if nothing in DB
network.execute = Mock(return_value=FakeCursor([]))
self.assertTrue(network.should_schedule('game', 1, 'work', 'daily'))
self.assertTrue(network.should_schedule('game', 1, 'work', 'weekly'))
# Check for don't schedule if DB time is our current time
network.execute = Mock(return_value=FakeCursor([{'year': 2016, 'day': 1}]))
self.assertFalse(network.should_schedule('game', 1, 'work', 'daily'))
network.execute = Mock(return_value=FakeCursor([{'year': None, 'day': 16797}]))
self.assertFalse(network.should_schedule('game', 1, 'work', 'weekly'))
# Check for do schedule if DB time is older than our current time
network.execute = Mock(return_value=FakeCursor([{'year': 2015, 'day': 365}]))
self.assertTrue(network.should_schedule('game', 1, 'work', 'daily'))
network.execute = Mock(return_value=FakeCursor([{'year': None, 'day': 16790}]))
self.assertTrue(network.should_schedule('game', 1, 'work', 'weekly'))