Skip to content

Commit

Permalink
[2.x] Remove some deprecations (#795)
Browse files Browse the repository at this point in the history
* Remove deprecation tests

* Remove 'Filter.name' deprecation

* Fixup 'Filter.field_name' in tests
  • Loading branch information
Ryan P Kilby authored and carltongibson committed Oct 24, 2017
1 parent af6cff8 commit dd4795c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 117 deletions.
15 changes: 0 additions & 15 deletions django_filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ class Filter(object):
def __init__(self, field_name=None, label=None, method=None, lookup_expr='exact',
distinct=False, exclude=False, **kwargs):
self.field_name = field_name
if field_name is None and 'name' in kwargs:
deprecate("`Filter.name` has been renamed to `Filter.field_name`.")
self.field_name = kwargs.pop('name')
self.label = label
self.method = method
self.lookup_expr = lookup_expr
Expand Down Expand Up @@ -132,18 +129,6 @@ def fset(self, value):
return locals()
method = property(**method())

def name():
def fget(self):
deprecate("`Filter.name` has been renamed to `Filter.field_name`.")
return self.field_name

def fset(self, value):
deprecate("`Filter.name` has been renamed to `Filter.field_name`.")
self.field_name = value

return locals()
name = property(**name())

def label():
def fget(self):
if self._label is None and hasattr(self, 'parent'):
Expand Down
2 changes: 1 addition & 1 deletion tests/rest_framework/test_filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_isodatetimefilter(self):
field = Article._meta.get_field('published')
result = FilterSet.filter_for_field(field, 'published')
self.assertIsInstance(result, filters.IsoDateTimeFilter)
self.assertEqual(result.name, 'published')
self.assertEqual(result.field_name, 'published')

def test_booleanfilter_widget(self):
field = User._meta.get_field('is_active')
Expand Down
54 changes: 0 additions & 54 deletions tests/test_deprecations.py

This file was deleted.

10 changes: 5 additions & 5 deletions tests/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ class Meta:
def test_filtering_with_multiple_lookup_exprs(self):

class F(FilterSet):
min_duration = DurationFilter(name='duration', lookup_expr='gte')
max_duration = DurationFilter(name='duration', lookup_expr='lte')
min_duration = DurationFilter(field_name='duration', lookup_expr='gte')
max_duration = DurationFilter(field_name='duration', lookup_expr='lte')

class Meta:
model = SpacewalkRecord
Expand Down Expand Up @@ -551,7 +551,7 @@ def users(request):
return User.objects.filter(pk__lt=request.user.pk)

class F(FilterSet):
author = ModelChoiceFilter(name='author', queryset=users)
author = ModelChoiceFilter(field_name='author', queryset=users)

class Meta:
model = Comment
Expand Down Expand Up @@ -907,7 +907,7 @@ def test_filtering(self):
Comment.objects.create(date=datetime.date(2016, 1, 3), **kwargs)

class F(FilterSet):
published = DateFromToRangeFilter(name='date')
published = DateFromToRangeFilter(field_name='date')

class Meta:
model = Comment
Expand Down Expand Up @@ -1886,7 +1886,7 @@ def setUp(self):

def test_filtering_with_declared_filters(self):
class F(FilterSet):
account = CharFilter(name='username')
account = CharFilter(field_name='username')

class Meta:
model = User
Expand Down
50 changes: 25 additions & 25 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_field_with_list_lookup_expr(self):
def test_field_params(self):
with mock.patch.object(Filter, 'field_class',
spec=['__call__']) as mocked:
f = Filter(name='somefield', label='somelabel',
f = Filter(field_name='somefield', label='somelabel',
widget='somewidget')
f.field
mocked.assert_called_once_with(required=False,
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_filtering_exclude(self):

def test_filtering_uses_name(self):
qs = mock.Mock(spec=['filter'])
f = Filter(name='somefield')
f = Filter(field_name='somefield')
f.filter(qs, 'value')
result = qs.filter.assert_called_once_with(somefield__exact='value')
self.assertNotEqual(qs, result)
Expand All @@ -180,22 +180,22 @@ def test_filtering_skipped_with_none_value(self):

def test_filtering_with_list_value(self):
qs = mock.Mock(spec=['filter'])
f = Filter(name='somefield', lookup_expr=['some_lookup_expr'])
f = Filter(field_name='somefield', lookup_expr=['some_lookup_expr'])
result = f.filter(qs, Lookup('value', 'some_lookup_expr'))
qs.filter.assert_called_once_with(somefield__some_lookup_expr='value')
self.assertNotEqual(qs, result)

def test_filtering_skipped_with_list_value_with_blank(self):
qs = mock.Mock()
f = Filter(name='somefield', lookup_expr=['some_lookup_expr'])
f = Filter(field_name='somefield', lookup_expr=['some_lookup_expr'])
result = f.filter(qs, Lookup('', 'some_lookup_expr'))
self.assertListEqual(qs.method_calls, [])
self.assertEqual(qs, result)

def test_filtering_skipped_with_list_value_with_blank_lookup(self):
return # Now field is required to provide valid lookup_expr if it provides any
qs = mock.Mock(spec=['filter'])
f = Filter(name='somefield', lookup_expr=None)
f = Filter(field_name='somefield', lookup_expr=None)
result = f.filter(qs, Lookup('value', ''))
qs.filter.assert_called_once_with(somefield__exact='value')
self.assertNotEqual(qs, result)
Expand All @@ -210,7 +210,7 @@ def test_filter_using_method(self):

def test_filtering_uses_distinct(self):
qs = mock.Mock(spec=['filter', 'distinct'])
f = Filter(name='somefield', distinct=True)
f = Filter(field_name='somefield', distinct=True)
f.filter(qs, 'value')
result = qs.distinct.assert_called_once_with()
self.assertNotEqual(qs, result)
Expand All @@ -231,13 +231,13 @@ def filter(self_, qs, value):

def test_lookup_false(self):
qs = mock.Mock(spec=['filter'])
f = self.test_filter_class(name='somefield')
f = self.test_filter_class(field_name='somefield')
result = f.filter(qs, Lookup('', 'exact'))
self.assertEqual(qs, result)

def test_lookup_true(self):
qs = mock.Mock(spec=['filter'])
f = self.test_filter_class(name='somefield')
f = self.test_filter_class(field_name='somefield')
result = f.filter(qs, Lookup('somesearch', 'exact'))
qs.filter.assert_called_once_with(somefield__exact='somesearch')
self.assertNotEqual(qs, result)
Expand Down Expand Up @@ -268,35 +268,35 @@ def test_default_field(self):

def test_filtering(self):
qs = mock.Mock(spec=['filter'])
f = BooleanFilter(name='somefield')
f = BooleanFilter(field_name='somefield')
result = f.filter(qs, True)
qs.filter.assert_called_once_with(somefield__exact=True)
self.assertNotEqual(qs, result)

def test_filtering_exclude(self):
qs = mock.Mock(spec=['exclude'])
f = BooleanFilter(name='somefield', exclude=True)
f = BooleanFilter(field_name='somefield', exclude=True)
result = f.filter(qs, True)
qs.exclude.assert_called_once_with(somefield__exact=True)
self.assertNotEqual(qs, result)

def test_filtering_skipped_with_blank_value(self):
qs = mock.Mock()
f = BooleanFilter(name='somefield')
f = BooleanFilter(field_name='somefield')
result = f.filter(qs, '')
self.assertListEqual(qs.method_calls, [])
self.assertEqual(qs, result)

def test_filtering_skipped_with_none_value(self):
qs = mock.Mock()
f = BooleanFilter(name='somefield')
f = BooleanFilter(field_name='somefield')
result = f.filter(qs, None)
self.assertListEqual(qs.method_calls, [])
self.assertEqual(qs, result)

def test_filtering_lookup_expr(self):
qs = mock.Mock(spec=['filter'])
f = BooleanFilter(name='somefield', lookup_expr='isnull')
f = BooleanFilter(field_name='somefield', lookup_expr='isnull')
result = f.filter(qs, True)
qs.filter.assert_called_once_with(somefield__isnull=True)
self.assertNotEqual(qs, result)
Expand Down Expand Up @@ -447,7 +447,7 @@ def test_conjoined_true(self):

def test_filtering(self):
qs = mock.Mock(spec=['filter'])
f = MultipleChoiceFilter(name='somefield')
f = MultipleChoiceFilter(field_name='somefield')
with mock.patch('django_filters.filters.Q') as mockQclass:
mockQ1, mockQ2 = mock.MagicMock(), mock.MagicMock()
mockQclass.side_effect = [mockQ1, mockQ2]
Expand All @@ -462,7 +462,7 @@ def test_filtering(self):

def test_filtering_exclude(self):
qs = mock.Mock(spec=['exclude'])
f = MultipleChoiceFilter(name='somefield', exclude=True)
f = MultipleChoiceFilter(field_name='somefield', exclude=True)
with mock.patch('django_filters.filters.Q') as mockQclass:
mockQ1, mockQ2 = mock.MagicMock(), mock.MagicMock()
mockQclass.side_effect = [mockQ1, mockQ2]
Expand All @@ -477,7 +477,7 @@ def test_filtering_exclude(self):

def test_filtering_on_required_skipped_when_len_of_value_is_len_of_field_choices(self):
qs = mock.Mock(spec=[])
f = MultipleChoiceFilter(name='somefield', required=True)
f = MultipleChoiceFilter(field_name='somefield', required=True)
f.always_filter = False
result = f.filter(qs, [])
self.assertEqual(len(f.field.choices), 0)
Expand All @@ -492,7 +492,7 @@ def test_filtering_on_required_skipped_when_len_of_value_is_len_of_field_choices

def test_filtering_skipped_with_empty_list_value_and_some_choices(self):
qs = mock.Mock(spec=[])
f = MultipleChoiceFilter(name='somefield')
f = MultipleChoiceFilter(field_name='somefield')
f.field.choices = ['some', 'values', 'here']
result = f.filter(qs, [])
self.assertEqual(qs, result)
Expand Down Expand Up @@ -551,7 +551,7 @@ def test_filter_conjoined_true(self):
users = User.objects.all()

for item in filter_list:
f = MultipleChoiceFilter(name='favorite_books__pk', conjoined=True)
f = MultipleChoiceFilter(field_name='favorite_books__pk', conjoined=True)
queryset = f.filter(users, item[0])
expected_pks = [c[0] for c in queryset.values_list('pk')]
self.assertListEqual(
Expand Down Expand Up @@ -584,7 +584,7 @@ def test_conjoined_true(self):

def test_filtering(self):
qs = mock.Mock(spec=['filter'])
f = TypedMultipleChoiceFilter(name='somefield')
f = TypedMultipleChoiceFilter(field_name='somefield')
with mock.patch('django_filters.filters.Q') as mockQclass:
mockQ1, mockQ2 = mock.MagicMock(), mock.MagicMock()
mockQclass.side_effect = [mockQ1, mockQ2]
Expand All @@ -599,7 +599,7 @@ def test_filtering(self):

def test_filtering_exclude(self):
qs = mock.Mock(spec=['exclude'])
f = TypedMultipleChoiceFilter(name='somefield', exclude=True)
f = TypedMultipleChoiceFilter(field_name='somefield', exclude=True)
with mock.patch('django_filters.filters.Q') as mockQclass:
mockQ1, mockQ2 = mock.MagicMock(), mock.MagicMock()
mockQclass.side_effect = [mockQ1, mockQ2]
Expand All @@ -614,7 +614,7 @@ def test_filtering_exclude(self):

def test_filtering_on_required_skipped_when_len_of_value_is_len_of_field_choices(self):
qs = mock.Mock(spec=[])
f = TypedMultipleChoiceFilter(name='somefield', required=True)
f = TypedMultipleChoiceFilter(field_name='somefield', required=True)
f.always_filter = False
result = f.filter(qs, [])
self.assertEqual(len(f.field.choices), 0)
Expand All @@ -629,7 +629,7 @@ def test_filtering_on_required_skipped_when_len_of_value_is_len_of_field_choices

def test_filtering_skipped_with_empty_list_value_and_some_choices(self):
qs = mock.Mock(spec=[])
f = TypedMultipleChoiceFilter(name='somefield')
f = TypedMultipleChoiceFilter(field_name='somefield')
f.field.choices = ['some', 'values', 'here']
result = f.filter(qs, [])
self.assertEqual(qs, result)
Expand Down Expand Up @@ -688,7 +688,7 @@ def test_filter_conjoined_true(self):
users = User.objects.all()

for item in filter_list:
f = TypedMultipleChoiceFilter(name='favorite_books__pk', conjoined=True)
f = TypedMultipleChoiceFilter(field_name='favorite_books__pk', conjoined=True)
queryset = f.filter(users, item[0])
expected_pks = [c[0] for c in queryset.values_list('pk')]
self.assertListEqual(
Expand Down Expand Up @@ -807,7 +807,7 @@ def test_default_field_with_queryset(self):

def test_filtering_to_field_name(self):
qs = User.objects.all()
f = ModelMultipleChoiceFilter(name='first_name',
f = ModelMultipleChoiceFilter(field_name='first_name',
to_field_name='first_name',
queryset=qs)
user = User.objects.create(first_name='Firstname')
Expand Down Expand Up @@ -1203,7 +1203,7 @@ def test_default_field_with_assigning_model(self):
self.assertIsInstance(field, forms.ChoiceField)

def test_empty_value_in_choices(self):
f = AllValuesFilter(name='username')
f = AllValuesFilter(field_name='username')
f.model = User

self.assertEqual(list(f.field.choices), [
Expand Down
Loading

0 comments on commit dd4795c

Please sign in to comment.