def test_filter_with_all_keys_allowed(self): filtering = {'foo': 'bar', 'fu': 'bá'} allowed_filters = ['foo', 'fu'] filter_processor = DynamicModelFilterProcessor(filtering, allowed_filters) self.assertEquals(filter_processor.filters, filtering)
def test_filter_with_all_keys_allowed(self): filtering = {"foo": "bar", "fu": "bá"} allowed_filters = ["foo", "fu"] filter_processor = DynamicModelFilterProcessor(filtering, allowed_filters) self.assertEqual(filter_processor.filters, filtering)
def test_clean_string_None_to_isnull(self): filtering = {"foo": "bar", "fu": "bá", "none": "None"} allowed_filters = ["foo", "fu", "none"] filter_processor = DynamicModelFilterProcessor(filtering, allowed_filters) expected = {"foo": "bar", "fu": "bá", "none__isnull": True} self.assertEqual(filter_processor.filters, expected)
def test_clean_bool_lowercase_values(self): filtering = {"foo": "true", "fu": "false"} allowed_filters = ["foo", "fu"] filter_processor = DynamicModelFilterProcessor(filtering, allowed_filters) expected = {"foo": True, "fu": False} self.assertEqual(filter_processor.filters, expected)
def test_remove_None_filter(self): filtering = {"foo": "bar", "fu": None} allowed_filters = ["foo", "fu"] filter_processor = DynamicModelFilterProcessor(filtering, allowed_filters) expected = {"foo": "bar"} self.assertEqual(filter_processor.filters, expected)
def test_clean_string_None_to_isnull(self): filtering = {'foo': 'bar', 'fu': 'bá', 'none': 'None'} allowed_filters = ['foo', 'fu', 'none'] filter_processor = DynamicModelFilterProcessor(filtering, allowed_filters) expected = {'foo': 'bar', 'fu': 'bá', 'none__isnull': True} self.assertEquals(filter_processor.filters, expected)
def test_clean_bool_lowercase_values(self): filtering = {'foo': 'true', 'fu': 'false'} allowed_filters = ['foo', 'fu'] filter_processor = DynamicModelFilterProcessor(filtering, allowed_filters) expected = {'foo': True, 'fu': False} self.assertEquals(filter_processor.filters, expected)
def test_remove_None_filter(self): filtering = {'foo': 'bar', 'fu': None} allowed_filters = ['foo', 'fu'] filter_processor = DynamicModelFilterProcessor(filtering, allowed_filters) expected = {'foo': 'bar'} self.assertEquals(filter_processor.filters, expected)
def apply_filters(self, filtering): model_filtering = self.model.extra["filtering"] processor = DynamicModelFilterProcessor(filtering, model_filtering) return self.filter(**processor.filters)
def apply_filters(self, filtering): # TODO: filtering must be based on field's settings, not on models # settings. model_filtering = self.model.extra["filtering"] processor = DynamicModelFilterProcessor(filtering, model_filtering) return self.filter(**processor.filters)