source: ndgCommon/trunk/ndg/common/unittests/clients/xmldb/eXist/testatomdbinitialiser.py @ 4942

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/unittests/clients/xmldb/eXist/testatomdbinitialiser.py@4942
Revision 4942, 2.5 KB checked in by cbyrom, 12 years ago (diff)

Replace old eXist connector tests with tests based on the new clients
+ extend and fix this wherever necessary.

Line 
1'''
2A test class for the AtomDBInitialiser module.
3
4@author C Byrom, Tessella Jan 2009
5'''
6import unittest, time, logging
7from ndg.common.src.clients.xmldb.eXist.atomdbinitialiser import AtomDBInitialiser as ai
8import ndg.common.unittests.testconstants as tc
9from ndg.common.unittests.testutils import testUtils as tu
10import ndg.common.src.clients.xmldb.eXist.dbconstants as dc
11
12class testAtomDBInitialiser(unittest.TestCase):
13   
14    def setUp(self):
15        '''
16        set up data used in the tests.
17        '''
18        self.utils = tu(tc.EXIST_DBCONFIG_FILE)
19        self.ai = ai(self.utils.ac)
20        logging.basicConfig(level=logging.DEBUG,
21                        format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s')
22
23
24    def testSetUpIndexes(self):
25        fileName = self.utils.ac.resources.indexes.keys()[0]
26        pathName = fileName.replace('_', '/')
27        pathName = dc.EXIST_CONFIG_PATH + pathName.replace('.xconf', '') + '/' + fileName
28        # firstly, remove this file, if it exists
29        if not self.utils.ac.isNewDoc(pathName):
30            self.utils.ac.deleteDoc(pathName)
31        self.assertEquals(self.utils.ac.isNewDoc(pathName), True)
32       
33        # now run the set up
34        self.ai._AtomDBInitialiser__setUpIndexes()
35       
36        # now check it exists
37        self.assertFalse(self.utils.ac.isNewDoc(pathName))
38
39
40    def testSetUpEXistCollections(self):
41        try:
42            self.utils.ac.client.removeCollection(dc.ATOM_COLLECTION_PATH)
43            self.assertTrue(self.utils.ac.isNewCollection(dc.ATOM_COLLECTION_PATH))
44
45            self.ai._AtomDBInitialiser__setUpEXistAtomCollections()
46            self.assertFalse(self.utils.ac.isNewCollection(dc.ATOM_COLLECTION_PATH))
47        except Exception, e:
48            self.fail("Should not have thrown an exception")
49
50
51    def testAddAtomSchema(self):
52        fileName = self.utils.ac.resources.xsd.keys()[0] + '.xsd'
53        pathName = dc.SCHEMAS_COLLECTION_PATH + '/' + fileName
54        # firstly, remove this file, if it exists
55        if not self.utils.ac.isNewDoc(pathName):
56            self.utils.ac.deleteDoc(pathName)
57            time.sleep(2)
58
59        self.assertEquals(self.utils.ac.isNewDoc(pathName), True)
60
61        self.ai._AtomDBInitialiser__addAtomSchema()
62       
63        # now check it exists
64        self.assertEquals(self.utils.ac.isNewDoc(pathName), False)
65
66       
67       
68if __name__ == '__main__':
69
70    unittest.main()
Note: See TracBrowser for help on using the repository browser.