From e204b8418317624096178c8caf5aea510434cccf Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Mon, 21 Dec 2009 02:52:30 +0000 Subject: [PATCH] Added test for custom collection names on Document --- tests/document.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/document.py b/tests/document.py index bec66ee9..40dec4d6 100644 --- a/tests/document.py +++ b/tests/document.py @@ -156,6 +156,30 @@ class DocumentTest(unittest.TestCase): meta = {'allow_inheritance': False} self.assertRaises(ValueError, create_employee_class) + def test_collection_name(self): + """Ensure that a collection with a specified name may be used. + """ + collection = 'personCollTest' + if collection in self.db.collection_names(): + self.db.drop_collection(collection) + + class Person(Document): + name = StringField() + meta = {'collection': collection} + + user = Person(name="Test User") + user.save() + self.assertTrue(collection in self.db.collection_names()) + + user_obj = self.db[collection].find_one() + self.assertEqual(user_obj['name'], "Test User") + + user_obj = Person.objects[0] + self.assertEqual(user_obj.name, "Test User") + + Person.drop_collection() + self.assertFalse(collection in self.db.collection_names()) + def test_creation(self): """Ensure that document may be created using keyword arguments. """