2021-02-16 20:36:41 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import pytest
|
2021-08-16 13:24:37 +00:00
|
|
|
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
|
|
|
|
2021-07-21 02:49:32 +00:00
|
|
|
|
|
|
|
def cleanup(datastore_path):
|
|
|
|
# Unlink test output files
|
|
|
|
files = ['output.txt',
|
|
|
|
'url-watches.json',
|
|
|
|
'notification.txt',
|
|
|
|
'count.txt',
|
2022-01-02 21:28:34 +00:00
|
|
|
'endpoint-content.txt'
|
|
|
|
]
|
2021-07-21 02:49:32 +00:00
|
|
|
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
|
|
|
|
|
2021-07-21 02:49:32 +00:00
|
|
|
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}
|
2021-08-12 10:05:59 +00:00
|
|
|
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()
|
2021-08-12 10:05:59 +00:00
|
|
|
cleanup(app_config['datastore_path'])
|
|
|
|
|
|
|
|
|
2021-02-26 19:07:26 +00:00
|
|
|
request.addfinalizer(teardown)
|
2021-02-27 08:05:25 +00:00
|
|
|
yield app
|