From 474bd7a5d4b0b47eeedc03ad471ae9e630e95258 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 1 Dec 2017 14:43:40 -0500 Subject: [PATCH] Used a separate admin site for autocomplete tests. --- tests/admin_views/test_autocomplete_view.py | 10 +++++----- tests/admin_views/urls.py | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/admin_views/test_autocomplete_view.py b/tests/admin_views/test_autocomplete_view.py index 8396ceb5d1d..b8c12448e12 100644 --- a/tests/admin_views/test_autocomplete_view.py +++ b/tests/admin_views/test_autocomplete_view.py @@ -1,7 +1,6 @@ import json from django.contrib import admin -from django.contrib.admin import site from django.contrib.admin.tests import AdminSeleniumTestCase from django.contrib.admin.views.autocomplete import AutocompleteJsonView from django.contrib.auth.models import Permission, User @@ -30,6 +29,7 @@ class BookAdmin(admin.ModelAdmin): inlines = [AuthorshipInline] +site = admin.AdminSite(name='autocomplete_admin') site.register(Question, QuestionAdmin) site.register(Answer, AnswerAdmin) site.register(Author, AuthorAdmin) @@ -39,7 +39,7 @@ site.register(Book, BookAdmin) class AutocompleteJsonViewTests(AdminViewBasicTestCase): as_view_args = {'model_admin': QuestionAdmin(Question, site)} factory = RequestFactory() - url = reverse_lazy('admin:admin_views_question_autocomplete') + url = reverse_lazy('autocomplete_admin:admin_views_question_autocomplete') @classmethod def setUpTestData(cls): @@ -156,12 +156,12 @@ class SeleniumTests(AdminSeleniumTestCase): self.superuser = User.objects.create_superuser( username='super', password='secret', email='super@example.com', ) - self.admin_login(username='super', password='secret', login_url=reverse('admin:index')) + self.admin_login(username='super', password='secret', login_url=reverse('autocomplete_admin:index')) def test_select(self): from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select - self.selenium.get(self.live_server_url + reverse('admin:admin_views_answer_add')) + self.selenium.get(self.live_server_url + reverse('autocomplete_admin:admin_views_answer_add')) elem = self.selenium.find_element_by_css_selector('.select2-selection') elem.click() # Open the autocomplete dropdown. results = self.selenium.find_element_by_css_selector('.select2-results') @@ -196,7 +196,7 @@ class SeleniumTests(AdminSeleniumTestCase): def test_select_multiple(self): from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select - self.selenium.get(self.live_server_url + reverse('admin:admin_views_question_add')) + self.selenium.get(self.live_server_url + reverse('autocomplete_admin:admin_views_question_add')) elem = self.selenium.find_element_by_css_selector('.select2-selection') elem.click() # Open the autocomplete dropdown. results = self.selenium.find_element_by_css_selector('.select2-results') diff --git a/tests/admin_views/urls.py b/tests/admin_views/urls.py index d0a671dc004..9f8bdf5cba7 100644 --- a/tests/admin_views/urls.py +++ b/tests/admin_views/urls.py @@ -1,6 +1,7 @@ from django.conf.urls import include, url from . import admin, custom_has_permission_admin, customadmin, views +from .test_autocomplete_view import site as autocomplete_site urlpatterns = [ url(r'^test_admin/admin/doc/', include('django.contrib.admindocs.urls')), @@ -15,4 +16,5 @@ urlpatterns = [ # All admin views accept `extra_context` to allow adding it like this: url(r'^test_admin/admin8/', (admin.site.get_urls(), 'admin', 'admin-extra-context'), {'extra_context': {}}), url(r'^test_admin/has_permission_admin/', custom_has_permission_admin.site.urls), + url(r'^test_admin/autocomplete_admin/', autocomplete_site.urls), ]