def updateMetadata(file, metadata, logger): try: logger.debug('Start updating the metadata in the xml file %s'%file) mdEditor = ChildMetadataBinding(file, logger) mdEditor.updateId(metadata['identifier']) mdEditor.updateTitle(metadata['title']) mdEditor.updateAbstract(metadata['abstract']) mdEditor.updateHierarchyLevelName(metadata['hierarchylevel']) mdEditor.updateBoundingBox(metadata['westBoundLongitude'], metadata['eastBoundLongitude'], metadata['southBoundLatitude'], metadata['northBoundLatitude']) mdEditor.updateDateStamp(metadata['dateStamp']) mdEditor.updateReferenceTime(metadata['temporalExtent_begin'], metadata['temporalExtent_end']) mdEditor.updateReferenceDate(metadata['cite_date']) mdEditor.updateGraphicOverview(metadata['overviews']) mdEditor.updateIdCode(metadata['identifier']) mdEditor.updateOnlineResource(metadata['onlineresource']) print '============================' print mdEditor.tostring() print '============================' mdEditor.saveFile(file) return True except: logger.error('Problems while updating the metadata for the xml file %s'%file) raise
def testUpdateGraphicOverview(self): try: updateValue = [ #'http://kartenforum.slub-dresden.de/cgi-bin/mtbows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=Historische%20Messtischblaetter&TRANSPARENT=true&FORMAT=image%2Fpng&STYLES=&SRS=EPSG%3A4314&BBOX=20.9999980927,55.7999992371,21.1666679382,55.9000015259&WIDTH=40&HEIGHT=40&TIME=19344', #'http://fotothek.slub-dresden.de/thumbs/df/dk/0010000/df_dk_0010001_0192.jpg', 'http://fotothek.slub-dresden.de/mids/df/dk/0010000/df_dk_0010001_0192.jpg' ] tmpDirectory = tempfile.mkdtemp('', 'tmp_', TEMPLATE_FILES['tmp_dir']) mdFile = createTemporaryCopy(TEMPLATE_FILES['child'], tmpDirectory) mdEditor = ChildMetadataBinding(mdFile, self.logger) response = mdEditor.updateGraphicOverview(updateValue) self.assertTrue(response, 'Function: testUpdateGraphicOverview - Response is not like expected.') # check if value is correctly set xmlHierarchy = [ mdEditor.ns['gmd']+'identificationInfo', mdEditor.ns['gmd']+'MD_DataIdentification', mdEditor.ns['gmd']+'graphicOverview', mdEditor.ns['gmd']+'MD_BrowseGraphic', mdEditor.ns['gmd']+'fileName', mdEditor.ns['gco']+'CharacterString' ] valueElements = mdEditor.root.findall('/'.join(xmlHierarchy)) self.assertTrue(len(valueElements) == 1, 'Function: testUpdateGraphicOverview - Response has not the expected length') self.assertEqual(valueElements[0].text,updateValue[0], 'Function: testUpdateGraphicOverview - Response is not equal to the expected response.') #self.assertEqual(valueElements[1].text,updateValue[1], 'Function: testUpdateGraphicOverview - Response is not equal to the expected response.') #self.assertEqual(valueElements[2].text,updateValue[2], 'Function: testUpdateGraphicOverview - Response is not equal to the expected response.') except: raise finally: shutil.rmtree(tmpDirectory)