Exemplo n.º 1
0
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})
Exemplo n.º 2
0
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})
Exemplo n.º 3
0
    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])
Exemplo n.º 4
0
    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])
Exemplo n.º 5
0
    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})
Exemplo n.º 6
0
    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})
Exemplo n.º 7
0
    def test_count(self):
        Document.col.insert({})
        Document.col.insert({})

        self.assertEqual(Document.find().count(), 2)
Exemplo n.º 8
0
 def setUp(self):
     self.doc = Document()
Exemplo n.º 9
0
    def test_count(self):
        Document.col.insert({})
        Document.col.insert({})

        self.assertEqual(Document.find().count(), 2)
Exemplo n.º 10
0
 def setUp(self):
     self.doc = Document()
Exemplo n.º 11
0
    def setUp(self):
        self.document = Document()

        self.connection = pymongo.Connection()
        self.db = self.connection.test
        self.collection = self.db.test_collection
Exemplo n.º 12
0
    def test_init_with_values(self):
        data = {'attr1': 1, 'attr2': 2}
        document = Document(data)

        self.assertEquals(document, data)