2022-02-09 10:55:26 +00:00
|
|
|
from datetime import datetime as dt
|
2022-05-21 11:06:10 +00:00
|
|
|
from datetime import timedelta
|
|
|
|
from unittest.mock import MagicMock
|
2023-05-01 08:28:11 +00:00
|
|
|
|
2022-05-21 11:06:10 +00:00
|
|
|
import pytest
|
|
|
|
import vorta.scheduler
|
2023-04-17 10:17:01 +00:00
|
|
|
from PyQt6 import QtCore
|
2022-05-21 11:06:10 +00:00
|
|
|
from vorta.application import VortaApp
|
|
|
|
from vorta.store.models import BackupProfileModel, EventLogModel
|
2018-11-01 06:01:44 +00:00
|
|
|
|
2022-05-21 11:06:10 +00:00
|
|
|
PROFILE_NAME = 'Default'
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def clockmock(monkeypatch):
|
|
|
|
datetime_mock = MagicMock(wraps=dt)
|
|
|
|
monkeypatch.setattr(vorta.scheduler, "dt", datetime_mock)
|
|
|
|
|
|
|
|
return datetime_mock
|
|
|
|
|
|
|
|
|
|
|
|
def test_schedule_tab(qapp: VortaApp, qtbot, clockmock):
|
2020-03-03 05:19:36 +00:00
|
|
|
main = qapp.main_window
|
2018-11-05 10:30:59 +00:00
|
|
|
tab = main.scheduleTab
|
2022-02-09 10:55:26 +00:00
|
|
|
|
2022-05-21 11:06:10 +00:00
|
|
|
# setup
|
|
|
|
time_now = dt(2020, 5, 6, 4, 30)
|
|
|
|
clockmock.now.return_value = time_now
|
|
|
|
|
2022-02-09 10:55:26 +00:00
|
|
|
# Work around
|
|
|
|
# because already 'deleted' scheduletabs are still connected to the signal
|
|
|
|
qapp.scheduler.schedule_changed.connect(lambda *args: tab.draw_next_scheduled_backup())
|
|
|
|
|
|
|
|
# Test
|
2023-04-17 10:17:01 +00:00
|
|
|
qtbot.mouseClick(tab.scheduleOffRadio, QtCore.Qt.MouseButton.LeftButton)
|
2018-11-17 10:12:00 +00:00
|
|
|
assert tab.nextBackupDateTimeLabel.text() == 'None scheduled'
|
2018-11-01 06:01:44 +00:00
|
|
|
|
2021-10-27 04:37:28 +00:00
|
|
|
tab.scheduleIntervalCount.setValue(5)
|
2023-04-17 10:17:01 +00:00
|
|
|
qtbot.mouseClick(tab.scheduleIntervalRadio, QtCore.Qt.MouseButton.LeftButton)
|
2021-10-27 04:37:28 +00:00
|
|
|
assert "None" not in tab.nextBackupDateTimeLabel.text()
|
2018-11-01 06:01:44 +00:00
|
|
|
|
|
|
|
tab.scheduleFixedTime.setTime(QtCore.QTime(23, 59))
|
2022-03-24 06:27:07 +00:00
|
|
|
|
|
|
|
# Clicking currently broken for this button on github.com only
|
2023-04-17 10:17:01 +00:00
|
|
|
# qtbot.mouseClick(tab.scheduleFixedRadio, QtCore.Qt.MouseButton.LeftButton)
|
2022-03-24 06:27:07 +00:00
|
|
|
|
|
|
|
# Workaround for github
|
|
|
|
tab.scheduleFixedRadio.setChecked(True)
|
|
|
|
tab.scheduleFixedRadio.clicked.emit()
|
|
|
|
|
2022-05-21 11:06:10 +00:00
|
|
|
assert tab.nextBackupDateTimeLabel.text() == 'Run a manual backup first'
|
|
|
|
|
|
|
|
next_backup = time_now.replace(hour=23, minute=59)
|
|
|
|
last_time = time_now - timedelta(days=2)
|
|
|
|
|
|
|
|
# setup model
|
|
|
|
profile = BackupProfileModel.get(name=PROFILE_NAME)
|
|
|
|
profile.schedule_make_up_missed = False
|
|
|
|
profile.save()
|
2022-08-15 17:02:40 +00:00
|
|
|
event = EventLogModel(
|
|
|
|
subcommand='create',
|
|
|
|
profile=profile.id,
|
|
|
|
returncode=0,
|
|
|
|
category='scheduled',
|
|
|
|
start_time=last_time,
|
|
|
|
end_time=last_time,
|
|
|
|
)
|
2022-05-21 11:06:10 +00:00
|
|
|
event.save()
|
|
|
|
|
|
|
|
qapp.scheduler.set_timer_for_profile(profile.id)
|
|
|
|
tab.draw_next_scheduled_backup()
|
2022-05-25 15:42:54 +00:00
|
|
|
|
|
|
|
assert tab.nextBackupDateTimeLabel.text() not in [
|
|
|
|
"Run a manual backup first",
|
|
|
|
"None scheduled",
|
|
|
|
]
|
|
|
|
assert qapp.scheduler.next_job_for_profile(profile.id).time == next_backup
|
|
|
|
|
2022-05-21 11:06:10 +00:00
|
|
|
qapp.scheduler.remove_job(profile.id)
|