Changeset 4788 for exist


Ignore:
Timestamp:
12/01/09 11:38:32 (11 years ago)
Author:
cbyrom
Message:

Improve testing of existdbclient - adjust how new atoms are stored
and removed - so that the DB is left in a reliably consistent state.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgutilstests/lib/testexistdbclient.py

    r4783 r4788  
    2929        set up data used in the tests. 
    3030        ''' 
    31         self.tidyUp = False    #     switch to indicate to tearDown that we need to delete the created eXist file 
     31        self.createdAtoms = []    # array to store paths to atoms created - in order to then delete them 
    3232        self.utils = tu(tc.DBCONFIG_FILE) 
    3333 
    3434    def testCreateOrUpdateEXistFile(self): 
    35         self.tidyUp = True 
    3635        try: 
    3736            self.utils.dbc.createOrUpdateEXistFile(data.testdata.xmlString, \ 
    3837                                             self.VALID_COLLECTION_PATH, \ 
    3938                                             self.VALID_FILE) 
     39            self.createdAtoms.append(self.VALID_FILE_PATH) 
    4040            self.utils.dbc.createOrUpdateEXistFile(data.testdata.xmlString, \ 
    4141                                             self.VALID_COLLECTION_PATH, \ 
     
    5959    def testValidCheckAtomSchemaCompliance(self): 
    6060        atom = self.utils.createAtomInEXist(tc.xmlString) 
     61        self.createdAtoms.append(atom.getFullPath()) 
    6162        atomPath = atom.getDefaultCollectionPath() + atom.atomName 
    6263        self.assertEqual([], self.utils.dbc.checkAtomSchemaCompliance(atomPath)) 
    63         self.utils.dbc.deleteAtomInExist(atom) 
    6464         
    6565    def testInvalidCheckAtomSchemaCompliance(self): 
    6666        atom = self.utils.createAtomInEXist(tc.invalidXmlString) 
    67         atomPath = atom.getDefaultCollectionPath() + atom.atomName 
     67        self.createdAtoms.append(atom.getFullPath()) 
     68        atomPath = atom.getFullPath() 
    6869        errors = self.utils.dbc.checkAtomSchemaCompliance(atomPath) 
    6970        self.assertEqual(1, len(errors)) 
    7071        self.assertTrue(errors[0].startswith(" Invalid content was found starting with element 'contributor'")) 
    71         self.utils.dbc.deleteAtomInExist(atom) 
    7272         
    7373    def testInvalidEmailCheckAtomSchemaCompliance(self): 
    7474        atom = self.utils.createAtomInEXist(tc.invalidEmailXmlString) 
    75         atomPath = atom.getDefaultCollectionPath() + atom.atomName 
     75        self.createdAtoms.append(atom.getFullPath()) 
     76        atomPath = atom.getFullPath() 
    7677        errors = self.utils.dbc.checkAtomSchemaCompliance(atomPath) 
    7778        self.assertEqual(2, len(errors)) 
    7879        self.assertTrue(errors[1].find("of element 'email' is not valid") > -1) 
    79         self.utils.dbc.deleteAtomInExist(atom) 
    8080 
    8181    def testValidCheckAtomSchemaComplianceWithKeyword(self): 
    8282        atom = self.utils.createAtom(tc.xmlString) 
     83        self.createdAtoms.append(atom.getFullPath()) 
    8384        self.assertEqual([], self.utils.dbc.checkAtomSchemaCompliance('', atom = atom)) 
    8485 
     
    99100    def testCreateAtomInExist(self): 
    100101        createdAtom = self.utils.createAtomInEXist(tc.xmlString) 
     102        self.createdAtoms.append(createdAtom.getFullPath()) 
    101103        self.assertNotEquals(None, createdAtom) 
    102         self.utils.dbc.deleteAtomInExist(createdAtom) 
    103104 
    104105    def testGetAtom(self): 
    105106        createdAtom = self.utils.createAtomInEXist(tc.xmlString) 
     107        self.createdAtoms.append(createdAtom.getFullPath()) 
    106108        self.assertNotEquals(None, createdAtom) 
    107109        self.assertNotEquals(None, self.utils.dbc.getAtom(createdAtom.datasetID)) 
    108         self.utils.dbc.deleteAtomInExist(createdAtom) 
    109110 
    110111 
     
    165166 
    166167    def testLookupEXistFileFind(self): 
    167         self.tidyUp = True 
    168168        self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
    169169        self.assertNotEquals(self.utils.dbc._eXistDBClient__lookupEXistFile(self.VALID_FILE_PATH), None) 
     
    173173 
    174174    def testIsNewEXistFileBeforeAndAfterCreateFile(self): 
    175         self.tidyUp = True 
    176175        self.assertEquals(self.utils.dbc.isNewEXistFile(self.VALID_FILE_PATH), True) 
    177176        self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     177        self.createdAtoms.append(self.VALID_FILE_PATH) 
    178178        self.assertEquals(self.utils.dbc.isNewEXistFile(self.VALID_FILE_PATH), False) 
    179179             
    180180    def testCreateEXistFile(self): 
    181         self.tidyUp = True 
    182         self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     181        self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     182        self.createdAtoms.append(self.VALID_FILE_PATH) 
    183183         
    184184    def testCreateEXistFileDuplicate(self): 
    185         self.tidyUp = True 
    186         self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     185        self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     186        self.createdAtoms.append(self.VALID_FILE_PATH) 
    187187        # NB, this just overwrites the file - so is valid here 
    188188        self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     
    196196     
    197197    def testGetEXistFileSucceed(self): 
    198         self.tidyUp = True 
    199         self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     198        self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     199        self.createdAtoms.append(self.VALID_FILE_PATH) 
    200200        self.assertNotEquals(self.utils.dbc.getEXistFile(self.VALID_FILE_PATH), None) 
    201201     
    202202    def testBackupEXistFile(self): 
    203         self.tidyUp = True 
    204         self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     203        self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     204        self.createdAtoms.append(self.VALID_FILE_PATH) 
    205205        backupFile = self.utils.dbc.backupEXistFile(self.VALID_COLLECTION_PATH, self.VALID_FILE) 
    206206        time.sleep(2) 
     
    213213             
    214214    def testGetAtomFileCollectionPath(self): 
    215         self.tidyUp = True 
    216         self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     215        self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     216        self.createdAtoms.append(self.VALID_FILE_PATH) 
    217217        self.utils.dbc.getAtomFileCollectionPath(data.testdata.id) 
    218218             
     
    221221             
    222222    def testGetAllAtomIDs(self): 
    223         self.tidyUp = True 
    224         self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     223        self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     224        self.createdAtoms.append(self.VALID_FILE_PATH) 
    225225        ids = self.utils.dbc.getAllAtomIDs() 
    226226        self.assertNotEquals(0, len(ids)) 
     
    228228             
    229229    def testGetAllAtomCollections(self): 
    230         self.tidyUp = True 
    231         self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     230        self.assertEquals(self.utils.dbc.createEXistFile(data.testdata.xmlString, self.VALID_COLLECTION_PATH, self.VALID_FILE), True) 
     231        self.createdAtoms.append(self.VALID_FILE_PATH) 
    232232        ids = self.utils.dbc.getAllAtomCollections() 
    233233        self.assertNotEquals(0, len(ids)) 
     
    244244        self.utils.dbc.runAsynchAtomPublish(atom) 
    245245 
     246 
    246247    def testRestoreBackup(self): 
    247248        atom = self.utils.createAtomInEXist(tc.xmlString) 
     249        self.createdAtoms.append(self.VALID_FILE_PATH) 
    248250        atom = self.utils.createAtomInEXist(tc.xmlString) 
    249251        backupPath = self.utils.dbc.backupName 
     
    262264        atom.atomTypeID = VTD.DE_TERM 
    263265        atom = self.utils.dbc.createAtomInExist(atom) 
     266        self.createdAtoms.append(atom.getFullPath()) 
    264267        self.utils.dbc.createDIFDocumentFromAtom(atom) 
    265         self.utils.dbc.deleteAtomInExist(atom) 
    266268         
    267269    def tearDown(self): 
    268         if self.tidyUp: 
     270        for path  in self.createdAtoms: 
    269271            # delete the test file, in case it has been used in a test 
    270             self.utils.dbc.deleteEXistFile(self.VALID_FILE_PATH) 
     272            self.utils.deleteAtomInExist(path) 
    271273 
    272274if __name__ == '__main__': 
Note: See TracChangeset for help on using the changeset viewer.