How to use the richie.apps.search.forms.ItemSearchForm function in richie

To help you get started, we’ve selected a few richie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openfun / richie / tests / apps / search / test_forms_search_items.py View on Github external
def test_forms_items_limit_greater_than_1(self, *_):
        """The `limit` param should be greater than 1."""
        form = ItemSearchForm(data=QueryDict(query_string="limit=0"))
        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors, {"limit": ["Ensure this value is greater than or equal to 1."]}
        )
github openfun / richie / tests / apps / search / test_forms_search_items.py View on Github external
def test_forms_items_offset_greater_than_0(self, *_):
        """The `offset` param should be greater than 0."""
        form = ItemSearchForm(data=QueryDict(query_string="offset=-1"))
        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors,
            {"offset": ["Ensure this value is greater than or equal to 0."]},
        )
github openfun / richie / tests / apps / search / test_forms_search_items.py View on Github external
def test_forms_items_params_not_required(self, *_):
        """No params are required for the search form."""
        form = ItemSearchForm()
        self.assertTrue(form.is_valid())
github openfun / richie / tests / apps / search / test_forms_search_items.py View on Github external
def test_forms_items_limit_integer(self, *_):
        """The `limit` param should be an integer."""
        form = ItemSearchForm(data=QueryDict(query_string="limit=a"))
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors, {"limit": ["Enter a whole number."]})

        form = ItemSearchForm(data=QueryDict(query_string="limit=1"))
        self.assertTrue(form.is_valid())
github openfun / richie / tests / apps / search / test_forms_search_items.py View on Github external
def test_forms_items_offset_integer(self, *_):
        """The `offset` param should be an integer."""
        form = ItemSearchForm(data=QueryDict(query_string="offset=a"))
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors, {"offset": ["Enter a whole number."]})

        form = ItemSearchForm(data=QueryDict(query_string="offset=1"))
        self.assertTrue(form.is_valid())
github openfun / richie / tests / apps / search / test_forms_search_items.py View on Github external
def test_forms_items_offset_integer(self, *_):
        """The `offset` param should be an integer."""
        form = ItemSearchForm(data=QueryDict(query_string="offset=a"))
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors, {"offset": ["Enter a whole number."]})

        form = ItemSearchForm(data=QueryDict(query_string="offset=1"))
        self.assertTrue(form.is_valid())
github openfun / richie / tests / apps / search / test_forms_search_items.py View on Github external
def test_forms_items_single_values_in_querystring(self, *_):
        """
        The fields from filter definitions should be normalized as lists. The fields defined
        on the form should be single values (limit, offset and query).
        """
        form = ItemSearchForm(
            data=QueryDict(query_string=("limit=9&offset=3&query=maths"))
        )
        self.assertTrue(form.is_valid())
        self.assertEqual(
            form.cleaned_data, {"limit": 9, "offset": 3, "query": "maths", "scope": ""}
        )
github openfun / richie / tests / apps / search / test_forms_search_items.py View on Github external
def test_forms_items_empty_querystring(self, *_):
        """The empty query string should be a valid search form."""
        form = ItemSearchForm(data=QueryDict())
        self.assertTrue(form.is_valid())
        self.assertEqual(
            form.cleaned_data, {"limit": None, "offset": None, "query": "", "scope": ""}
        )
github openfun / richie / tests / apps / search / test_forms_search_items.py View on Github external
def test_forms_items_limit_integer(self, *_):
        """The `limit` param should be an integer."""
        form = ItemSearchForm(data=QueryDict(query_string="limit=a"))
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors, {"limit": ["Enter a whole number."]})

        form = ItemSearchForm(data=QueryDict(query_string="limit=1"))
        self.assertTrue(form.is_valid())
github openfun / richie / tests / apps / search / test_forms_search_items.py View on Github external
def test_forms_items_build_es_query_by_match_text_with_kind(self, *_):
        """
        Make sure the generated query filters the items by kind when one is provided
        as argument.
        """
        form = ItemSearchForm(
            data=QueryDict(query_string="limit=20&offset=2&query=some%20phrase%20terms")
        )
        self.assertTrue(form.is_valid())
        self.assertEqual(
            form.build_es_query(kind="subjects"),
            (
                20,
                2,
                {
                    "query": {
                        "bool": {
                            "must": [
                                {"term": {"kind": "subjects"}},
                                {
                                    "multi_match": {
                                        "analyzer": "english",