Skip to content

Commit a3bf453

Browse files
committed
Added 2 tests more
* Check the new feature to add an xmlstring directly * Check the function to clean an XML
1 parent 7f2c33e commit a3bf453

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

tests/test_libcomxml.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from . import unittest
33
import locale
44
import re
5-
from libcomxml.core import XmlField, XmlModel
5+
from libcomxml.core import XmlField, XmlModel, clean_xml
66

77

88
class Cd(XmlModel):
@@ -24,6 +24,31 @@ def __init__(self):
2424
super(Catalog, self).__init__('CATALOG', 'catalog')
2525

2626

27+
class TestCleaned(unittest.TestCase):
28+
def setUp(self):
29+
self.xml = "<?xml version='1.0' encoding='UTF-8'?>\n"
30+
self.xml += """
31+
<CATALOG>
32+
<CD>
33+
<ARTIST>Bob Dylan</ARTIST>
34+
<ARTIST>Bob Dylan</ARTIST>
35+
<COMPANY>Columbia</COMPANY>
36+
<TITLE>Empire Burlesque</TITLE>
37+
<YEAR>1985</YEAR>
38+
<PRICE>10.9</PRICE>
39+
</CD>
40+
</CATALOG>"""
41+
self.cleaned_xml = "<?xml version='1.0' encoding='UTF-8'?>"
42+
self.cleaned_xml += "<CATALOG><CD><ARTIST>Bob Dylan</ARTIST>"
43+
self.cleaned_xml += "<ARTIST>Bob Dylan</ARTIST>"
44+
self.cleaned_xml += "<COMPANY>Columbia</COMPANY>"
45+
self.cleaned_xml += "<TITLE>Empire Burlesque</TITLE><YEAR>1985</YEAR>"
46+
self.cleaned_xml += "<PRICE>10.9</PRICE></CD></CATALOG>"
47+
48+
def test_clean(self):
49+
self.assertEqual(clean_xml(self.xml), self.cleaned_xml)
50+
51+
2752
class TestFields(unittest.TestCase):
2853
def setUp(self):
2954
self.field = XmlField('Quantity', '10000', attributes={'uom': 'unit'})
@@ -76,6 +101,14 @@ def setUp(self):
76101
<YEAR>1988</YEAR>
77102
<PRICE>9.9</PRICE>
78103
</CD>
104+
<CD>
105+
<TITLE>Tupelo Honey</TITLE>
106+
<ARTIST>Van Morrison</ARTIST>
107+
<COUNTRY>UK</COUNTRY>
108+
<COMPANY>Polydor</COMPANY>
109+
<PRICE>8.20</PRICE>
110+
<YEAR>1971</YEAR>
111+
</CD>
79112
</CATALOG>""")
80113
self.catalog = Catalog()
81114
cd = Cd()
@@ -99,7 +132,16 @@ def setUp(self):
99132
'year': 1988
100133
})
101134
self.catalog.cds.append(cd)
135+
cd = """<CD>
136+
<TITLE>Tupelo Honey</TITLE>
137+
<ARTIST>Van Morrison</ARTIST>
138+
<COUNTRY>UK</COUNTRY>
139+
<COMPANY>Polydor</COMPANY>
140+
<PRICE>8.20</PRICE>
141+
<YEAR>1971</YEAR>
142+
</CD>"""
143+
self.catalog.cds.append(cd)
102144
self.catalog.build_tree()
103145

104146
def test_xml(self):
105-
self.assertEqual(str(self.catalog), self.xml)
147+
self.assertEqual(str(self.catalog), self.xml)

0 commit comments

Comments
 (0)