You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
58 lines
1.5 KiB
4 years ago
|
#!/usr/bin/python3
|
||
|
|
||
|
import pytest
|
||
3 years ago
|
from changedetectionio import changedetection_app
|
||
|
from changedetectionio import store
|
||
4 years ago
|
import os
|
||
4 years ago
|
|
||
|
# 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/
|
||
|
|
||
4 years ago
|
global app
|
||
4 years ago
|
|
||
3 years ago
|
|
||
|
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))
|
||
|
x = 1
|
||
|
except FileNotFoundError:
|
||
|
pass
|
||
|
|
||
4 years ago
|
@pytest.fixture(scope='session')
|
||
|
def app(request):
|
||
|
"""Create application for the tests."""
|
||
|
datastore_path = "./test-datastore"
|
||
4 years ago
|
|
||
4 years ago
|
try:
|
||
|
os.mkdir(datastore_path)
|
||
|
except FileExistsError:
|
||
|
pass
|
||
|
|
||
3 years ago
|
# Enable a BASE_URL for notifications to work (so we can look for diff/ etc URLs)
|
||
|
os.environ["BASE_URL"] = "http://mysite.com/"
|
||
3 years ago
|
cleanup(datastore_path)
|
||
4 years ago
|
|
||
3 years ago
|
|
||
4 years ago
|
app_config = {'datastore_path': datastore_path}
|
||
3 years ago
|
cleanup(app_config['datastore_path'])
|
||
4 years ago
|
datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], include_default_watches=False)
|
||
4 years ago
|
app = changedetection_app(app_config, datastore)
|
||
4 years ago
|
app.config['STOP_THREADS'] = True
|
||
4 years ago
|
|
||
|
def teardown():
|
||
4 years ago
|
datastore.stop_thread = True
|
||
4 years ago
|
app.config.exit.set()
|
||
3 years ago
|
cleanup(app_config['datastore_path'])
|
||
|
|
||
|
|
||
4 years ago
|
request.addfinalizer(teardown)
|
||
4 years ago
|
yield app
|