Skip to content

Commit db318d4

Browse files
author
alenkadev
committed
refactor: update edx-notes OAuth2 client creation logic for improved test environment handling
1 parent 4eb0964 commit db318d4

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

conftest.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# avoid duplicating the implementation
1212

1313
from cms.conftest import _django_clear_site_cache, pytest_configure # pylint: disable=unused-import
14-
from oauth2_provider.models import Application
1514

1615

1716
# When using self.assertEquals, diffs are truncated. We don't want that, always
@@ -20,13 +19,19 @@
2019

2120

2221
@pytest.fixture(autouse=True)
23-
def create_edxnotes_oauth_client(db):
24-
"""
25-
Automatically create the edx-notes OAuth2 Application for tests when
26-
ENABLE_EDXNOTES is enabled.
27-
"""
28-
if settings.FEATURES.get('ENABLE_EDXNOTES', False):
29-
from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory
30-
31-
if not Application.objects.filter(name=settings.EDXNOTES_CLIENT_NAME).exists():
32-
ApplicationFactory(name=settings.EDXNOTES_CLIENT_NAME)
22+
def create_edxnotes_oauth_client(django_db_blocker):
23+
"""
24+
Create the edx-notes OAuth2 Application only when notes settings are
25+
available and enabled for the current test environment.
26+
"""
27+
features = getattr(settings, 'FEATURES', {})
28+
client_name = getattr(settings, 'EDXNOTES_CLIENT_NAME', None)
29+
if not features.get('ENABLE_EDXNOTES', False) or not client_name:
30+
return
31+
32+
with django_db_blocker.unblock():
33+
from oauth2_provider.models import Application
34+
from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory
35+
36+
if not Application.objects.filter(name=client_name).exists():
37+
ApplicationFactory(name=client_name)

0 commit comments

Comments
 (0)