Skip to content

Commit

Permalink
Test introspection returns correct suggestions url
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyZmeem committed Dec 7, 2023
1 parent 00d3dd1 commit af53102
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test_project/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
admin.site.unregister(User)


class ZaibatsuAdminSite(admin.AdminSite):
site_header = 'Zaibatsu Admin'
site_title = 'Zaibatsu Admin Portal'
index_title = 'Welcome to Zaibatsu Admin Portal'


zaibatsu_admin_site = ZaibatsuAdminSite(name='zaibatsu')


class AuthorField(StrField):
name = 'author'
model = Book
Expand Down Expand Up @@ -137,7 +146,6 @@ def get_fields(self, model):
return fields


@admin.register(User)
class CustomUserAdmin(DjangoQLSearchMixin, UserAdmin):
djangoql_schema = UserQLSchema
search_fields = ('username', 'first_name', 'last_name')
Expand All @@ -153,3 +161,7 @@ def get_queryset(self, request):
return qs.\
annotate(groups_count=Count('groups')).\
prefetch_related('groups')


admin.site.register(User, CustomUserAdmin)
zaibatsu_admin_site.register(User, CustomUserAdmin)
10 changes: 10 additions & 0 deletions test_project/core/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ def test_introspections(self):
for model in ('core.book', 'auth.user', 'auth.group'):
self.assertIn(model, introspections['models'])

def test_introspection_suggestion_api_url(self):
self.assertTrue(self.client.login(**self.credentials))
for app in ['admin', 'zaibatsu']:
url = reverse('%s:auth_user_djangoql_introspect' % app)
introspections = self.get_json(url)
self.assertEqual(
reverse('%s:auth_user_djangoql_suggestions' % app),
introspections['suggestions_api_url'],
)

def test_djangoql_syntax_help(self):
url = reverse('admin:djangoql_syntax_help')
# unauthorized request should be redirected
Expand Down
2 changes: 2 additions & 0 deletions test_project/test_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
except ImportError: # Django < 2.0
from django.conf.urls import url as re_path

from core.admin import zaibatsu_admin_site
from core.views import completion_demo


urlpatterns = [
re_path(r'^admin/', admin.site.urls),
re_path(r'^zaibatsu-admin/', zaibatsu_admin_site.urls),
re_path(r'^$', completion_demo),
]

Expand Down

0 comments on commit af53102

Please sign in to comment.