1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-23 08:17:08 +00:00
vorta/tests/unit/test_schedule.py
jetchirag b015368fee
Integration Tests for Borg (#1716)
Move existing tests into subfolder `tests/unit`. Write integration tests that actually run the installed borg executable. Those tests can be found in `tests/integration`.  Those pytest fixtures that are the same for both kinds of tests remain in `tests/conftest.py`. The others can be found in `tests/integration/conftest.py` or `tests/unit/conftest.py`. This adds nox to the project and configures it to run the tests with different borg versions. This also updates the ci workflow to run the integration tests using nox.

* noxfile.py : Run pytest with a matrix of borg versions OR a specific borg version

* Makefile : Run using nox. Add phonies `test-unit` and `test-integration`.

* tests/conftest.py : Move some fixtures/functions to `tests/unit/conftest.py`.

* tests/test_*.py --> tests/unit/ : Move unittests and assets into subfolder

* tests/integration/ : Write integration tests.

* requirements.d/dev.txt: Add `nox` and `pkgconfig`. The latter is needed for installing new borg versions.

* .github/actions/setup/action.yml : Update to install pre-commit and nox when needed. The action now no longer installs Vorta.

* .github/actions/install-dependencies/action.yml : Install system deps of borg with this new composite action.

* .github/workflows/test.yml : Rename `test` ci to `test-unit` and update it for the new test setup.
                                              Implement `test-integration` ci.

Signed-off-by: Chirag Aggarwal <thechiragaggarwal@gmail.com>
2023-08-05 13:49:45 +00:00

79 lines
2.3 KiB
Python

from datetime import datetime as dt
from datetime import timedelta
from unittest.mock import MagicMock
import pytest
import vorta.scheduler
from PyQt6 import QtCore
from vorta.application import VortaApp
from vorta.store.models import BackupProfileModel, EventLogModel
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):
main = qapp.main_window
tab = main.scheduleTab
# setup
time_now = dt(2020, 5, 6, 4, 30)
clockmock.now.return_value = time_now
# 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
qtbot.mouseClick(tab.scheduleOffRadio, QtCore.Qt.MouseButton.LeftButton)
assert tab.nextBackupDateTimeLabel.text() == 'None scheduled'
tab.scheduleIntervalCount.setValue(5)
qtbot.mouseClick(tab.scheduleIntervalRadio, QtCore.Qt.MouseButton.LeftButton)
assert "None" not in tab.nextBackupDateTimeLabel.text()
tab.scheduleFixedTime.setTime(QtCore.QTime(23, 59))
# Clicking currently broken for this button on github.com only
# qtbot.mouseClick(tab.scheduleFixedRadio, QtCore.Qt.MouseButton.LeftButton)
# Workaround for github
tab.scheduleFixedRadio.setChecked(True)
tab.scheduleFixedRadio.clicked.emit()
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()
event = EventLogModel(
subcommand='create',
profile=profile.id,
returncode=0,
category='scheduled',
start_time=last_time,
end_time=last_time,
)
event.save()
qapp.scheduler.set_timer_for_profile(profile.id)
tab.draw_next_scheduled_backup()
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
qapp.scheduler.remove_job(profile.id)