-
Notifications
You must be signed in to change notification settings - Fork 49
/
conftest.py
56 lines (45 loc) · 1.56 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
import shutil
from pathlib import Path
import pytest
from django.conf import settings
from django.core.management import call_command
from rdmo.accounts.utils import set_group_permissions
@pytest.fixture(scope="session")
def fixtures():
allowed_file_stems = {
'accounts',
'conditions',
'domain',
'groups',
'options',
'overlays',
'projects',
'questions',
'sites',
'tasks',
'users',
'views'
}
fixtures = []
for fixture_dir in settings.FIXTURE_DIRS:
filenames = [filename for filename in Path(fixture_dir).iterdir() if filename.stem in allowed_file_stems]
fixtures.extend(filenames)
return fixtures
@pytest.fixture(scope='session')
def django_db_setup(django_db_setup, django_db_blocker, fixtures): # noqa: PT004 - pytest-django requires this name "django_db_setup"
"""Populate database with test data from fixtures directories."""
with django_db_blocker.unblock():
call_command('loaddata', *fixtures)
set_group_permissions()
@pytest.fixture
def files(settings, tmp_path):
"""Create a temporary MEDIA_ROOT directory and copy test data into it."""
media_path = Path(__file__).parent.joinpath("testing").joinpath("media")
settings.MEDIA_ROOT = tmp_path.joinpath("media")
shutil.copytree(media_path, settings.MEDIA_ROOT)
return settings.MEDIA_ROOT
@pytest.fixture
def json_data():
json_file = Path(settings.BASE_DIR) / 'import' / 'catalogs.json'
return {'elements': json.loads(json_file.read_text())}