Skip to content

Commit

Permalink
More preparation to also check change records
Browse files Browse the repository at this point in the history
  • Loading branch information
stroeder committed Feb 29, 2016
1 parent d48b822 commit e8a55d2
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions Tests/t_ldif.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
See http://www.python-ldap.org/ for details.
$Id: t_ldif.py,v 1.15 2016/02/29 18:56:43 stroeder Exp $
$Id: t_ldif.py,v 1.16 2016/02/29 22:44:42 stroeder Exp $
"""

# from Python's standard lib
Expand Down Expand Up @@ -45,7 +45,7 @@ def parse_records(

def unparse_records(records):
"""
Returns LDIF string with entry records from list `entry_records'
Returns LDIF string with entry records from list `records'
"""
ldif_file = StringIO()
ldif_writer = ldif.LDIFWriter(ldif_file)
Expand All @@ -59,35 +59,44 @@ class TestEntryRecords(unittest.TestCase):
Various LDIF test cases
"""

def check_entry_records(
def check_records(
self,
ldif_string,
entry_records,
records,
record_type='entry',
ignored_attr_types=None,
max_entries=0
):
"""
Checks whether entry records in `ldif_string' gets correctly parsed
and matches list of unparsed `entry_records'.
and matches list of unparsed `records'.
"""
ldif_string = textwrap.dedent(ldif_string).lstrip() + '\n'
parsed_entry_records = parse_records(
parsed_records = parse_records(
ldif_string,
record_type='entry',
record_type=record_type,
ignored_attr_types=ignored_attr_types,
max_entries=max_entries,
)
parsed_entry_records2 = parse_records(
unparse_records(entry_records),
record_type='entry',
parsed_records2 = parse_records(
unparse_records(records),
record_type=record_type,
ignored_attr_types=ignored_attr_types,
max_entries=max_entries,
)
self.assertEqual(parsed_entry_records, entry_records)
self.assertEqual(parsed_entry_records2, entry_records)
self.assertEqual(parsed_records, records)
self.assertEqual(parsed_records2, records)

def test_empty(self):
self.check_records(
"""
version: 1
""",
[]
)

def test_simple(self):
self.check_entry_records(
self.check_records(
"""
version: 1
Expand All @@ -106,7 +115,7 @@ def test_simple(self):
)

def test_simple2(self):
self.check_entry_records(
self.check_records(
"""
dn:cn=x,cn=y,cn=z
attrib:value
Expand All @@ -123,7 +132,7 @@ def test_simple2(self):
)

def test_multiple(self):
self.check_entry_records(
self.check_records(
"""
dn: cn=x,cn=y,cn=z
a: v
Expand Down Expand Up @@ -154,7 +163,7 @@ def test_multiple(self):
)

def test_folded(self):
self.check_entry_records(
self.check_records(
"""
dn: cn=x,cn=y,cn=z
attrib: very\x20
Expand All @@ -174,7 +183,7 @@ def test_folded(self):
)

def test_empty(self):
self.check_entry_records(
self.check_records(
"""
dn: cn=x,cn=y,cn=z
attrib1:
Expand All @@ -194,7 +203,7 @@ def test_empty(self):
)

def test_binary(self):
self.check_entry_records(
self.check_records(
"""
dn: cn=x,cn=y,cn=z
attrib:: CQAKOiVA
Expand All @@ -210,7 +219,7 @@ def test_binary(self):
)

def test_binary2(self):
self.check_entry_records(
self.check_records(
"""
dn: cn=x,cn=y,cn=z
attrib::CQAKOiVA
Expand All @@ -224,7 +233,7 @@ def test_binary2(self):
)

def test_unicode(self):
self.check_entry_records(
self.check_records(
"""
dn: cn=Michael Stroeder,dc=stroeder,dc=com
lastname: Ströder
Expand All @@ -238,7 +247,7 @@ def test_unicode(self):
)

def test_sorted(self):
self.check_entry_records(
self.check_records(
"""
dn: cn=x,cn=y,cn=z
b: value_b
Expand All @@ -258,7 +267,7 @@ def test_sorted(self):
)

def test_ignored_attr_types(self):
self.check_entry_records(
self.check_records(
"""
dn: cn=x,cn=y,cn=z
a: value_a
Expand All @@ -278,7 +287,7 @@ def test_ignored_attr_types(self):
)

def test_comments(self):
self.check_entry_records(
self.check_records(
"""
# comment #1
with line-folding
Expand Down Expand Up @@ -316,7 +325,7 @@ def test_comments(self):
)

def test_max_entries(self):
self.check_entry_records(
self.check_records(
"""
dn: cn=x1,cn=y1,cn=z1
b1: value_b1
Expand Down Expand Up @@ -358,7 +367,7 @@ def test_multiple_empty_lines(self):
"""
see http://sourceforge.net/p/python-ldap/feature-requests/18/
"""
self.check_entry_records(
self.check_records(
"""
# normal
dn: uid=one,dc=tld
Expand Down

0 comments on commit e8a55d2

Please sign in to comment.