2018-11-01 06:01:44 +00:00
|
|
|
import pytest
|
|
|
|
import peewee
|
2018-11-30 00:40:18 +00:00
|
|
|
import sys
|
|
|
|
from datetime import datetime as dt
|
2018-11-01 06:01:44 +00:00
|
|
|
|
|
|
|
import vorta
|
|
|
|
from vorta.application import VortaApp
|
2018-12-05 09:05:47 +00:00
|
|
|
from vorta.models import RepoModel, SourceFileModel, ArchiveModel, BackupProfileModel
|
2018-11-01 06:01:44 +00:00
|
|
|
|
2018-11-05 10:30:59 +00:00
|
|
|
|
2018-11-27 11:33:16 +00:00
|
|
|
def pytest_configure(config):
|
|
|
|
sys._called_from_test = True
|
|
|
|
|
|
|
|
|
2018-11-30 00:40:18 +00:00
|
|
|
@pytest.fixture
|
2018-11-06 06:47:04 +00:00
|
|
|
def app(tmpdir, qtbot):
|
2018-11-01 06:01:44 +00:00
|
|
|
tmp_db = tmpdir.join('settings.sqlite')
|
|
|
|
mock_db = peewee.SqliteDatabase(str(tmp_db))
|
|
|
|
vorta.models.init_db(mock_db)
|
2018-11-06 06:47:04 +00:00
|
|
|
|
|
|
|
new_repo = RepoModel(url='i0fi93@i593.repo.borgbase.com:repo')
|
|
|
|
new_repo.save()
|
2018-11-30 00:40:18 +00:00
|
|
|
|
|
|
|
profile = BackupProfileModel.get(id=1)
|
|
|
|
profile.repo = new_repo.id
|
2018-11-06 06:47:04 +00:00
|
|
|
profile.save()
|
|
|
|
|
2018-11-30 00:40:18 +00:00
|
|
|
test_archive = ArchiveModel(snapshot_id='99999', name='test-archive', time=dt(2000, 1, 1, 0, 0), repo=1)
|
|
|
|
test_archive.save()
|
|
|
|
|
2018-12-05 09:05:47 +00:00
|
|
|
source_dir = SourceFileModel(dir='/tmp/another', repo=new_repo)
|
2018-11-06 06:47:04 +00:00
|
|
|
source_dir.save()
|
2018-11-30 00:40:18 +00:00
|
|
|
|
|
|
|
app = VortaApp([])
|
2018-12-04 02:58:12 +00:00
|
|
|
app.main_window.show()
|
2018-11-30 00:40:18 +00:00
|
|
|
qtbot.addWidget(app.main_window)
|
2018-11-06 06:47:04 +00:00
|
|
|
return app
|
|
|
|
|
2018-11-22 00:43:37 +00:00
|
|
|
|
2018-11-30 00:40:18 +00:00
|
|
|
@pytest.fixture
|
2018-12-05 09:05:47 +00:00
|
|
|
def choose_file_dialog(*args):
|
2018-11-30 00:40:18 +00:00
|
|
|
class MockFileDialog:
|
2018-12-04 02:58:12 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2018-11-30 00:40:18 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
def open(self, func):
|
|
|
|
func()
|
|
|
|
|
|
|
|
def selectedFiles(self):
|
|
|
|
return ['/tmp']
|
|
|
|
|
|
|
|
return MockFileDialog
|
|
|
|
|
|
|
|
|
2018-11-06 06:47:04 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def borg_json_output():
|
|
|
|
def _read_json(subcommand):
|
2018-11-27 11:33:16 +00:00
|
|
|
stdout = open(f'tests/borg_json_output/{subcommand}_stdout.json')
|
|
|
|
stderr = open(f'tests/borg_json_output/{subcommand}_stderr.json')
|
|
|
|
return stdout, stderr
|
2018-11-06 06:47:04 +00:00
|
|
|
return _read_json
|