Skip to content

Commit

Permalink
Used a separate admin site for autocomplete tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Dec 2, 2017
1 parent cf12257 commit 474bd7a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/admin_views/test_autocomplete_view.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -39,7 +39,7 @@ class BookAdmin(admin.ModelAdmin):
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):
Expand Down Expand Up @@ -156,12 +156,12 @@ def setUp(self):
self.superuser = User.objects.create_superuser(
username='super', password='secret', email='[email protected]',
)
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')
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_select(self):
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')
Expand Down
2 changes: 2 additions & 0 deletions tests/admin_views/urls.py
Original file line number Diff line number Diff line change
@@ -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')),
Expand All @@ -15,4 +16,5 @@
# 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),
]

0 comments on commit 474bd7a

Please sign in to comment.