Skip to content

Commit

Permalink
config error if urls loaded too early
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Jun 14, 2023
1 parent 031b082 commit b04f8f9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
django-version: [4.2.2]
drf-version: [3.14.0]
variant: ['']
backend: [threading, immediate, celery]
backend: [threading, immediate, celery, broken]
include:

# Alternate configurations
Expand Down Expand Up @@ -108,7 +108,14 @@ jobs:
python -c "import tests"
celery -A tests worker &
- name: Test with unittest
if: ${{ matrix.variant != 'broken' }}
run: python -m unittest discover -s tests -t . -v
- name: Test broken URL message
if: ${{ matrix.variant == 'broken' }}
run: |
set +e
python -m unittest discover -s tests -t . -v
test $? -eq 1
- name: Test build
run: python -m build
npm:
Expand Down
9 changes: 9 additions & 0 deletions data_wizard/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
from rest_framework import routers
from django.core.exceptions import ImproperlyConfigured
from .views import RunViewSet
from . import discovered


if not discovered:
raise ImproperlyConfigured(
"data_wizard.urls imported before data_wizard.autodiscover(). "
"Try moving data_wizard to an earlier position in INSTALLED_APPS."
)


router = routers.SimpleRouter()
Expand Down
28 changes: 20 additions & 8 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@
REVERSION_APPS = tuple()


if TEST_VARIANT == "broken":
APP_ORDER = (
"tests.data_app",
"tests.naturalkey_app",
"tests.eav_app",
"tests.source_app",
"data_wizard",
"data_wizard.sources",
)
else:
APP_ORDER = (
"tests.data_app",
"tests.naturalkey_app",
"tests.eav_app",
"data_wizard",
"data_wizard.sources",
"tests.source_app",
)

INSTALLED_APPS = (
(
"django.contrib.contenttypes",
Expand All @@ -57,14 +76,7 @@
)
+ WQ_APPS
+ REVERSION_APPS
+ (
"data_wizard",
"data_wizard.sources",
"tests.data_app",
"tests.naturalkey_app",
"tests.eav_app",
"tests.source_app",
)
+ APP_ORDER
)


Expand Down
8 changes: 8 additions & 0 deletions tests/source_app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig


class CustomURLConfig(AppConfig):
name = "tests.source_app"

def ready(self):
import tests.urls

0 comments on commit b04f8f9

Please sign in to comment.