Skip to content

Commit

Permalink
refactor: add "fixtures" fixture to reuse in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
afuetterer committed Nov 15, 2023
1 parent 9eb6ea4 commit 7aa821f
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,33 @@
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):
def django_db_setup(django_db_setup, django_db_blocker, fixtures):
"""Populate database with test data from fixtures directories."""
with django_db_blocker.unblock():
fixtures = []
for fixture_dir in settings.FIXTURE_DIRS:
for file in Path(fixture_dir).iterdir():
if file.stem in [
'accounts',
'conditions',
'domain',
'groups',
'options',
'overlays',
'projects',
'questions',
'sites',
'tasks',
'users',
'views'
]:
fixtures.append(file)

call_command('loaddata', *fixtures)
set_group_permissions()

Expand All @@ -49,7 +53,4 @@ def files(settings, tmp_path):
@pytest.fixture
def json_data():
json_file = Path(settings.BASE_DIR) / 'import' / 'catalogs.json'
json_data = {
'elements': json.loads(json_file.read_text())
}
return json_data
return {'elements': json.loads(json_file.read_text())}

0 comments on commit 7aa821f

Please sign in to comment.