mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Add safe=False to tags autocomplete view. Add tests
This commit is contained in:
parent
84a507715e
commit
26db43e85d
@ -1,7 +1,11 @@
|
||||
import json
|
||||
|
||||
from django.test import TestCase, override_settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core import mail
|
||||
|
||||
from taggit.models import Tag
|
||||
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
from wagtail.wagtailcore.models import Page
|
||||
from wagtail.wagtailadmin.utils import send_mail
|
||||
@ -112,3 +116,51 @@ class TestExplorerNavView(TestCase, WagtailTestUtils):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed('wagtailadmin/shared/explorer_nav.html')
|
||||
self.assertEqual(response.context['nodes'][0][0], self.homepage)
|
||||
|
||||
|
||||
class TestTagsAutocomplete(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
self.login()
|
||||
Tag.objects.create(name="Test", slug="test")
|
||||
|
||||
def test_tags_autocomplete(self):
|
||||
response = self.client.get(reverse('wagtailadmin_tag_autocomplete'), {
|
||||
'term': 'test'
|
||||
})
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response['Content-Type'], 'application/json')
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
|
||||
self.assertEqual(data, ['Test'])
|
||||
|
||||
def test_tags_autocomplete_partial_match(self):
|
||||
response = self.client.get(reverse('wagtailadmin_tag_autocomplete'), {
|
||||
'term': 'te'
|
||||
})
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response['Content-Type'], 'application/json')
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
|
||||
self.assertEqual(data, ['Test'])
|
||||
|
||||
def test_tags_autocomplete_different_term(self):
|
||||
response = self.client.get(reverse('wagtailadmin_tag_autocomplete'), {
|
||||
'term': 'hello'
|
||||
})
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response['Content-Type'], 'application/json')
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_tags_autocomplete_no_term(self):
|
||||
response = self.client.get(reverse('wagtailadmin_tag_autocomplete'))
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response['Content-Type'], 'application/json')
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
|
||||
self.assertEqual(data, [])
|
||||
|
@ -10,4 +10,4 @@ def autocomplete(request):
|
||||
else:
|
||||
tags = Tag.objects.none()
|
||||
|
||||
return JsonResponse([tag.name for tag in tags])
|
||||
return JsonResponse([tag.name for tag in tags], safe=False)
|
||||
|
Loading…
Reference in New Issue
Block a user