示例#1
0
    def test_return_only(self):
        xq = Xquery(xpath='/el')
        xq.xq_var = '$n'
        xq.return_only({
            'myid': '@id',
            'some_name': 'name',
            'first_letter': 'substring(@n,1,1)'
        })
        xq_return = xq._constructReturn()
        self.assertTrue('return <el>' in xq_return)
        self.assertTrue('<field>{$n/@id}</field>' in xq_return)
        self.assertTrue('<field>{$n/name}</field>' in xq_return)
        self.assertTrue('<field>{substring($n/@n,1,1)}</field>' in xq_return)
        self.assertTrue('</el>' in xq_return)

        xq = Xquery(xpath='/some/el/notroot')
        xq.return_only({'id': '@id'})
        self.assertTrue('return <notroot>' in xq._constructReturn())

        # case where node test can't be the return element
        xq = Xquery(xpath='/foo/bar/node()')
        xq.return_only({'myid': '@id'})
        xq_return = xq._constructReturn()
        self.assertTrue('return <node>' in xq_return)

        xq = Xquery(xpath='/foo/bar/*')
        xq.return_only({'myid': '@id'})
        xq_return = xq._constructReturn()
        self.assertTrue('return <node>' in xq_return)
示例#2
0
    def test_return_also_raw(self):
        xq = Xquery(xpath='/el')
        xq.xq_var = '$n'
        xq._raw_prefix = 'r_'
        xq.return_also({'myid': 'count(util:expand(%(xq_var)s/@id))'},
                       raw=True)
        self.assertTrue('<r_myid>{count(util:expand($n/@id))}</r_myid>' in
                        xq._constructReturn())

        xq = Xquery(xpath='/el')
        xq.xq_var = '$n'
        xq._raw_prefix = 'r_'
        xq.return_also({'myid': '@id'}, raw=True)
        self.assertTrue('<r_myid>{@id}</r_myid>' in xq._constructReturn())
示例#3
0
 def test_return_also__fulltext_score(self):
     xq = Xquery(xpath='/el')
     xq.xq_var = '$n'
     xq.return_also({'fulltext_score': ''})
     self.assertTrue('let $fulltext_score := ft:score($n)' in xq.getQuery())
     self.assertTrue('<fulltext_score>{$fulltext_score}</fulltext_score>' in
                     xq._constructReturn())
示例#4
0
 def test_return_also(self):
     xq = Xquery(xpath='/el')
     xq.xq_var = '$n'
     xq.return_also({'myid': '@id', 'some_name': 'name'})
     self.assertTrue('{$n}' in xq._constructReturn())
     self.assertTrue('<field>{$n/@id}</field>' in xq._constructReturn())