def test_related_field_ajax_list_filter(self):
        request = self.factory.get('url')
        field, lookup_params, model, model_admin, field_path = self.get_related_field_ajax_list_filter_params()
        list_filter = RelatedFieldAjaxListFilter(field, request, lookup_params, model, model_admin, field_path)

        self.assertTrue(list_filter.has_output())

        choices = list_filter.field_choices(field, request, model_admin)

        self.assertIsInstance(choices, list)
        self.assertEqual(len(choices), 0)
Example #2
0
    def test_related_field_ajax_list_filter(self):
        request = self.factory.get('url')
        field, lookup_params, model, model_admin, field_path = self.get_related_field_ajax_list_filter_params()
        list_filter = RelatedFieldAjaxListFilter(field, request, lookup_params, model, model_admin, field_path)

        self.assertTrue(list_filter.has_output())

        choices = list_filter.field_choices(field, request, model_admin)

        self.assertIsInstance(choices, list)
        self.assertEqual(len(choices), 0)
    def test_related_field_ajax_list_filter_with_initial(self):
        initial = self.models[1]
        request = self.factory.get('url', {'field__id__exact': initial.pk})
        field, lookup_params, model, model_admin, field_path = self.get_related_field_ajax_list_filter_params()
        list_filter = RelatedFieldAjaxListFilter(field, request, lookup_params, model, model_admin, field_path)

        self.assertTrue(list_filter.has_output())

        choices = list_filter.field_choices(field, request, model_admin)

        self.assertIsInstance(choices, list)
        self.assertEqual(len(choices), 1)
        self.assertEqual(choices[0], (initial.pk, smart_text(initial)))
Example #4
0
    def test_related_field_ajax_list_filter_with_initial(self):
        initial = self.models[1]
        request = self.factory.get('url', {'field__id__exact': initial.pk})
        field, lookup_params, model, model_admin, field_path = self.get_related_field_ajax_list_filter_params_with_initial()
        list_filter = RelatedFieldAjaxListFilter(field, request, lookup_params, model, model_admin, field_path)

        self.assertTrue(list_filter.has_output())

        choices = list_filter.field_choices(field, request, model_admin)

        self.assertIsInstance(choices, list)
        self.assertEqual(len(choices), 1)
        self.assertEqual(choices[0], (initial.pk, smart_text(initial)))
Example #5
0
    def test_related_field_ajax_list_filter(self):
        request = self.factory.get('url')
        field, lookup_params, model, model_admin, field_path = self.get_related_field_ajax_list_filter_params()
        list_filter = RelatedFieldAjaxListFilter(field, request, lookup_params, model, model_admin, field_path)

        self.assertTrue(list_filter.has_output())

        field_choices = list_filter.field_choices(field, request, model_admin)

        self.assertEqual(field_choices, [
            (self.models[0].pk, smart_text(self.models[0])),
            (self.models[1].pk, smart_text(self.models[1])),
        ])

        # check choice selection
        choices = list(list_filter.choices(self.fake_change_list))
        choices[0]['display'] = str(choices[0]['display'])  # gettext_lazy()
        self.assertEqual(choices, [
            {'display': 'All', 'query_string': '', 'selected': True},
            {'display': 'first1', 'query_string': '', 'selected': False},
            {'display': 'second2', 'query_string': '', 'selected': False},
        ])