def test_skip(self):
     D3.COLLECTION.drop()
     whiskeycache.clear_cache()
     theese_dees = [D3({'myJaws':'1'}),D3({'myJaws':'2'}),D3({'myJaws':'3'})]
     self.assertEqual(D3.find({}, skip=2).count(), 1)
     self.assertEqual(D3.find({}, sort=[('myJaws',1)], skip=2).next().myJaws, '3')
     self.assertEqual(D3.find({}, skip=4).count(), 0)
 def test_or_query(self):
     D3.COLLECTION.drop()
     whiskeycache.clear_cache()
     theese_dees = [
         D3({'myJaws': 'big'}),
         D3({'myJaws': 'small'}),
         D3({'myJaws': 'just right'})
     ]
     for d in theese_dees:
         d.save()
     queries = [{
         'myJaws': 'big'
     }, {
         'myJaws': 'big',
         'someOtherVal': None,
         '$or': [
             {
                 'myJaws': 'small'
             },
             {
                 'myJaws': 'just right'
             },
         ]
     }, {
         '$or': [
             {
                 'myJaws': 'small'
             },
             {
                 'myJaws': 'just right'
             },
         ]
     }, {
         'some_dict': [],
         '$or': [
             {
                 'myJaws': 'big'
             },
             {
                 'myJaws': 'just right'
             },
         ]
     }, {
         '$or': [{
             'some_list': []
         }, {
             'some_dict': {}
         }]
     }]
     i = 1
     for query in queries:
         print '=' * 72
         print str(i) + 'query ' + str(query)
         self.assertEqual(len(whiskeycache.find(D3, query, [('_id', -1)])),
                          D3.COLLECTION.find(query).count())
         i += 1
 def test_skip(self):
     D3.COLLECTION.drop()
     whiskeycache.clear_cache()
     theese_dees = [
         D3({'myJaws': '1'}),
         D3({'myJaws': '2'}),
         D3({'myJaws': '3'})
     ]
     self.assertEqual(D3.find({}, skip=2).count(), 1)
     self.assertEqual(
         D3.find({}, sort=[('myJaws', 1)], skip=2).next().myJaws, '3')
     self.assertEqual(D3.find({}, skip=4).count(), 0)
    def test_or_query(self):
        D3.COLLECTION.drop()
        whiskeycache.clear_cache()
        theese_dees = [D3({'myJaws':'big'}),D3({'myJaws':'small'}),D3({'myJaws':'just right'})]
        for d in theese_dees:
            d.save()
        queries = [
                    {'myJaws':'big'

                },
                    {
                     'myJaws':'big',
                     'someOtherVal':None,
                     '$or':[
                          
                             {'myJaws':'small'},
                             {'myJaws':'just right'},
                         ]
                 }, 
                 {
                     '$or':[
                             {'myJaws':'small'},
                             {'myJaws':'just right'},
                         ]
                 },
                  {
                     'some_dict':[],
                     '$or':[
                           
                             {'myJaws':'big'},
                             {'myJaws':'just right'},
                         ]
                 },
                  {
                    '$or':[
                            {'some_list':[]},
                            {'some_dict':{}}
                        ]
                    }
             ]
        i = 1
        for query in queries:
            print '='*72
            print str(i) + 'query ' + str(query)
            self.assertEqual( len(whiskeycache.find(D3, query, [('_id', -1)] )), D3.COLLECTION.find(query).count())
            i += 1
    def test_whiskeycursor_next(self):
        D3.COLLECTION.drop()

        dees = [D3(), D3(), D3()]
        for d in dees:
            d.save()

        whiskeycache.clear_cache()

        whiskey_cursor = D3.find()
        nexted = whiskey_cursor.next()
        self.assertTrue(nexted._id == dees[2]._id)
        self.assertTrue(len(whiskey_cursor)==len(dees)-1)
        
        whiskey_cursor = D3.find()
        for i,d in enumerate(whiskey_cursor):
            index = len(dees) - i - 1
            self.assertTrue(d._id == dees[index]._id)
    def test_whiskeycursor_next(self):
        D3.COLLECTION.drop()

        dees = [D3(), D3(), D3()]
        for d in dees:
            d.save()

        whiskeycache.clear_cache()

        whiskey_cursor = D3.find()
        nexted = whiskey_cursor.next()
        self.assertTrue(nexted._id == dees[2]._id)
        self.assertTrue(len(whiskey_cursor) == len(dees) - 1)

        whiskey_cursor = D3.find()
        for i, d in enumerate(whiskey_cursor):
            index = len(dees) - i - 1
            self.assertTrue(d._id == dees[index]._id)
    def test_outbound_list_terminal(self):
        Edge.COLLECTION.drop()

        parent = ParentNode()
        for i in range(4):
            parent.sub_node_list.append(SubNode())

        parent.save()
        self.assertTrue(Edge.COLLECTION.find().count() == 4)

        whiskeycache.clear_cache()

        parent2 = ParentNode.from_id(parent._id)
        self.assertTrue(len(parent2.sub_node_list) == 4)

        parent2.sub_node_list.pop()
        self.assertTrue(len(parent2.sub_node_list) == 3)

        parent2.sub_node_list.extend([SubNode(), SubNode()])
        self.assertTrue(len(parent2.sub_node_list) == 5)

        parent2.save()
        #print parent2

        whiskeycache.clear_cache()

        parent3 = ParentNode.from_id(parent._id)
        #print parent3
        self.assertTrue(len(parent3.sub_node_list) == 5)

        #print "Edge.COLLECTION.find().count() %d" % Edge.COLLECTION.find().count()
        self.assertTrue(Edge.COLLECTION.find().count() == 5)
    
        #parent3.sub_node_list.insert(2, SubNode())

        parent3.sub_node_list.pop(1)

        parent3.sub_node_list.remove(parent3.sub_node_list[0])

        try:
            parent3.sub_node_list.append(ParentNode())
        except AssertionError, e:
            pass
    def test_assigning_subdoc(self):
        whiskeycache.clear_cache()
        #print '\n\nRAM: %s\n\nMORE_RAM: %s\n\n' % (whiskeycache.RAM, whiskeycache.MORE_RAM)
        sub_node = SubNode()
        parent_node = ParentNode()
        #print '\n\nRAM: %s\n\nMORE_RAM: %s\n\n' % (whiskeycache.RAM, whiskeycache.MORE_RAM)
        self.assertTrue(sub_node.parent == None)
        #you should be able to set the value of a connection before it's created
        parent_node.sub_node = sub_node
        #print '\n\nRAM: %s\n\nMORE_RAM: %s\n\n' % (whiskeycache.RAM, whiskeycache.MORE_RAM)
        #print 'sub.p '+str(sub_node.parent)
        #print 'parent '+str(parent_node)
        self.assertTrue(sub_node.parent == parent_node)

        parent_node.save()
        
        whiskeycache.clear_cache()

        parent_node2 = ParentNode.from_id(parent_node._id)
        self.assertTrue(parent_node2 == parent_node)
        #print "parent node id %s subnode id %s" % (str(parent_node2.sub_node._id), str(sub_node._id))
        self.assertTrue(parent_node2.sub_node._id == sub_node._id)
    def test_from_db_ref(self):
        #create a doc, tell it how big my balls are
        how_big = 'So big.'
        d = D5()
        d.myJaws = how_big
        d.save()

        #create a db ref, these save natively in the db, but they are about as usefull as a whole in a piece of toast
        dbref = DBRef(d.COLLECTION_NAME, d._id)

        whiskeycache.clear_cache()

        class A(WhiskeyNode):
            pass

        from_ref = A.from_dbref(dbref.collection, dbref.id)
        self.assertTrue(from_ref.get_field('myJaws') == how_big)
        #test that i can save a property on this generic document,
        even_bigger = 'even bigger...'

        from_ref.add_field('myJaws', unicode)
        self.assertTrue(from_ref.myJaws == how_big)
        from_ref.myJaws = even_bigger
        from_ref.save()

        whiskeycache.clear_cache()

        #make sure we saved
        from_ref3 = A.from_dbref(dbref.collection, dbref.id)
        self.assertTrue(from_ref3.get_field('myJaws') == even_bigger)

        whiskeycache.clear_cache()

        #retreving the doc with the proper class should make things happy
        from_ref2 = D5.from_dbref(dbref.collection, dbref.id)
        self.assertTrue(from_ref2.get_field('myJaws') == even_bigger)
        self.assertFalse(from_ref2.myJaws == how_big)
        self.assertTrue(from_ref2.myJaws == even_bigger)
    def test_from_db_ref(self):
        #create a doc, tell it how big my balls are
        how_big = 'So big.'
        d = D5()
        d.myJaws = how_big
        d.save()

        #create a db ref, these save natively in the db, but they are about as usefull as a whole in a piece of toast
        dbref = DBRef(d.COLLECTION_NAME, d._id)

        whiskeycache.clear_cache()

        class A(WhiskeyNode):pass
        from_ref = A.from_dbref(dbref.collection, dbref.id)
        self.assertTrue(from_ref.get_field('myJaws') == how_big)
        #test that i can save a property on this generic document,
        even_bigger = 'even bigger...'

        from_ref.add_field('myJaws', unicode)
        self.assertTrue(from_ref.myJaws == how_big)
        from_ref.myJaws = even_bigger
        from_ref.save()

        whiskeycache.clear_cache()

        #make sure we saved
        from_ref3 = A.from_dbref(dbref.collection, dbref.id)
        self.assertTrue(from_ref3.get_field('myJaws') == even_bigger)


        whiskeycache.clear_cache()

        #retreving the doc with the proper class should make things happy
        from_ref2 = D5.from_dbref(dbref.collection, dbref.id)
        self.assertTrue(from_ref2.get_field('myJaws') == even_bigger)
        self.assertFalse(from_ref2.myJaws == how_big)
        self.assertTrue(from_ref2.myJaws == even_bigger)
 def __cleanup(self):
     Edge.COLLECTION.drop()
     EmailAddress.COLLECTION.drop()
     User.COLLECTION.drop()
     ContactInfo.COLLECTION.drop()
     whiskeycache.clear_cache()
Exemple #12
0
 def __cleanup(self):
     Edge.COLLECTION.drop()
     EmailAddress.COLLECTION.drop()
     User.COLLECTION.drop()
     ContactInfo.COLLECTION.drop()
     whiskeycache.clear_cache()