changedetection.io/backend/tests/conftest.py

44 wiersze
1019 B
Python
Czysty Zwykły widok Historia

2021-02-16 20:36:41 +00:00
#!/usr/bin/python3
import pytest
from backend import changedetection_app
from backend 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
2021-02-21 13:08:34 +00:00
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
2021-02-21 12:41:00 +00:00
try:
os.unlink("{}/url-watches.json".format(datastore_path))
except FileNotFoundError:
pass
2021-02-16 20:36:41 +00:00
app_config = {'datastore_path': 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-02-16 20:36:41 +00:00
def teardown():
2021-02-21 12:41:00 +00:00
datastore.stop_thread = True
2021-02-21 13:26:19 +00:00
app.config['STOP_THREADS'] = True
2021-02-16 20:36:41 +00:00
request.addfinalizer(teardown)
2021-02-16 20:42:26 +00:00
2021-02-21 13:26:19 +00:00
return app