Skip to content

Commit a1dd1aa

Browse files
committed
Add test case for custom lookup field scenario
1 parent 4c19c12 commit a1dd1aa

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

examples/simple/settings/testing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'search_indexes.documents.address': 'test_address',
1818
'search_indexes.documents.author': 'test_author',
1919
'search_indexes.documents.book': 'test_book',
20+
'search_indexes.documents.tag': 'test_tag',
2021
'search_indexes.documents.city': 'test_city',
2122
'search_indexes.documents.publisher': 'test_publisher',
2223
'search_indexes.documents.location': 'test_location',

src/django_elasticsearch_dsl_drf/tests/test_views.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TestViews(BaseRestFrameworkTestCase):
4242
def setUpClass(cls):
4343
"""Set up class."""
4444
cls.books = factories.BookWithoutTagsAndOrdersFactory.create_batch(20)
45+
cls.tags = factories.TagGenreFactory.create_batch(20)
4546

4647
call_command('search_index', '--rebuild', '-f')
4748

@@ -70,6 +71,16 @@ def test_detail_view(self):
7071
getattr(__obj, __field)
7172
)
7273

74+
def test_detail_view_with_custom_lookup(self):
75+
"""Test detail view with a custom lookup field."""
76+
__obj = self.tags[0]
77+
url = reverse('tagdocument-detail', kwargs={'title': __obj.title})
78+
data = {}
79+
80+
response = self.client.get(url, data)
81+
self.assertEqual(response.status_code, status.HTTP_200_OK)
82+
self.assertEqual(response.data['id'], __obj.title)
83+
7384

7485
if __name__ == '__main__':
7586
unittest.main()

0 commit comments

Comments
 (0)