Skip to content

Commit

Permalink
Implement base class select method
Browse files Browse the repository at this point in the history
  • Loading branch information
bkg committed Dec 7, 2016
1 parent c51c1b9 commit d0786d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions spillway/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def query(self, force=False):
def select(self):
"""Set GeoQuerySet from field values and filters.
Subclasses implement this. Not called directly, use .query().
Subclasses may override this. Not called directly, use .query().
"""
raise NotImplementedError
self.queryset = self.queryset.filter(**self.cleaned_data)


class SpatialQueryForm(QuerySetForm):
Expand Down
11 changes: 9 additions & 2 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.test import SimpleTestCase
from django.test import SimpleTestCase, TestCase
from django.forms import fields
from django.contrib.gis import geos

from spillway import forms
from .models import Location


class PKeyQuerySetForm(forms.QuerySetForm):
Expand Down Expand Up @@ -39,7 +40,13 @@ def test_intersects_invalid(self):
self.assertFalse(form.is_valid())


class QuerySetFormTestCase(SimpleTestCase):
class QuerySetFormTestCase(TestCase):
def test_queryset(self):
Location.add_buffer((5, 7), 2)
qs = Location.objects.all()
form = PKeyQuerySetForm({'pk': '1'}, queryset=qs)
self.assertEqual(form.query()[0].pk, 1)

def test_missing_queryset(self):
form = PKeyQuerySetForm({'pk': '1'})
self.assertRaises(TypeError, form.query)

0 comments on commit d0786d7

Please sign in to comment.