Skip to content

Commit

Permalink
Merge pull request #62 from miki725/coreapi
Browse files Browse the repository at this point in the history
added CoreAPIURLFilterBackend
  • Loading branch information
miki725 authored Jul 23, 2018
2 parents a22e341 + 730ff88 commit 924c7b1
Show file tree
Hide file tree
Showing 37 changed files with 440 additions and 59 deletions.
9 changes: 9 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
History
-------

0.3.6 (2018-07-23)
~~~~~~~~~~~~~~~~~~

* Added support for ``extra_kwargs`` in ``ModelFilterSet.Meta``.
* Added ``CoreAPIURLFilterBackend`` which enables documented filters in swagger docs.
* Added ``iin`` lookup in plain and sqlalchemy backends.
* Fixing inconsistency between plain and Django ``week_day`` lookup.
Now both are consistent with ``1``-Monday and ``7``-Sunday.

0.3.5 (2018-02-27)
~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.backends.base.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.backends.base module
===============================
url\_filter.backends.base module
================================

.. automodule:: url_filter.backends.base
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.backends.django.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.backends.django module
=================================
url\_filter.backends.django module
==================================

.. automodule:: url_filter.backends.django
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.backends.plain.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.backends.plain module
================================
url\_filter.backends.plain module
=================================

.. automodule:: url_filter.backends.plain
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.backends.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.backends package
===========================
url\_filter.backends package
============================

.. automodule:: url_filter.backends
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.backends.sqlalchemy.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.backends.sqlalchemy module
=====================================
url\_filter.backends.sqlalchemy module
======================================

.. automodule:: url_filter.backends.sqlalchemy
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.exceptions.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.exceptions module
============================
url\_filter.exceptions module
=============================

.. automodule:: url_filter.exceptions
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.fields.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.fields module
========================
url\_filter.fields module
=========================

.. automodule:: url_filter.fields
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.filters.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.filters module
=========================
url\_filter.filters module
==========================

.. automodule:: url_filter.filters
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.filtersets.base.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.filtersets.base module
=================================
url\_filter.filtersets.base module
==================================

.. automodule:: url_filter.filtersets.base
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.filtersets.django.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.filtersets.django module
===================================
url\_filter.filtersets.django module
====================================

.. automodule:: url_filter.filtersets.django
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.filtersets.plain.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.filtersets.plain module
==================================
url\_filter.filtersets.plain module
===================================

.. automodule:: url_filter.filtersets.plain
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.filtersets.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.filtersets package
=============================
url\_filter.filtersets package
==============================

.. automodule:: url_filter.filtersets
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.filtersets.sqlalchemy.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.filtersets.sqlalchemy module
=======================================
url\_filter.filtersets.sqlalchemy module
========================================

.. automodule:: url_filter.filtersets.sqlalchemy
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.integrations.drf.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.integrations.drf module
==================================
url\_filter.integrations.drf module
===================================

.. automodule:: url_filter.integrations.drf
:members:
Expand Down
7 changes: 7 additions & 0 deletions docs/api/url_filter.integrations.drf_coreapi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
url\_filter.integrations.drf\_coreapi module
============================================

.. automodule:: url_filter.integrations.drf_coreapi
:members:
:undoc-members:
:show-inheritance:
5 changes: 3 additions & 2 deletions docs/api/url_filter.integrations.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.integrations package
===============================
url\_filter.integrations package
================================

.. automodule:: url_filter.integrations
:members:
Expand All @@ -12,4 +12,5 @@ Submodules
.. toctree::

url_filter.integrations.drf
url_filter.integrations.drf_coreapi

4 changes: 2 additions & 2 deletions docs/api/url_filter.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter package
==================
url\_filter package
===================

.. automodule:: url_filter
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.utils.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.utils module
=======================
url\_filter.utils module
========================

.. automodule:: url_filter.utils
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/url_filter.validators.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url_filter.validators module
============================
url\_filter.validators module
=============================

.. automodule:: url_filter.validators
:members:
Expand Down
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
-r requirements.txt
coreapi
coverage
django-extensions
djangorestframework
flake8
importanize
mock
pdbpp
ptpython
pytest
pytest-cov
pytest-django
Expand Down
8 changes: 7 additions & 1 deletion tests/backends/test_plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def test_filter_in(self):
[DATA[1]]
)

def test_filter_iin(self):
self._test_filter(
FilterSpec(['restaurant', 'waiters', 'name'], 'iin', ['john', 'steve'], False),
[DATA[1]]
)

def test_filter_in_simple_list(self):
self._test_filter(
FilterSpec(['nicknames'], 'in', ['ace', 'dogs'], False),
Expand Down Expand Up @@ -246,7 +252,7 @@ def test_filter_year(self):

def test_filter_week_day(self):
self._test_filter(
FilterSpec(['created'], 'week_day', 1, False),
FilterSpec(['created'], 'week_day', 2, False), # Monday
[DATA[1]]
)

Expand Down
6 changes: 6 additions & 0 deletions tests/backends/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ def test_build_clause_in(self, alchemy_db):
Waiter.name.in_(['Django', 'rocks'])
)

