From 64b391fae1d78435b4d94b3b359aa78a63f97799 Mon Sep 17 00:00:00 2001 From: Manu Date: Tue, 6 Nov 2018 14:47:04 +0800 Subject: [PATCH] Add more tests and sample borg output. --- src/vorta/assets/UI/mainwindow.ui | 4 +- src/vorta/models.py | 3 ++ tests/borg_json_output/create_stderr.json | 32 ++++++++++++ tests/borg_json_output/create_stdout.json | 48 ++++++++++++++++++ tests/borg_json_output/info_stderr.json | 20 ++++++++ tests/borg_json_output/info_stdout.json | 22 +++++++++ tests/borg_json_output/list_stderr.json | 17 +++++++ tests/borg_json_output/list_stdout.json | 60 +++++++++++++++++++++++ tests/conftest.py | 29 +++++++++-- tests/test_repo.py | 29 ++++++++--- tests/test_schedule.py | 1 - tests/test_snapshots.py | 41 ++++++++++++++++ 12 files changed, 294 insertions(+), 12 deletions(-) create mode 100644 tests/borg_json_output/create_stderr.json create mode 100644 tests/borg_json_output/create_stdout.json create mode 100644 tests/borg_json_output/info_stderr.json create mode 100644 tests/borg_json_output/info_stdout.json create mode 100644 tests/borg_json_output/list_stderr.json create mode 100644 tests/borg_json_output/list_stdout.json create mode 100644 tests/test_snapshots.py diff --git a/src/vorta/assets/UI/mainwindow.ui b/src/vorta/assets/UI/mainwindow.ui index 6804c282..1b8f2b95 100644 --- a/src/vorta/assets/UI/mainwindow.ui +++ b/src/vorta/assets/UI/mainwindow.ui @@ -18,8 +18,8 @@ - 800 - 600 + 16777215 + 16777215 diff --git a/src/vorta/models.py b/src/vorta/models.py index a5c17214..988455e6 100644 --- a/src/vorta/models.py +++ b/src/vorta/models.py @@ -67,6 +67,9 @@ class BackupProfileModel(pw.Model): prune_month = pw.IntegerField(default=6) prune_year = pw.IntegerField(default=2) + def refresh(self): + return type(self).get(self._pk_expr()) + class Meta: database = db diff --git a/tests/borg_json_output/create_stderr.json b/tests/borg_json_output/create_stderr.json new file mode 100644 index 00000000..84470679 --- /dev/null +++ b/tests/borg_json_output/create_stderr.json @@ -0,0 +1,32 @@ +{"original_size": 0, "compressed_size": 0, "deduplicated_size": 0, "nfiles": 0, "time": 1541485444.8891299, "type": "archive_progress", "path": "Users/manu/Documents/financial/Allianz"} +{"message": "Initializing cache transaction: Reading config", "operation": 1, "msgid": "cache.begin_transaction", "type": "progress_message", "finished": false, "time": 1541485444.8924448} +{"message": "Initializing cache transaction: Reading chunks", "operation": 1, "msgid": "cache.begin_transaction", "type": "progress_message", "finished": false, "time": 1541485444.893108} +{"message": "Initializing cache transaction: Reading files", "operation": 1, "msgid": "cache.begin_transaction", "type": "progress_message", "finished": false, "time": 1541485444.893551} +{"operation": 1, "msgid": "cache.begin_transaction", "type": "progress_message", "finished": true, "time": 1541485444.894015} +{"original_size": 219715, "compressed_size": 201311, "deduplicated_size": 201311, "nfiles": 0, "time": 1541485446.009297, "type": "archive_progress", "path": "Users/manu/Documents/financial/Allianz/DOC-TOB-IN-EN-1114.pdf"} +{"type": "file_status", "status": "M", "path": "/Users/manu/Documents/financial/Allianz/DOC-TOB-IN-EN-1114.pdf"} +{"type": "file_status", "status": "M", "path": "/Users/manu/Documents/financial/Allianz/IBG_Nov_2013_1.pdf"} +{"type": "file_status", "status": "M", "path": "/Users/manu/Documents/financial/Allianz/cert-2014.pdf"} +{"type": "file_status", "status": "M", "path": "/Users/manu/Documents/financial/Allianz/cert-2015.pdf"} +{"original_size": 2397780, "compressed_size": 2333367, "deduplicated_size": 2333367, "nfiles": 4, "time": 1541485447.7346282, "type": "archive_progress", "path": "Users/manu/Documents/financial/Allianz/cert-2018.pdf"} +{"type": "file_status", "status": "M", "path": "/Users/manu/Documents/financial/Allianz/cert-2018.pdf"} +{"name": "borg.repository", "time": 1541485448.00131, "message": "Remote: Storage quota: 10.48 MB out of 1.00 GB used.", "type": "log_message", "levelname": "INFO"} +{"original_size": 2476130, "compressed_size": 2407012, "deduplicated_size": 2407012, "nfiles": 5, "time": 1541485448.1266649, "type": "archive_progress", "path": "Users/manu/Documents/financial/Allianz/invoice-2016.pdf"} +{"type": "file_status", "status": "M", "path": "/Users/manu/Documents/financial/Allianz/invoice-2016.pdf"} +{"original_size": 2579891, "compressed_size": 2508476, "deduplicated_size": 2508476, "nfiles": 6, "time": 1541485448.490915, "type": "archive_progress", "path": "Users/manu/Documents/financial/Allianz/invoice-2018.pdf"} +{"type": "file_status", "status": "M", "path": "/Users/manu/Documents/financial/Allianz/invoice-2018.pdf"} +{"original_size": 2682858, "compressed_size": 2610103, "deduplicated_size": 2610103, "nfiles": 7, "time": 1541485448.794081, "type": "archive_progress", "path": "Users/manu/Documents/financial/Allianz/invoice-2017.pdf"} +{"type": "file_status", "status": "M", "path": "/Users/manu/Documents/financial/Allianz/invoice-2017.pdf"} +{"type": "file_status", "status": "M", "path": "/Users/manu/Documents/financial/Allianz/membership card.pdf"} +{"original_size": 3034142, "compressed_size": 2951714, "deduplicated_size": 2951714, "nfiles": 9, "time": 1541485449.0265841, "type": "archive_progress", "path": "Users/manu/Documents/financial/Allianz/invoice-2019"} +{"type": "file_status", "status": "A", "path": "/Users/manu/Documents/financial/Allianz/invoice-2019"} +{"type": "file_status", "status": "d", "path": "/Users/manu/Documents/financial/Allianz"} +{"name": "borg.repository", "time": 1541485454.6220284, "message": "Remote: Storage quota: 13.44 MB out of 1.00 GB used.", "type": "log_message", "levelname": "INFO"} +{"total": 2, "type": "progress_percent", "time": 1541485454.960747, "finished": false, "current": 1, "message": "Remote: Compacting segments 0%", "info": null, "msgid": "repository.compact_segments", "operation": 1} +{"total": 2, "type": "progress_percent", "time": 1541485454.9839778, "finished": false, "current": 2, "message": "Remote: Compacting segments 50%", "info": null, "msgid": "repository.compact_segments", "operation": 1} +{"time": 1541485454.9841166, "operation": 1, "finished": true, "type": "progress_percent", "msgid": "repository.compact_segments"} +{"message": "Saving files cache", "operation": 2, "msgid": "cache.commit", "type": "progress_message", "finished": false, "time": 1541485455.270078} +{"message": "Saving chunks cache", "operation": 2, "msgid": "cache.commit", "type": "progress_message", "finished": false, "time": 1541485455.273303} +{"message": "Saving cache config", "operation": 2, "msgid": "cache.commit", "type": "progress_message", "finished": false, "time": 1541485455.2741609} +{"operation": 2, "msgid": "cache.commit", "type": "progress_message", "finished": true, "time": 1541485455.276022} +{"original_size": 3038309, "compressed_size": 2954077, "deduplicated_size": 2954077, "nfiles": 10, "time": 1541485455.2761118, "type": "archive_progress", "path": ""} diff --git a/tests/borg_json_output/create_stdout.json b/tests/borg_json_output/create_stdout.json new file mode 100644 index 00000000..750d736c --- /dev/null +++ b/tests/borg_json_output/create_stdout.json @@ -0,0 +1,48 @@ +{ + "archive": { + "command_line": [ + "/Users/manu/.pyenv/versions/3.7.1/bin/borg", + "create", + "--list", + "--progress", + "--info", + "--log-json", + "--json", + "w66xh7lj@w66xh7lj.repo.borgbase.com:repo::test-snapadkkfdddasdf", + "/Users/manu/Documents/financial/Allianz" + ], + "duration": 4.454152, + "end": "2018-11-06T14:24:09.000000", + "id": "b7a67208a9329bc48f7e2953b9803ffe0175e776a49d7f1a9c07581e3e7b5a17", + "limits": { + "max_archive_size": 2.851491780813361e-05 + }, + "name": "test-snapadkkfdddasdf", + "start": "2018-11-06T14:24:04.000000", + "stats": { + "compressed_size": 2954077, + "deduplicated_size": 2954077, + "nfiles": 10, + "original_size": 3038309 + } + }, + "cache": { + "path": "/Users/manu/.cache/borg/daf2e2b94a1b57f0effc96939813ef58d0af04414f92f87c3e092a99adaa90eb", + "stats": { + "total_chunks": 97, + "total_csize": 23892256, + "total_size": 27955635, + "total_unique_chunks": 63, + "unique_csize": 13435127, + "unique_size": 15520474 + } + }, + "encryption": { + "mode": "repokey-blake2" + }, + "repository": { + "id": "daf2e2b94a1b57f0effc96939813ef58d0af04414f92f87c3e092a99adaa90eb", + "last_modified": "2018-11-06T14:24:14.000000", + "location": "ssh://w66xh7lj@w66xh7lj.repo.borgbase.com/./repo" + } +} diff --git a/tests/borg_json_output/info_stderr.json b/tests/borg_json_output/info_stderr.json new file mode 100644 index 00000000..01f61b8c --- /dev/null +++ b/tests/borg_json_output/info_stderr.json @@ -0,0 +1,20 @@ +{"type": "log_message", "time": 1541485706.185808, "message": "using builtin fallback logging configuration", "levelname": "DEBUG", "name": "borg.logger"} +{"type": "log_message", "time": 1541485706.329196, "message": "35 self tests completed in 0.14 seconds", "levelname": "DEBUG", "name": "borg.archiver"} +{"type": "log_message", "time": 1541485706.32982, "message": "SSH command line: ['ssh', 'w66xh7lj@w66xh7lj.repo.borgbase.com', 'borg', 'serve', '--umask=077', '--debug']", "levelname": "DEBUG", "name": "borg.remote"} +{"type": "log_message", "time": 1541485712.0352168, "message": "Remote: using builtin fallback logging configuration", "levelname": "DEBUG", "name": "borg.logger"} +{"type": "log_message", "time": 1541485712.10305, "message": "Remote: 35 self tests completed in 0.16 seconds", "levelname": "DEBUG", "name": "borg.archiver"} +{"type": "log_message", "time": 1541485711.9786682, "levelname": "DEBUG", "message": "Remote: using builtin fallback logging configuration", "name": "borg.logger"} +{"type": "log_message", "time": 1541485711.9788692, "levelname": "DEBUG", "message": "Remote: Initialized logging system for JSON-based protocol", "name": "borg.remote"} +{"type": "log_message", "time": 1541485712.2395813, "levelname": "DEBUG", "message": "Remote: Resolving repository path b'repo'", "name": "root"} +{"type": "log_message", "time": 1541485712.240386, "levelname": "DEBUG", "message": "Remote: Resolved repository path to '/srv/repos/w66xh7lj/repo'", "name": "root"} +{"type": "log_message", "time": 1541485712.7960937, "levelname": "DEBUG", "message": "Remote: Verified integrity of /srv/repos/w66xh7lj/repo/index.153", "name": "borg.crypto.file_integrity"} +{"type": "log_message", "time": 1541485713.763066, "message": "TAM-verified manifest", "levelname": "DEBUG", "name": "borg.crypto.key"} +{"type": "log_message", "time": 1541485713.779689, "message": "security: read previous location 'ssh://w66xh7lj@w66xh7lj.repo.borgbase.com/./repo'", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541485713.780284, "message": "security: read manifest timestamp '2018-11-06T06:24:14.199720'", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541485713.780406, "message": "security: determined newest manifest timestamp as 2018-11-06T06:24:14.199720", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541485713.7819798, "message": "security: repository checks ok, allowing access", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541485713.7866921, "message": "Verified integrity of /Users/manu/.cache/borg/daf2e2b94a1b57f0effc96939813ef58d0af04414f92f87c3e092a99adaa90eb/chunks", "levelname": "DEBUG", "name": "borg.crypto.file_integrity"} +{"type": "log_message", "time": 1541485713.7872949, "message": "security: read previous location 'ssh://w66xh7lj@w66xh7lj.repo.borgbase.com/./repo'", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541485713.787873, "message": "security: read manifest timestamp '2018-11-06T06:24:14.199720'", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541485713.788007, "message": "security: determined newest manifest timestamp as 2018-11-06T06:24:14.199720", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541485713.788181, "message": "security: repository checks ok, allowing access", "levelname": "DEBUG", "name": "borg.cache"} diff --git a/tests/borg_json_output/info_stdout.json b/tests/borg_json_output/info_stdout.json new file mode 100644 index 00000000..968b7f2f --- /dev/null +++ b/tests/borg_json_output/info_stdout.json @@ -0,0 +1,22 @@ +{ + "cache": { + "path": "/Users/manu/.cache/borg/daf2e2b94a1b57f0effc96939813ef58d0af04414f92f87c3e092a99adaa90eb", + "stats": { + "total_chunks": 97, + "total_csize": 23892256, + "total_size": 27955635, + "total_unique_chunks": 63, + "unique_csize": 13435127, + "unique_size": 15520474 + } + }, + "encryption": { + "mode": "repokey-blake2" + }, + "repository": { + "id": "daf2e2b94a1b57f0effc96939813ef58d0af04414f92f87c3e092a99adaa90eb", + "last_modified": "2018-11-06T14:24:14.000000", + "location": "ssh://w66xh7lj@w66xh7lj.repo.borgbase.com/./repo" + }, + "security_dir": "/Users/manu/.config/borg/security/daf2e2b94a1b57f0effc96939813ef58d0af04414f92f87c3e092a99adaa90eb" +} diff --git a/tests/borg_json_output/list_stderr.json b/tests/borg_json_output/list_stderr.json new file mode 100644 index 00000000..e690cac6 --- /dev/null +++ b/tests/borg_json_output/list_stderr.json @@ -0,0 +1,17 @@ +{"type": "log_message", "time": 1541483306.565752, "message": "using builtin fallback logging configuration", "levelname": "DEBUG", "name": "borg.logger"} +{"type": "log_message", "time": 1541483306.700531, "message": "35 self tests completed in 0.13 seconds", "levelname": "DEBUG", "name": "borg.archiver"} +{"type": "log_message", "time": 1541483306.701061, "message": "SSH command line: ['ssh', 'i0fis593@i0fis593.repo.borgbase.com', 'borg', 'serve', '--umask=077', '--debug']", "levelname": "DEBUG", "name": "borg.remote"} +{"type": "log_message", "time": 1541483311.98485, "message": "Remote: using builtin fallback logging configuration", "levelname": "DEBUG", "name": "borg.logger"} +{"type": "log_message", "time": 1541483312.104528, "message": "Remote: 35 self tests completed in 0.30 seconds", "levelname": "DEBUG", "name": "borg.archiver"} +{"type": "log_message", "time": 1541483311.9681718, "name": "borg.logger", "message": "Remote: using builtin fallback logging configuration", "levelname": "DEBUG"} +{"type": "log_message", "time": 1541483311.9683647, "name": "borg.remote", "message": "Remote: Initialized logging system for JSON-based protocol", "levelname": "DEBUG"} +{"type": "log_message", "time": 1541483312.2289863, "name": "root", "message": "Remote: Resolving repository path b'repo'", "levelname": "DEBUG"} +{"type": "log_message", "time": 1541483312.2298186, "name": "root", "message": "Remote: Resolved repository path to '/srv/repos/i0fis593/repo'", "levelname": "DEBUG"} +{"type": "log_message", "time": 1541483312.525757, "name": "borg.crypto.file_integrity", "message": "Remote: Verified integrity of /srv/repos/i0fis593/repo/index.81", "levelname": "DEBUG"} +Enter passphrase for key ssh://i0fis593@i0fis593.repo.borgbase.com/./repo: +{"type": "log_message", "time": 1541483318.230314, "message": "TAM-verified manifest", "levelname": "DEBUG", "name": "borg.crypto.key"} +{"type": "log_message", "time": 1541483318.234584, "message": "security: read previous location 'ssh://i0fis593@i0fis593.repo.borgbase.com/./repo'", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541483318.2360609, "message": "security: read manifest timestamp '2018-11-06T04:35:11.031517'", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541483318.236227, "message": "security: determined newest manifest timestamp as 2018-11-06T04:35:11.031517", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541483318.238312, "message": "security: repository checks ok, allowing access", "levelname": "DEBUG", "name": "borg.cache"} +{"type": "log_message", "time": 1541483318.244082, "message": "RemoteRepository: 213 B bytes sent, 4.19 kB bytes received, 6 messages sent", "levelname": "DEBUG", "name": "borg.remote"} diff --git a/tests/borg_json_output/list_stdout.json b/tests/borg_json_output/list_stdout.json new file mode 100644 index 00000000..f656e485 --- /dev/null +++ b/tests/borg_json_output/list_stdout.json @@ -0,0 +1,60 @@ +{ + "archives": [ + { + "archive": "nyx2.local-2018-11-04T23:19:04.864971", + "barchive": "nyx2.local-2018-11-04T23:19:04.864971", + "id": "32c86b44565e0f517abb3f1982f2789794773269ffc233e63c4f9b7e70527147", + "name": "nyx2.local-2018-11-04T23:19:04.864971", + "start": "2018-11-04T23:19:15.000000", + "time": "2018-11-04T23:19:15.000000" + }, + { + "archive": "nyx2.local-2018-11-05T22:12:14.375598", + "barchive": "nyx2.local-2018-11-05T22:12:14.375598", + "id": "6130a386f6a8e44efa35a3ab727a7116402edd9ef426c974b1ef40657313be05", + "name": "nyx2.local-2018-11-05T22:12:14.375598", + "start": "2018-11-05T22:12:45.000000", + "time": "2018-11-05T22:12:45.000000" + }, + { + "archive": "nyx2.local-2018-11-05T22:13:23.166918", + "barchive": "nyx2.local-2018-11-05T22:13:23.166918", + "id": "185d842309bc72e54ff3ca12c8022c473563c33435db413fdd7de1cab38ae9cf", + "name": "nyx2.local-2018-11-05T22:13:23.166918", + "start": "2018-11-05T22:13:32.000000", + "time": "2018-11-05T22:13:32.000000" + }, + { + "archive": "nyx2.local-2018-11-05T23:05:00.117950", + "barchive": "nyx2.local-2018-11-05T23:05:00.117950", + "id": "1bdbfedd59bd7222c3a8cc1a0188966b5db9484a3b0377009499b2c18d4f8ec5", + "name": "nyx2.local-2018-11-05T23:05:00.117950", + "start": "2018-11-05T23:05:09.000000", + "time": "2018-11-05T23:05:09.000000" + }, + { + "archive": "nyx2.local-2018-11-06T09:35:00.569691", + "barchive": "nyx2.local-2018-11-06T09:35:00.569691", + "id": "dd59bb26c1eed3aa21424a252cd73efcff0252156c50d67fb806a3a772c7cb48", + "name": "nyx2.local-2018-11-06T09:35:00.569691", + "start": "2018-11-06T09:35:10.000000", + "time": "2018-11-06T09:35:10.000000" + }, + { + "archive": "nyx2.local-2018-11-06T12:35:00.087922", + "barchive": "nyx2.local-2018-11-06T12:35:00.087922", + "id": "0ad78376f9e8d0f9ad359535c582da910b12a3d8c61ee5cc30bc57b1eb4c1b9a", + "name": "nyx2.local-2018-11-06T12:35:00.087922", + "start": "2018-11-06T12:35:09.000000", + "time": "2018-11-06T12:35:09.000000" + } + ], + "encryption": { + "mode": "repokey-blake2" + }, + "repository": { + "id": "3c1861de5908546a65409ed6b98024c0a4845d5348496010896798368c2424dd", + "last_modified": "2018-11-06T12:35:11.000000", + "location": "ssh://i0fis593@i0fis593.repo.borgbase.com/./repo" + } +} diff --git a/tests/conftest.py b/tests/conftest.py index 77b97de8..01887ed5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,14 +1,37 @@ - +import io import pytest import peewee import vorta from vorta.application import VortaApp +from vorta.models import RepoModel, SourceDirModel @pytest.fixture() -def app(tmpdir): +def app(tmpdir, qtbot): tmp_db = tmpdir.join('settings.sqlite') mock_db = peewee.SqliteDatabase(str(tmp_db)) vorta.models.init_db(mock_db) - return VortaApp([]) + app = VortaApp([]) + qtbot.addWidget(app.main_window) + return app + +@pytest.fixture() +def app_with_repo(app): + profile = app.profile() + new_repo = RepoModel(url='i0fi93@i593.repo.borgbase.com:repo') + new_repo.save() + profile.repo = new_repo + profile.save() + + source_dir = SourceDirModel(dir='/tmp', repo=new_repo) + source_dir.save() + return app + +@pytest.fixture +def borg_json_output(): + def _read_json(subcommand): + stdout = open(f'tests/borg_json_output/{subcommand}_stdout.json').read() + stderr = open(f'tests/borg_json_output/{subcommand}_stderr.json').read() + return io.StringIO(stdout), io.StringIO(stderr) + return _read_json diff --git a/tests/test_repo.py b/tests/test_repo.py index 51415039..71f6ff9a 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -1,19 +1,18 @@ -import io from PyQt5 import QtCore import vorta.borg.borg_thread import vorta.models from vorta.views.repo_add import AddRepoWindow -from vorta.models import EventLogModel, RepoModel +from vorta.models import EventLogModel, RepoModel, SnapshotModel -def test_repo_tab(app, qtbot): +def test_create_error(app, qtbot): main = app.main_window qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton) assert main.createProgressText.text() == 'Add a remote backup repository first.' -def test_repo_add(app, qtbot, mocker): +def test_repo_add(app, qtbot, mocker, borg_json_output): # Add new repo window main = app.main_window add_repo_window = AddRepoWindow(main.repoTab) @@ -27,8 +26,9 @@ def test_repo_add(app, qtbot, mocker): qtbot.keyClicks(add_repo_window.passwordLineEdit, 'long-password-long') - popen_result =mocker.MagicMock(stdout=io.StringIO("some initial binary data"), - stderr=io.StringIO("some initial binary data"), + stdout, stderr = borg_json_output('info') + popen_result =mocker.MagicMock(stdout=stdout, + stderr=stderr, returncode=0) mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result) @@ -42,3 +42,20 @@ def test_repo_add(app, qtbot, mocker): # assert EventLogModel.select().count() == 2 assert RepoModel.get(id=1).url == 'aaabbb.com:repo' +def test_create(app_with_repo, borg_json_output, mocker, qtbot): + main = app_with_repo.main_window + stdout, stderr = borg_json_output('create') + popen_result =mocker.MagicMock(stdout=stdout, + stderr=stderr, + returncode=0) + mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result) + + qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton) + qtbot.waitUntil(lambda: main.createProgressText.text().startswith('INFO: Remote')) + assert EventLogModel.select().count() == 1 + assert SnapshotModel.select().count() == 1 + assert RepoModel.get(id=1).unique_size == 15520474 + assert main.createStartBtn.isEnabled() + assert main.snapshotTab.snapshotTable.rowCount() == 1 + assert main.scheduleTab.logTableWidget.rowCount() == 1 + diff --git a/tests/test_schedule.py b/tests/test_schedule.py index cdfa1845..892bd754 100644 --- a/tests/test_schedule.py +++ b/tests/test_schedule.py @@ -1,7 +1,6 @@ from datetime import datetime as dt, date, time from PyQt5 import QtCore -from vorta.views.schedule_tab import ScheduleTab def test_schedule_tab(app, qtbot): main = app.main_window diff --git a/tests/test_snapshots.py b/tests/test_snapshots.py new file mode 100644 index 00000000..3dea5c3c --- /dev/null +++ b/tests/test_snapshots.py @@ -0,0 +1,41 @@ +import io +import pytest +from PyQt5 import QtCore + +from vorta.models import BackupProfileModel, SnapshotModel +import vorta.borg + + +def test_prune_intervals(app, qtbot): + prune_intervals = ['hour', 'day', 'week', 'month', 'year'] + main = app.main_window + tab = main.snapshotTab + profile = BackupProfileModel.get(id=1) + + for i in prune_intervals: + getattr(tab, f'prune_{i}').setValue(9) + tab.save_prune_setting(None) + profile = profile.refresh() + assert getattr(profile, f'prune_{i}') == 9 + + +def test_repo_list(app_with_repo, qtbot, mocker, borg_json_output): + main = app_with_repo.main_window + tab = main.snapshotTab + main.tabWidget.setCurrentIndex(3) + tab.list_action() + assert not tab.checkButton.isEnabled() + + stdout, stderr = borg_json_output('list') + popen_result =mocker.MagicMock(stdout=stdout, + stderr=stderr, + returncode=0) + mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result) + + with qtbot.waitSignal(app_with_repo.backup_finished_event, timeout=3000) as blocker: + pass + + assert SnapshotModel.select().count() == 6 + assert main.createProgressText.text() == 'Refreshing snapshots done.' + assert tab.checkButton.isEnabled() +