|
11 | 11 | # avoid duplicating the implementation |
12 | 12 |
|
13 | 13 | from cms.conftest import _django_clear_site_cache, pytest_configure # pylint: disable=unused-import |
14 | | -from oauth2_provider.models import Application |
15 | 14 |
|
16 | 15 |
|
17 | 16 | # When using self.assertEquals, diffs are truncated. We don't want that, always |
|
20 | 19 |
|
21 | 20 |
|
22 | 21 | @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