def test_build_clause_iin(self, alchemy_db):
self._test_build_clause(
alchemy_db, 'name', 'iin', ['Django', 'rocks'],
func.lower(Waiter.name).in_(['django', 'rocks'])
)

def test_build_clause_isnull(self, alchemy_db):
self._test_build_clause(
alchemy_db, 'name', 'isnull', True,
Expand Down
11 changes: 11 additions & 0 deletions tests/filtersets/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Meta(object):
model = Place
allow_related = False
allow_related_reverse = False
extra_kwargs = {
'id': {'no_lookup': True},
}

filters = PlaceFilterSet().get_filters()

Expand All @@ -37,6 +40,7 @@ class Meta(object):

assert isinstance(filters['id'], Filter)
assert isinstance(filters['id'].form_field, forms.IntegerField)
assert filters['id'].no_lookup is True
assert isinstance(filters['name'], Filter)
assert isinstance(filters['name'].form_field, forms.CharField)
assert isinstance(filters['address'], Filter)
Expand Down Expand Up @@ -127,6 +131,11 @@ def test_get_filters_with_both_reverse_and_direct_relations(self):
class RestaurantFilterSet(ModelFilterSet):
class Meta(object):
model = Restaurant
extra_kwargs = {
'place': {
'id': {'no_lookup': True},
},
}

filters = RestaurantFilterSet().get_filters()

Expand All @@ -140,6 +149,8 @@ class Meta(object):
'id', 'name',
}

assert filters['place'].filters['id'].no_lookup is True

assert isinstance(filters['serves_hot_dogs'], Filter)
assert isinstance(filters['serves_hot_dogs'].form_field, forms.BooleanField)
assert isinstance(filters['serves_pizza'], Filter)
Expand Down
11 changes: 11 additions & 0 deletions tests/filtersets/test_plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class Meta(object):
"ignored": [{}],
}
allow_related = False
extra_kwargs = {
'id': {'no_lookup': True},
}

filters = PlaceFilterSet().get_filters()

Expand All @@ -45,6 +48,7 @@ class Meta(object):

assert isinstance(filters['id'], Filter)
assert isinstance(filters['id'].form_field, forms.IntegerField)
assert filters['id'].no_lookup is True
assert isinstance(filters['name'], Filter)
assert isinstance(filters['name'].form_field, forms.CharField)
assert isinstance(filters['address'], Filter)
Expand Down Expand Up @@ -78,6 +82,11 @@ class Meta(object):
"name": "Demon Dogs",
"address": "944 W. Fullerton"
}
extra_kwargs = {
'restaurant': {
'place': {'no_lookup': True},
},
}

filters = PlaceFilterSet().get_filters()

Expand All @@ -91,6 +100,8 @@ class Meta(object):
'id', 'name', 'restaurant',
}

assert filters['restaurant'].filters['place'].no_lookup is True

assert isinstance(filters['id'], Filter)
assert isinstance(filters['id'].form_field, forms.IntegerField)
assert isinstance(filters['address'], Filter)
Expand Down
11 changes: 11 additions & 0 deletions tests/filtersets/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class PlaceFilterSet(SQLAlchemyModelFilterSet):
class Meta(object):
model = Place
allow_related = False
extra_kwargs = {
'id': {'no_lookup': True},
}

filters = PlaceFilterSet().get_filters()

Expand All @@ -38,6 +41,7 @@ class Meta(object):

assert isinstance(filters['id'], Filter)
assert isinstance(filters['id'].form_field, forms.IntegerField)
assert filters['id'].no_lookup is True
assert isinstance(filters['name'], Filter)
assert isinstance(filters['name'].form_field, forms.CharField)
assert isinstance(filters['address'], Filter)
Expand Down Expand Up @@ -88,6 +92,11 @@ def test_get_filters_with_both_reverse_and_direct_relations(self):
class RestaurantFilterSet(SQLAlchemyModelFilterSet):
class Meta(object):
model = Restaurant
extra_kwargs = {
'place': {
'id': {'no_lookup': True},
},
}

filters = RestaurantFilterSet().get_filters()

Expand All @@ -101,6 +110,8 @@ class Meta(object):
'id', 'name', 'restaurant_id'
}

assert filters['place'].filters['id'].no_lookup is True

assert isinstance(filters['serves_hot_dogs'], Filter)
assert isinstance(filters['serves_hot_dogs'].form_field, forms.BooleanField)
assert isinstance(filters['serves_pizza'], Filter)
Expand Down
Loading

0 comments on commit 924c7b1

Please sign in to comment.