2023-07-16 01:50:12 +10:00
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rolltime(check_datetime , curr_time=datetime.datetime.now()):
|
|
|
|
|
|
|
|
|
|
last_time = datetime.datetime.strptime(check_datetime, '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
time_to_grow = curr_time.replace(hour=14, minute=8, second=8, microsecond=0) #+ datetime.timedelta(days=0)
|
|
|
|
|
|
|
|
|
|
timediff = (time_to_grow - last_time).total_seconds()
|
|
|
|
|
|
2023-07-16 14:29:54 +10:00
|
|
|
|
# print()
|
2023-07-16 01:50:12 +10:00
|
|
|
|
# print(f'\tlast_time : {last_time}')
|
|
|
|
|
# print(f'\ttime_to_grow : {time_to_grow}')
|
|
|
|
|
# print(f'\tcurr_time : {curr_time.strftime("%Y-%m-%d %H:%M:%S")}')
|
|
|
|
|
# print(f'\t\tsecs diff : {timediff}')
|
|
|
|
|
|
2023-07-16 14:29:54 +10:00
|
|
|
|
if timediff > 86400 or (curr_time > time_to_grow and last_time < time_to_grow):
|
2023-07-16 01:50:12 +10:00
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestPipisa(unittest.TestCase):
|
|
|
|
|
def test_very_long_ago(self):
|
|
|
|
|
self.assertEqual(rolltime('2021-10-11 23:44:00'), True, "Пиписа прокручена очень давно. Очевидный прокрут")
|
|
|
|
|
|
|
|
|
|
def test_just_after(self):
|
|
|
|
|
self.assertEqual(rolltime(
|
|
|
|
|
datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
|
), False, "Попытка крутить когда старый прокрут был через 1 минуту после сегодняшнего обновления роллов. Фейл.")
|
|
|
|
|
|
|
|
|
|
def test_yesterdayroll(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
rolltime(
|
|
|
|
|
(
|
|
|
|
|
datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0) - datetime.timedelta(days=1)
|
|
|
|
|
).strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
|
|
datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0)
|
|
|
|
|
), True, "Крутилась вчера через минуту после обновления роллов. Должно пропускать ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_hour_before_roll(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
rolltime(
|
|
|
|
|
(
|
|
|
|
|
datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0) - datetime.timedelta(hours=1)
|
|
|
|
|
).strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
|
|
datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0)
|
|
|
|
|
), True, "Крутилась последний раз за час до прокрута. Надо разрешать заново!")
|
|
|
|
|
|
|
|
|
|
def test_after_midnight(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
rolltime(
|
|
|
|
|
(
|
|
|
|
|
datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0) - datetime.timedelta(hours=14)
|
|
|
|
|
).strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
|
|
datetime.datetime.now().replace(hour=0, minute=11, second=8, microsecond=0)
|
|
|
|
|
), False, "Где-то ночью прокручивается повторно. Фейл.")
|
|
|
|
|
|
|
|
|
|
def test_before_midnight(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
rolltime(
|
|
|
|
|
(
|
|
|
|
|
datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0) - datetime.timedelta(hours=15)
|
|
|
|
|
).strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
|
|
datetime.datetime.now().replace(hour=0, minute=11, second=8, microsecond=0) - datetime.timedelta(hours=15)
|
|
|
|
|
), False, "Где-то ночью прокручивается повторно. Фейл.")
|
2023-07-16 14:29:54 +10:00
|
|
|
|
|
|
|
|
|
def test_somewhere_after(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
rolltime(
|
|
|
|
|
(
|
|
|
|
|
datetime.datetime.now().replace(hour=14, minute=26, second=8, microsecond=0)
|
|
|
|
|
).strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
|
|
datetime.datetime.now().replace(hour=14, minute=27, second=8, microsecond=0)
|
|
|
|
|
), False, "Сегодня уже открутили а хотят ещё. Фейл.")
|
|
|
|
|
|
2023-07-16 01:50:12 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-07-16 01:53:33 +10:00
|
|
|
|
unittest.main(verbosity=2)
|