diff --git a/src/caosadvancedtools/cache.py b/src/caosadvancedtools/cache.py index bde76abf08cb5a8a7835746d1dcd827cc4b2c071..c255a00d0216c2b944e54158de6910538f3da1ae 100644 --- a/src/caosadvancedtools/cache.py +++ b/src/caosadvancedtools/cache.py @@ -29,9 +29,8 @@ import os import sqlite3 from hashlib import sha256 -from lxml import etree - import caosdb as db +from lxml import etree def put_in_container(stuff): @@ -44,11 +43,23 @@ def put_in_container(stuff): return stuff +def cleanXML(xml): + # remove transaction benchmark + props = xml.findall('TransactionBenchmark') + + for prop in props: + parent = prop.find("..") + parent.remove(prop) + + return xml + + def get_pretty_xml(cont): cont = put_in_container(cont) + xml = cont.to_xml(local_serialization=True) + cleanXML(xml) - return etree.tounicode(cont.to_xml( - local_serialization=True), pretty_print=True) + return etree.tounicode(xml, pretty_print=True) class Cache(object): diff --git a/unittests/test_cache.py b/unittests/test_cache.py index 985ac15ca52a06c6e00c13c6d87adcb8d21f1595..2d7b863fe971dd61a575e24f52853de4f5c4e204 100644 --- a/unittests/test_cache.py +++ b/unittests/test_cache.py @@ -26,8 +26,8 @@ from copy import deepcopy from tempfile import NamedTemporaryFile import caosdb as db - -from caosadvancedtools.cache import Cache +from caosadvancedtools.cache import Cache, cleanXML +from lxml import etree class CacheTest(unittest.TestCase): @@ -75,3 +75,19 @@ class CacheTest(unittest.TestCase): self.cache.insert_list(hashes, entities) self.assertEqual(self.cache.check_existing(hashes[0]), 1001) self.assertEqual(self.cache.check_existing(hashes[2]), 1003) + + def test_clean(self): + xml = etree.XML( + """\ + <Entities> + <TransactionBenchmark> + </TransactionBenchmark> + <RecordType id="110" name="Guitar"> + <Version id="eb8c7527980e598b887e84d055db18cfc3806ce6" head="true"/> + <Parent id="108" name="MusicalInstrument" flag="inheritance:OBLIGATORY,"/> + <Property id="106" name="electric" datatype="BOOLEAN" importance="RECOMMENDED" flag="inheritance:FIX"/> + </RecordType> + </Entities> +""") + cleanXML(xml) + assert len(xml.findall('TransactionBenchmark')) == 0