-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
041453e
commit 89fad11
Showing
4 changed files
with
50 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
course_discovery/apps/course_metadata/tests/management/test_mixins.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from unittest.mock import patch | ||
|
||
from course_discovery.apps.core.tests.mixins import ElasticsearchTestMixin | ||
from django.test import TestCase | ||
from course_discovery.apps.course_metadata.tests import factories | ||
from course_discovery.apps.course_metadata.search_indexes.documents import CourseDocument | ||
|
||
|
||
class TestSearchAfterMixin(ElasticsearchTestMixin, TestCase): | ||
""" | ||
Unit tests for SearchAfterMixin. | ||
Uses a proxy model `CourseProxy` that extends this mixin so we can replicate the behavior for Courses. | ||
""" | ||
def setUp(self): | ||
super().setUp() | ||
|
||
self.total_courses = 5 | ||
factories.CourseFactory.create_batch(self.total_courses) | ||
|
||
@patch("course_discovery.apps.course_metadata.models.registry.get_documents") | ||
def test_fetch_all_courses(self, mock_get_documents): | ||
query = 'Course*' | ||
mock_get_documents.return_value = [CourseDocument] | ||
|
||
queryset = factories.CourseProxy.search(query=query, page_size=2) | ||
|
||
unique_items = set(queryset) | ||
self.assertEqual(len(queryset), len(unique_items), 'Queryset contains duplicate entries.') | ||
self.assertEqual(len(queryset), self.total_courses) | ||
|
||
def test_wildcard_query_early_exit(self): | ||
""" | ||
Test the early exit optimization when the query is `(*)`. | ||
""" | ||
query = '*' | ||
|
||
queryset = factories.CourseProxy.search(query=query) | ||
|
||
self.assertEqual(len(queryset), self.total_courses) | ||
self.assertQuerysetEqual( | ||
queryset.order_by("id"), | ||
factories.Course.objects.all().order_by("id"), | ||
transform=lambda x: x | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters