1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-23 08:17:08 +00:00
vorta/tests/conftest.py

63 lines
1.6 KiB
Python
Raw Normal View History

2018-11-01 06:01:44 +00:00
import pytest
import peewee
import sys
from datetime import datetime as dt
2018-11-01 06:01:44 +00:00
import vorta
from vorta.application import VortaApp
from vorta.models import RepoModel, SourceFileModel, ArchiveModel, BackupProfileModel
2018-11-01 06:01:44 +00:00
def pytest_configure(config):
sys._called_from_test = True
@pytest.fixture
def app(tmpdir, qtbot, mocker):
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)
mocker.patch.object(vorta.application.VortaApp, 'set_borg_details_action', return_value=None)
2018-11-06 06:47:04 +00:00
new_repo = RepoModel(url='i0fi93@i593.repo.borgbase.com:repo')
new_repo.save()
profile = BackupProfileModel.get(id=1)
profile.repo = new_repo.id
2018-11-06 06:47:04 +00:00
profile.save()
test_archive = ArchiveModel(snapshot_id='99999', name='test-archive', time=dt(2000, 1, 1, 0, 0), repo=1)
test_archive.save()
source_dir = SourceFileModel(dir='/tmp/another', repo=new_repo)
2018-11-06 06:47:04 +00:00
source_dir.save()
app = VortaApp([])
app.open_main_window_action()
qtbot.addWidget(app.main_window)
2018-11-06 06:47:04 +00:00
return app
@pytest.fixture
def choose_file_dialog(*args):
class MockFileDialog:
def __init__(self, *args, **kwargs):
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):
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