Always compare parsed lists and not LDIF strings
This commit is contained in:
parent
c74ad89845
commit
4d09415f22
|
@ -15,29 +15,24 @@ except ImportError:
|
|||
class TestParse(unittest.TestCase):
|
||||
maxDiff = None
|
||||
|
||||
def check_ldif_to_records(self, ldif_string, expected):
|
||||
#import pdb; pdb.set_trace()
|
||||
got = ldif.ParseLDIF(StringIO(ldif_string))
|
||||
self.assertEqual(got, expected)
|
||||
def _parse_entry_records(self, ldif_string):
|
||||
return ldif.ParseLDIF(StringIO(ldif_string))
|
||||
|
||||
def check_records_to_ldif(self, records, expected):
|
||||
def _unparse_entry_records(self, records):
|
||||
f = StringIO()
|
||||
ldif_writer = ldif.LDIFWriter(f)
|
||||
for dn, attrs in records:
|
||||
ldif_writer.unparse(dn, attrs)
|
||||
got = f.getvalue()
|
||||
self.assertEqual(got, expected)
|
||||
return f.getvalue()
|
||||
|
||||
def check_roundtrip(self, ldif_source, records, ldif_expected=None):
|
||||
def check_roundtrip(self, ldif_source, entry_records):
|
||||
ldif_source = textwrap.dedent(ldif_source).lstrip() + '\n'
|
||||
if ldif_expected is None:
|
||||
ldif_expected = ldif_source
|
||||
else:
|
||||
ldif_expected = textwrap.dedent(ldif_expected).lstrip() + '\n'
|
||||
|
||||
self.check_ldif_to_records(ldif_source, records)
|
||||
self.check_records_to_ldif(records, ldif_expected)
|
||||
self.check_ldif_to_records(ldif_expected, records)
|
||||
parsed_entry_records = self._parse_entry_records(ldif_source)
|
||||
parsed_entry_records2 = self._parse_entry_records(
|
||||
self._unparse_entry_records(entry_records)
|
||||
)
|
||||
self.assertEqual(parsed_entry_records, entry_records)
|
||||
self.assertEqual(parsed_entry_records2, entry_records)
|
||||
|
||||
def test_simple(self):
|
||||
self.check_roundtrip("""
|
||||
|
@ -48,6 +43,15 @@ class TestParse(unittest.TestCase):
|
|||
('cn=x,cn=y,cn=z', {'attrib': [b'value', b'value2']}),
|
||||
])
|
||||
|
||||
def test_simple2(self):
|
||||
self.check_roundtrip("""
|
||||
dn:cn=x,cn=y,cn=z
|
||||
attrib:value
|
||||
attrib:value2
|
||||
""", [
|
||||
('cn=x,cn=y,cn=z', {'attrib': [b'value', b'value2']}),
|
||||
])
|
||||
|
||||
def test_multiple(self):
|
||||
self.check_roundtrip("""
|
||||
dn: cn=x,cn=y,cn=z
|
||||
|
@ -74,12 +78,7 @@ class TestParse(unittest.TestCase):
|
|||
""" % ('asdf.' * 20), [
|
||||
('cn=x,cn=y,cn=z', {'attrib': [b'verylong value'],
|
||||
'attrib2': [b'asdf.' * 20]}),
|
||||
], """
|
||||
dn: cn=x,cn=y,cn=z
|
||||
attrib: verylong value
|
||||
attrib2: asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.as
|
||||
df.asdf.asdf.asdf.asdf.asdf.asdf.
|
||||
""")
|
||||
])
|
||||
|
||||
def test_empty(self):
|
||||
self.check_roundtrip("""
|
||||
|
@ -105,10 +104,7 @@ class TestParse(unittest.TestCase):
|
|||
""", [
|
||||
('cn=Michael Stroeder,dc=stroeder,dc=com',
|
||||
{'lastname': [b'Str\303\266der']}),
|
||||
], """
|
||||
dn: cn=Michael Stroeder,dc=stroeder,dc=com
|
||||
lastname:: U3Ryw7ZkZXI=
|
||||
""")
|
||||
])
|
||||
|
||||
def test_sorted(self):
|
||||
self.check_roundtrip("""
|
||||
|
@ -120,12 +116,7 @@ class TestParse(unittest.TestCase):
|
|||
('cn=x,cn=y,cn=z', {'a': [b'value_a'],
|
||||
'b': [b'value_b'],
|
||||
'c': [b'value_c']}),
|
||||
], """
|
||||
dn: cn=x,cn=y,cn=z
|
||||
a: value_a
|
||||
b: value_b
|
||||
c: value_c
|
||||
""")
|
||||
])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue