def test_add_modify(self): # Duplicate file as we will change it newxmlfile = FilePath(self.mktemp()) FilePath(xmlFile).copyTo(newxmlfile) db = AugmentXMLDB((newxmlfile.path,)) for item in testRecords: yield self._checkRecord(db, item) newrecord = AugmentRecord( **testAddRecords[0] ) yield db.addAugmentRecords((newrecord,)) newdb = AugmentXMLDB((newxmlfile.path,)) for item in testRecords: yield self._checkRecord(newdb, item) yield self._checkRecord(newdb, testAddRecords[0]) newrecord = AugmentRecord( **testModifyRecords[0] ) yield db.addAugmentRecords((newrecord,)) newdb = AugmentXMLDB((newxmlfile.path,)) for item in testRecords: yield self._checkRecord(newdb, item) yield self._checkRecord(newdb, testModifyRecords[0])
def test_refresh(self): """ Ensure that a refresh without any file changes doesn't zero out the cache """ dbxml = AugmentXMLDB((xmlFile,)) keys = dbxml.db.keys() dbxml.refresh() self.assertEquals(keys, dbxml.db.keys())
def test_shouldReparse(self): """ Verify that a change to the file will get noticed """ newxmlfile = FilePath(self.mktemp()) FilePath(xmlFile).copyTo(newxmlfile) db = AugmentXMLDB((newxmlfile.path,)) self.assertFalse(db._shouldReparse([newxmlfile.path])) # No need to parse newxmlfile.setContent("") # Change the file self.assertTrue(db._shouldReparse([newxmlfile.path])) # Need to parse
def test_add_modify(self): dbpath = os.path.abspath(self.mktemp()) db = self._db(dbpath) dbxml = AugmentXMLDB((xmlFile, )) yield db.addAugmentRecords(dbxml.db.values()) for item in testRecords: yield self._checkRecord(db, item) # Verify that a default record is returned, even if not specified # in the DB yield self._checkRecordExists(db, "D11F03A0-97EA-48AF-9A6C-FAC7F3975767") newrecord = AugmentRecord(**testAddRecords[0]) yield db.addAugmentRecords((newrecord, )) newdb = self._db(dbpath) for item in testRecords: yield self._checkRecord(newdb, item) yield self._checkRecord(newdb, testAddRecords[0]) newrecord = AugmentRecord(**testModifyRecords[0]) yield db.addAugmentRecords((newrecord, )) newdb = self._db(dbpath) for item in testRecords: yield self._checkRecord(newdb, item) yield self._checkRecord(newdb, testModifyRecords[0])
def test_read_default(self): db = AugmentXMLDB((xmlFileDefault,)) for item in testRecords: yield self._checkRecord(db, item) for item in testRecordWildcardDefault: yield self._checkRecord(db, item)
def test_read(self): db = AugmentXMLDB((xmlFile,)) for item in testRecords: yield self._checkRecord(db, item) # Verify that a default record is returned, even if not specified # in the DB yield self._checkRecordExists(db, "D11F03A0-97EA-48AF-9A6C-FAC7F3975767")
def test_normalize(self): """ Ensure augment uids are normalized upon opening """ newxmlfile = FilePath(self.mktemp()) FilePath(xmlFileNormalization).copyTo(newxmlfile) uids = list(self.uidsFromFile(newxmlfile.path)) self.assertEquals(uids, ['aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa']) AugmentXMLDB((newxmlfile.path,)) uids = list(self.uidsFromFile(newxmlfile.path)) self.assertEquals(uids, ['AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA'])
def test_read_default(self): dbpath = os.path.abspath(self.mktemp()) db = self._db(dbpath) dbxml = AugmentXMLDB((xmlFileDefault,)) yield db.addAugmentRecords(dbxml.db.values()) for item in testRecords: yield self._checkRecord(db, item) for item in testRecordWildcardDefault: yield self._checkRecord(db, item) # Do a second time to test caching for item in testRecordWildcardDefault: yield self._checkRecord(db, item)
def test_read_typed_default(self): """ Augments key ("uid" element in xml) can be any of the following, in this order of precedence: full uid <recordType>-XX* <recordType>-X* XX* X* <recordType>-Default Default """ dbpath = os.path.abspath(self.mktemp()) db = self._db(dbpath) dbxml = AugmentXMLDB((xmlFileDefault,)) yield db.addAugmentRecords(dbxml.db.values()) for recordType, item in testRecordTypeDefault: yield self._checkRecord(db, item, recordType)