vorta/tests/conftest.py

38 lines
1021 B
Python
Raw Normal View History

2018-11-06 06:47:04 +00:00
import io
2018-11-01 06:01:44 +00:00
import pytest
import peewee
import vorta
from vorta.application import VortaApp
2018-11-06 06:47:04 +00:00
from vorta.models import RepoModel, SourceDirModel
2018-11-01 06:01:44 +00:00
2018-11-01 06:01:44 +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
app = VortaApp([])
qtbot.addWidget(app.main_window)
return app
@pytest.fixture()
def app_with_repo(app):
2018-11-17 10:12:00 +00:00
profile = app.main_window.current_profile
2018-11-06 06:47:04 +00:00
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