Created
May 18, 2011 07:50
-
-
Save rozza/978162 to your computer and use it in GitHub Desktop.
mongoengine/issues/166
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from django.conf import settings | |
import unittest | |
from mongoengine import * | |
from django.template.defaultfilters import length | |
from django.template import Context, Template | |
class TemplateFilterTest(unittest.TestCase): | |
def setUp(self): | |
connect(db='mongoenginetest') | |
settings.configure() | |
class Note(Document): | |
text = StringField() | |
self.Note = Note | |
def tearDown(self): | |
self.Note.drop_collection() | |
def test_filter(self): | |
"""Ensure that a queryset and filters work as expected | |
""" | |
for i in xrange(1, 101): | |
n = self.Note(name="Note: %s" % i) | |
n.save() | |
# Check the count | |
self.assertEqual(self.Note.objects.count(), 100) | |
# Get the first 10 and confirm | |
notes = self.Note.objects[:10] | |
self.assertEqual(len(notes), 10) | |
self.assertEqual(notes.count(), 10) | |
# Test djangos template filters | |
self.assertEqual(length(notes), 10) | |
t = Template("{{ notes|length }}") | |
c = Context({"notes": notes}) | |
self.assertEqual(t.render(c), "10") | |
# Test with limit | |
notes = self.Note.objects.limit(10) | |
self.assertEqual(len(notes), 10) | |
self.assertEqual(notes.count(), 10) | |
# Test djangos template filters | |
self.assertEqual(length(notes), 10) | |
t = Template("{{ notes|length }}") | |
c = Context({"notes": notes}) | |
self.assertEqual(t.render(c), "10") | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment