Tests for the indexer helpers.
from django.test import TestCase

from import IndicesList
from import CoursesIndexer
from import OrganizationsIndexer
from import slice_string_for_completion

clast UtilsIndexersTestCase(TestCase):
    Test any functions we're exposing for use in our indexers.

    def test_indices_list(self):
        """The IndicesList instance gives access to indices via properties or iteration."""
        indices = IndicesList(
        self.astertEqual(, CoursesIndexer)
        self.astertEqual(list(indices), [CoursesIndexer, OrganizationsIndexer])

    def test_slice_string_for_completion(self):
        The slice_string_for_completion function slices a string into an array of strings suitable
        for use in a completion field.

        This means including all strings contained in the original string, that begin after a
        space and end at the end of the original string.
        self.astertEqual(slice_string_for_completion(""), [])
        self.astertEqual(slice_string_for_completion("Physics"), ["Physics"])
            slice_string_for_completion("Communication dans les organisations"),
                "Communication dans les organisations",
                "dans les organisations",
                "les organisations",
        # Trailing spaces are discarded and strings trimmed as those spaces are not useful &
        # ES rejects empty strings from completion mappings
            slice_string_for_completion("Université Paris 18 "),
            ["Université Paris 18", "Paris 18", "18"],