Example #1
0
    def test_set_collection(self):
        # initialize with no collection
        xq = Xquery(xpath='/el')
        xq.set_collection('coll')
        self.assertEquals('collection("/db/coll")/el', xq.getQuery())

        # initialize with one collection, then switch
        xq = Xquery(collection='coll1')
        xq.set_collection('coll2')
        self.assertEquals('collection("/db/coll2")/node()', xq.getQuery())

        # leading slash is ok too
        xq.set_collection('/coll3')
        self.assertEquals('collection("/db/coll3")/node()', xq.getQuery())

        # set to None
        xq.set_collection(None)
        self.assertEquals('/node()', xq.getQuery())
Example #2
0
 def test_document(self):
     xq = Xquery(xpath='/el', document="/db/coll/file.xml")
     self.assertEquals('doc("/db/coll/file.xml")/el', xq.getQuery())
     # document takes precedence over collection
     xq.set_collection('coll')  # should be ignored
     self.assertEquals('doc("/db/coll/file.xml")/el', xq.getQuery())