2022-08-14 19:20:15 +02:00
|
|
|
"""
|
|
|
|
Special pytest init:
|
|
|
|
|
|
|
|
- Build a "local_test" YunoHost installation
|
|
|
|
- init Django with this local test installation
|
|
|
|
|
|
|
|
So the pytests will run against this local test installation
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import django
|
2023-08-20 17:18:17 +02:00
|
|
|
from django_yunohost_integration.local_test import CreateResults, create_local_test
|
2022-08-14 19:20:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
BASE_PATH = Path(__file__).parent.parent
|
|
|
|
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_configure():
|
|
|
|
print('Compile YunoHost files...')
|
2023-08-20 17:18:17 +02:00
|
|
|
result: CreateResults = create_local_test(
|
2022-08-14 19:20:15 +02:00
|
|
|
django_settings_path=BASE_PATH / 'conf' / 'settings.py',
|
|
|
|
destination=BASE_PATH / 'local_test',
|
|
|
|
runserver=False,
|
2022-08-14 19:30:06 +02:00
|
|
|
extra_replacements={
|
2023-08-20 17:18:17 +02:00
|
|
|
'__DEBUG_ENABLED__': 'NO', # "YES" or "NO" string
|
2022-08-15 09:17:30 +02:00
|
|
|
'__LOG_LEVEL__': 'INFO',
|
|
|
|
'__ADMIN_EMAIL__': 'foo-bar@test.tld',
|
2022-08-15 09:46:03 +02:00
|
|
|
'__DEFAULT_FROM_EMAIL__': 'django_app@test.tld',
|
2022-08-14 19:30:06 +02:00
|
|
|
},
|
2022-08-14 19:20:15 +02:00
|
|
|
)
|
2023-08-20 17:18:17 +02:00
|
|
|
print('Local test files created:')
|
|
|
|
print(result)
|
2022-08-14 19:20:15 +02:00
|
|
|
|
2023-08-20 17:18:17 +02:00
|
|
|
os.chdir(result.data_dir_path)
|
|
|
|
data_dir = str(result.data_dir_path)
|
|
|
|
if data_dir not in sys.path:
|
|
|
|
sys.path.insert(0, data_dir)
|
2022-08-14 19:20:15 +02:00
|
|
|
|
|
|
|
django.setup()
|