Skip to content
Snippets Groups Projects
Commit d2312596 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

ENH: Remove TransactionBenchmark from hased xml

parent ff6da0ca
No related branches found
No related tags found
1 merge request!22Release 0.3
...@@ -29,9 +29,8 @@ import os ...@@ -29,9 +29,8 @@ import os
import sqlite3 import sqlite3
from hashlib import sha256 from hashlib import sha256
from lxml import etree
import caosdb as db import caosdb as db
from lxml import etree
def put_in_container(stuff): def put_in_container(stuff):
...@@ -44,11 +43,23 @@ def put_in_container(stuff): ...@@ -44,11 +43,23 @@ def put_in_container(stuff):
return 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): def get_pretty_xml(cont):
cont = put_in_container(cont) cont = put_in_container(cont)
xml = cont.to_xml(local_serialization=True)
cleanXML(xml)
return etree.tounicode(cont.to_xml( return etree.tounicode(xml, pretty_print=True)
local_serialization=True), pretty_print=True)
class Cache(object): class Cache(object):
......
...@@ -26,8 +26,8 @@ from copy import deepcopy ...@@ -26,8 +26,8 @@ from copy import deepcopy
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
import caosdb as db import caosdb as db
from caosadvancedtools.cache import Cache, cleanXML
from caosadvancedtools.cache import Cache from lxml import etree
class CacheTest(unittest.TestCase): class CacheTest(unittest.TestCase):
...@@ -75,3 +75,19 @@ class CacheTest(unittest.TestCase): ...@@ -75,3 +75,19 @@ class CacheTest(unittest.TestCase):
self.cache.insert_list(hashes, entities) self.cache.insert_list(hashes, entities)
self.assertEqual(self.cache.check_existing(hashes[0]), 1001) self.assertEqual(self.cache.check_existing(hashes[0]), 1001)
self.assertEqual(self.cache.check_existing(hashes[2]), 1003) 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment