Luke Plant avatar Luke Plant committed 04a3f5b

Added test for rendering, and fixed filter label to be capitalised

Comments (0)

Files changed (2)


 from django.utils.safestring import mark_safe
 from django.utils.html import escape
 from django.utils.http import urlencode
+from django.utils.text import capfirst
 standard_filter_mapping = {
     def render(self, qs, params):
         out = []
         field_obj = qs.model._meta.get_field(self.field)
-        label = field_obj.verbose_name
+        label = capfirst(field_obj.verbose_name)
         for c in self.get_choices(qs, params):
             out.append(u'<a href="%s">%s</a> (%d) &nbsp;&nbsp;' % (escape(c.url), escape(c.label), c.count))
         return u'<div>%s: %s</div>' % (escape(label), u''.join(out))


 class TestFilterSet(TestCase):
+    # Tests are written so that adding new data to fixtures won't break the
+    # tests, so numbers/values are compared using DB queries. Extra care is
+    # taken to ensure that there is some data that matches what we are assuming
+    # is there.
     fixtures = ['django_easyfilters_tests']
     def test_queryset_no_filters(self):
         class BookFilterSet(FilterSet):
             fields = []
-            model = Book
         qs = Book.objects.all()
         data = {}
             fields = [
-            model = Book
         # Make another Genre that isn't used
         new_g, created = Genre.objects.get_or_create(name='Nonsense')
+    def test_filterset_render(self):
+        """
+        Smoke test to ensure that filtersets can be rendered
+        """
+        class BookFilterSet(FilterSet):
+            fields = [
+                'genre',
+                ]
+        fs = BookFilterSet(Book.objects.all(), {})
+        rendered = fs.render()
+        self.assertTrue('Genre' in rendered)
+        self.assertEqual(rendered, unicode(fs))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.