mirror of
https://github.com/django/django.git
synced 2025-10-25 22:56:12 +00:00
Refs #29138 -- Added extra tests for autocomplete FK to_field variations.
This commit is contained in:
committed by
Carlton Gibson
parent
ceb4b9ee68
commit
0b120f5d64
@@ -94,6 +94,30 @@ class AutocompleteJsonViewTests(AdminViewBasicTestCase):
|
||||
'pagination': {'more': False},
|
||||
})
|
||||
|
||||
def test_custom_to_field_permission_denied(self):
|
||||
Question.objects.create(question='Is this a question?')
|
||||
request = self.factory.get(self.url, {'term': 'is', **self.opts, 'field_name': 'question_with_to_field'})
|
||||
request.user = self.user
|
||||
with self.assertRaises(PermissionDenied):
|
||||
AutocompleteJsonView.as_view(**self.as_view_args)(request)
|
||||
|
||||
def test_custom_to_field_custom_pk(self):
|
||||
q = Question.objects.create(question='Is this a question?')
|
||||
opts = {
|
||||
'app_label': Question._meta.app_label,
|
||||
'model_name': Question._meta.model_name,
|
||||
'field_name': 'related_questions',
|
||||
}
|
||||
request = self.factory.get(self.url, {'term': 'is', **opts})
|
||||
request.user = self.superuser
|
||||
response = AutocompleteJsonView.as_view(**self.as_view_args)(request)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
self.assertEqual(data, {
|
||||
'results': [{'id': str(q.big_id), 'text': q.question}],
|
||||
'pagination': {'more': False},
|
||||
})
|
||||
|
||||
def test_field_does_not_exist(self):
|
||||
request = self.factory.get(self.url, {'term': 'is', **self.opts, 'field_name': 'does_not_exist'})
|
||||
request.user = self.superuser
|
||||
|
||||
Reference in New Issue
Block a user