changedetection.io/changedetectionio/tests/conftest.py

55 wiersze
1.4 KiB
Python
Czysty Zwykły widok Historia

2021-02-16 20:36:41 +00:00
#!/usr/bin/python3
import pytest
from changedetectionio import changedetection_app
from changedetectionio import store
2021-02-21 13:26:19 +00:00
import os
2021-02-16 20:36:41 +00:00
# https://github.com/pallets/flask/blob/1.1.2/examples/tutorial/tests/test_auth.py
# Much better boilerplate than the docs
# https://www.python-boilerplate.com/py3+flask+pytest/
2021-02-21 12:41:00 +00:00
global app
2021-02-16 20:36:41 +00:00
def cleanup(datastore_path):
# Unlink test output files
files = ['output.txt',
'url-watches.json',
'notification.txt',
'count.txt',
'endpoint-content.txt'
]
for file in files:
try:
os.unlink("{}/{}".format(datastore_path, file))
except FileNotFoundError:
pass
2021-02-16 20:36:41 +00:00
@pytest.fixture(scope='session')
def app(request):
"""Create application for the tests."""
datastore_path = "./test-datastore"
2021-02-21 12:41:00 +00:00
2021-02-21 13:08:34 +00:00
try:
os.mkdir(datastore_path)
except FileExistsError:
pass
cleanup(datastore_path)
2021-02-21 12:41:00 +00:00
2021-02-16 20:36:41 +00:00
app_config = {'datastore_path': datastore_path}
cleanup(app_config['datastore_path'])
2021-02-21 13:21:14 +00:00
datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], include_default_watches=False)
2021-02-21 12:41:00 +00:00
app = changedetection_app(app_config, datastore)
2021-03-01 13:29:21 +00:00
app.config['STOP_THREADS'] = True
2021-02-16 20:36:41 +00:00
def teardown():
2021-02-21 12:41:00 +00:00
datastore.stop_thread = True
2021-03-01 13:29:21 +00:00
app.config.exit.set()
cleanup(app_config['datastore_path'])
request.addfinalizer(teardown)
2021-02-27 08:05:25 +00:00
yield app