source: exist/trunk/python/ndgUtils/models/testexistdbclient.py @ 4229

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/python/ndgUtils/models/testexistdbclient.py@4229
Revision 4229, 4.7 KB checked in by cbyrom, 11 years ago (diff)

Add support for doing lists and summaries of atom docs via ndgDirectory and the existInterface class + add necessary xquery files for this + add new method to
allow retrieval of the collection to which an atom with a specified ID belongs - including the associated xquery file + extend tests to exercise these new features
+ add custom Atom error + improve preservation of key atom attributes when loading existing atoms into an Atom object + improve determining default atom collection

Line 
1'''
2A test class for the eXistDBClient module.
3
4C Byrom Jun 2008
5Tessella
6'''
7import unittest
8import existdbclient as dbc
9from ndgUtils.eXistConnector import eXistConnector
10import unittests.testdata as data
11import time
12
13class testEXistDBClient(unittest.TestCase):
14   
15     # collection path for CSML docs
16    VALID_COLLECTION_PATH = eXistConnector.BASE_COLLECTION_PATH
17    VALID_FILE = "tst.xml"
18    VALID_FILE_PATH = VALID_COLLECTION_PATH + VALID_FILE
19    DBCONFIG_FILE = "exist.config"
20   
21    def setUp(self):
22        '''
23        set up data used in the tests.
24        '''
25        print "Setting up..."
26        self.tidyUp = False    #     switch to indicate to tearDown that we need to delete the created eXist file
27        self.dbc = dbc.eXistDBClient(configFile = self.DBCONFIG_FILE)
28       
29       
30    def testSetUpEXistCollections(self):
31        try:
32            self.dbc._setUpEXistAtomCollections()
33        except:
34            fail("Should not have thrown an exception")
35       
36    def testLoadDBDetailsValid(self):
37        self.dbc._loadDBDetails(self.DBCONFIG_FILE)
38        if not self.dbc._pw or not self.dbc.eXistDBHostname or not self.dbc._username:
39            fail("Did not manage to read in db config data")
40       
41    def testLoadDBDetailsInvalid(self):
42        self.assertRaises(ValueError,self.dbc._loadDBDetails, "blah" + self.DBCONFIG_FILE)
43
44    def testLookupEXistFileFail(self):
45        self.assertEquals(self.dbc._lookupEXistFile(self.VALID_FILE_PATH), None)
46
47    def testLookupEXistFileFind(self):
48        self.tidyUp = True
49        self.assertEquals(self.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True)
50        self.assertNotEquals(self.dbc._lookupEXistFile(self.VALID_FILE_PATH), None)
51       
52    def testIsNewEXistFile(self):
53        self.assertEquals(self.dbc.isNewEXistFile(self.VALID_FILE_PATH), True)
54
55    def testIsNewEXistFileBeforeAndAfterCreateFile(self):
56        self.tidyUp = True
57        self.assertEquals(self.dbc.isNewEXistFile(self.VALID_FILE_PATH), True)
58        self.assertEquals(self.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True)
59        self.assertEquals(self.dbc.isNewEXistFile(self.VALID_FILE_PATH), False)
60           
61    def testCreateEXistFile(self):
62        self.tidyUp = True
63        self.assertEquals(self.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True)
64       
65    def testCreateEXistFileDuplicate(self):
66        self.tidyUp = True
67        self.assertEquals(self.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True)
68        # NB, this just overwrites the file - so is valid here
69        self.assertEquals(self.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True)
70       
71    def testDeleteEXistFile(self):
72        self.assertEquals(self.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True)
73        self.assertEquals(self.dbc.deleteEXistFile(self.VALID_FILE_PATH), True)
74   
75    def testGetEXistFileFail(self):
76        self.assertEquals(self.dbc.getEXistFile(self.VALID_FILE_PATH), None)
77   
78    def testGetEXistFileSucceed(self):
79        self.tidyUp = True
80        self.assertEquals(self.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True)
81        self.assertNotEquals(self.dbc.getEXistFile(self.VALID_FILE_PATH), None)
82   
83    def testBackupEXistFile(self):
84        self.tidyUp = True
85        self.assertEquals(self.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True)
86        time.sleep(2)
87        backupFile = self.dbc.backupEXistFile(self.VALID_COLLECTION_PATH, self.VALID_FILE)
88        self.assertNotEquals(backupFile, None)
89        self.assertNotEquals(self.dbc.getEXistFile(backupFile), None)
90        self.dbc.deleteEXistFile(backupFile)
91   
92    def testBackupEXistFileMissing(self):
93        self.assertRaises(SystemError, self.dbc.backupEXistFile, self.VALID_COLLECTION_PATH, self.VALID_FILE)
94
95           
96    def testGetAtomFileCollectionPath(self):
97        self.tidyUp = True
98        self.assertEquals(self.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True)
99        self.dbc.getAtomFileCollectionPath(data.testdata.id)
100        #self.dbc.getAtomFileCollectionPath('tag:localhost:5000,2008-09-23:/view/neodc.nerc.ac.uk__ATOM__activity_11737124322917004')
101
102   
103    def tearDown(self):
104        if self.tidyUp:
105            # delete the test file, in case it has been used in a test
106            self.dbc.deleteEXistFile(self.VALID_FILE_PATH)
107
108if __name__ == '__main__':
109
110    unittest.main()
Note: See TracBrowser for help on using the repository browser.