source: exist/trunk/python/ndgUtils/test_eXistInterface.py @ 3128

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/python/ndgUtils/test_eXistInterface.py@4025
Revision 3128, 1.9 KB checked in by lawrence, 12 years ago (diff)

The dif2moles round tripping is in place (but the comparison doesn't
work and needs analysis).

Line 
1import unittest,os
2from eXistInterface import *
3
4class TestCase(unittest.TestCase):
5    def setUp(self):
6        ''' Try to connect to the exist databases available '''
7        try:
8            passwordFile='passwords.txt'
9            f=open(passwordFile,'r')
10            pw={}
11            for line in f.readlines():
12                host,userid,password=line.strip().split(' ')
13                pw[host]=(userid,password)
14            f.close()
15            self.pw=pw
16        except IOError,e:
17            raise IOError('''\n
18        Running this test requires a "passwords.txt" file in directory %s 
19        This file should include one or more lines of the form:
20                hostname username password
21        and this test routine will use the *last* one of these to test things!
22        '''%os.getcwd())
23       
24    def test_listCollections(self):
25        ''' Test we can list collections in the database '''
26        for host in self.pw:
27            xmldb=ndg_eXist(db=host)
28            xq='''for $s in xmldb:get-child-collections('/db') return <collection>{$s}</collection>'''
29            id,summary=xmldb.executeQuery(xq)
30            self.assertEqual(True,(summary['hits']>0))
31            for i in range(summary['hits']): print host,xmldb.retrieveNext(id,i)
32            xmldb.release(id)
33           
34    def test_manipulateCollections(self):
35        ''' Test we can create a collection '''
36        dummy='/db/scratchBNL'
37        #just use the first one in our file ...
38        hosts=self.pw.keys()
39        xmldb=ndg_eXist(db=hosts[0])
40        r=xmldb.createCollection(dummy)
41        self.assertEqual(True,r,'unable to create collection')
42        r=xmldb.removeCollection(dummy)
43        self.assertEqual(True,r,'unable to remove collection')
44
45    #def test_xqueryLib(self):
46    #    ''' Test the installed xquery lib is the same as the source xquery lib '''
47    #    pass
48   
49if __name__=="__main__":
50    unittest.main()
Note: See TracBrowser for help on using the repository browser.