class DocumentPrivateProtected(unittest.TestCase): def setUp(self): self.doc = Document() def tearDown(self): Document.col.remove() def test_private_attr_id(self): """We must be able to set the _id of a document """ oid = ObjectId() self.doc._id = oid self.doc.save() print "Self doc", self.doc self.assertEqual(Document.col.find_one()['_id'], oid) def test_private_attr_during_save(self): self.doc.a = 'a' self.doc._b = 'b' self.doc.save() self.assertEqual(Document.find_one(), {'_id': self.doc._id, 'a': self.doc.a})
def test_advanced_cursor_methods(self): for i in range(10): Document.col.insert({'i': i}) objects = Document.find().skip(2).limit(5) self.assertEqual(range(2, 7), [o['i'] for o in objects])
def test_private_attr_during_save(self): self.doc.a = 'a' self.doc._b = 'b' self.doc.save() self.assertEqual(Document.find_one(), {'_id': self.doc._id, 'a': self.doc.a})
def test_count(self): Document.col.insert({}) Document.col.insert({}) self.assertEqual(Document.find().count(), 2)
def setUp(self): self.doc = Document()
def setUp(self): self.document = Document() self.connection = pymongo.Connection() self.db = self.connection.test self.collection = self.db.test_collection
def test_init_with_values(self): data = {'attr1': 1, 'attr2': 2} document = Document(data) self.assertEquals(document, data)