From ef46cb91d67a961552568272befb720ccf31674c Mon Sep 17 00:00:00 2001 From: Manu Date: Thu, 1 Nov 2018 14:01:44 +0800 Subject: [PATCH] Add test for scheduler tab. --- MANIFEST.in | 1 + README.md | 7 ++++--- setup.cfg | 6 ++---- tests/fixtures.py | 19 +++++++++++++++++++ tests/test_repo.py | 18 +----------------- tests/test_schedule.py | 29 +++++++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 MANIFEST.in create mode 100644 tests/fixtures.py create mode 100644 tests/test_schedule.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..aae95799 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-exclude tests * diff --git a/README.md b/README.md index 5414a313..a2aa323c 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Missing features: (PRs welcome) - [ ] Repo pruning - [ ] Repo checking - [ ] Full test coverage +- [ ] Use static type checks via mypy - [ ] Packaging for Linux ## Installation and Download @@ -48,7 +49,7 @@ Then run via $ vorta ``` -Qt Creator is used to edit views. Install using Homebrew and then open the .ui files in `vorta/UI`: +Qt Creator is used to edit views. Install from [their site](https://www.qt.io/download) or using Homebrew and then open the .ui files in `vorta/UI`: ``` $ brew cask install qt-creator $ brew install qt @@ -62,7 +63,7 @@ $ pyinstaller --clean --noconfirm vorta.spec ### Testing (work in progress) Tests are in the folder `/tests`. Testing happens at the level of UI components. Calls to `borg` are mocked and can be replaced with some example json-output. To run tests: ``` -$ python setup.py test +$ pytest ``` ## Privacy Policy @@ -78,5 +79,5 @@ $ python setup.py test ## License and Credits - Licensed under GPLv3. See LICENSE.txt for details. - Uses the excellent [BorgBackup](https://www.borgbackup.org) -- Based on PyQt and Qt. +- Based on [PyQt](https://riverbankcomputing.com/software/pyqt/intro) and [Qt](https://www.qt.io). - Icons by [FontAwesome](https://fontawesome.com) diff --git a/setup.cfg b/setup.cfg index ecf55c5e..be5154ff 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,9 +23,6 @@ long_description = file: README.md long_description_content_type = text/markdown license_file = LICENSE.txt -[aliases] -test=pytest - [options] python_requires = >= 3.6 setup_requires = @@ -50,6 +47,7 @@ tests = pytest pytest-qt pytest-mock + pytest-faulthandler mypy mypy-extensions @@ -59,7 +57,7 @@ gui_scripts = [tool:pytest] -addopts = -s +addopts = -vs testpaths = tests qt_default_raising = true filterwarnings = diff --git a/tests/fixtures.py b/tests/fixtures.py new file mode 100644 index 00000000..45b1ea62 --- /dev/null +++ b/tests/fixtures.py @@ -0,0 +1,19 @@ + +import pytest +import peewee + +import vorta +from vorta.application import VortaApp + +@pytest.fixture() +def app(tmpdir): + tmp_db = tmpdir.join('settings.sqlite') + mock_db = peewee.SqliteDatabase(str(tmp_db)) + vorta.models.init_db(mock_db) + return VortaApp([]) + + +@pytest.fixture() +def main(app): + main = app.main_window + return main diff --git a/tests/test_repo.py b/tests/test_repo.py index b7699e0c..2cb49e24 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -1,30 +1,14 @@ import pytest import io -import peewee from PyQt5 import QtCore import vorta.borg_runner import vorta.models -from vorta.application import VortaApp from vorta.views.repo_add import AddRepoWindow from vorta.models import EventLogModel, RepoModel - -@pytest.fixture() -def app(tmpdir): - tmp_db = tmpdir.join('settings.sqlite') - mock_db = peewee.SqliteDatabase(str(tmp_db)) - vorta.models.init_db(mock_db) - return VortaApp([]) - - -@pytest.fixture() -def main(app, qtbot): - main = app.main_window - qtbot.addWidget(main) - return main - +from .fixtures import * def test_repo_tab(main, qtbot): qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton) diff --git a/tests/test_schedule.py b/tests/test_schedule.py new file mode 100644 index 00000000..2aff3b52 --- /dev/null +++ b/tests/test_schedule.py @@ -0,0 +1,29 @@ +from datetime import datetime as dt, date, time +from PyQt5 import QtCore + +from vorta.views.schedule_tab import ScheduleTab + +from .fixtures import app, main + +def test_schedule_tab(main, qtbot): + tab = ScheduleTab(main.scheduleTabSlot) + qtbot.addWidget(tab) + qtbot.mouseClick(tab.scheduleApplyButton, QtCore.Qt.LeftButton) + assert tab.nextBackupDateTimeLabel.text() == 'Manual Backups' + + tab.scheduleIntervalRadio.setChecked(True) + tab.scheduleIntervalHours.setValue(5) + tab.scheduleIntervalMinutes.setValue(10) + qtbot.mouseClick(tab.scheduleApplyButton, QtCore.Qt.LeftButton) + assert tab.nextBackupDateTimeLabel.text().startswith('20') + + tab.scheduleOffRadio.setChecked(True) + qtbot.mouseClick(tab.scheduleApplyButton, QtCore.Qt.LeftButton) + assert tab.nextBackupDateTimeLabel.text() == 'Manual Backups' + + tab.scheduleFixedRadio.setChecked(True) + tab.scheduleFixedTime.setTime(QtCore.QTime(23, 59)) + qtbot.mouseClick(tab.scheduleApplyButton, QtCore.Qt.LeftButton) + next_backup = dt.combine(date.today(), time(23, 59)) + assert tab.nextBackupDateTimeLabel.text() == next_backup.strftime('%Y-%m-%d %H:%M') +