Skip to content

Commit

Permalink
1. Added TestEntryRecords.test_missing_trailing_line_separator()
Browse files Browse the repository at this point in the history
2. avoid adding trailing new-line in TestLDIFParser.check_records() which masks some corner-cases
3. TestChangeRecords: renamed method test_missing_trailing_separator() to test_missing_trailing_dash_separator()
  • Loading branch information
stroeder committed Jul 27, 2016
1 parent 850add0 commit 810f3aa
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 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.20 2016/07/24 14:57:46 stroeder Exp $
$Id: t_ldif.py,v 1.21 2016/07/27 09:31:30 stroeder Exp $
"""

# from Python's standard lib
Expand Down Expand Up @@ -75,7 +75,7 @@ def check_records(
Checks whether entry records in `ldif_string' gets correctly parsed
and matches list of unparsed `records'.
"""
ldif_string = textwrap.dedent(ldif_string).lstrip() + '\n'
ldif_string = textwrap.dedent(ldif_string).lstrip()
parsed_records = self._parse_records(
ldif_string,
ignored_attr_types=ignored_attr_types,
Expand All @@ -87,8 +87,8 @@ def check_records(
ignored_attr_types=ignored_attr_types,
max_entries=max_entries,
)
self.assertEqual(parsed_records, records)
self.assertEqual(parsed_records2, records)
self.assertEqual(records, parsed_records)
self.assertEqual(records, parsed_records2)


class TestEntryRecords(TestLDIFParser):
Expand All @@ -114,6 +114,7 @@ def test_simple(self):
dn: cn=x,cn=y,cn=z
attrib: value
attrib: value2
""",
[
(
Expand All @@ -131,6 +132,7 @@ def test_simple2(self):
dn:cn=x,cn=y,cn=z
attrib:value
attrib:value2
""",
[
(
Expand All @@ -154,6 +156,7 @@ def test_multiple(self):
attrib: value2
attrib: value3
b: v
""",
[
(
Expand Down Expand Up @@ -182,6 +185,7 @@ def test_folded(self):
line-folded\x20
value
attrib2: %s
""" % (b'asdf.'*20), [
(
'cn=x,cn=y,cn=z',
Expand All @@ -201,6 +205,7 @@ def test_empty_attr_values(self):
attrib1: foo
attrib2:
attrib2: foo
""",
[
(
Expand All @@ -218,6 +223,7 @@ def test_binary(self):
"""
dn: cn=x,cn=y,cn=z
attrib:: CQAKOiVA
""",
[
(
Expand All @@ -234,6 +240,7 @@ def test_binary2(self):
"""
dn: cn=x,cn=y,cn=z
attrib::CQAKOiVA
""",
[
(
Expand All @@ -248,6 +255,7 @@ def test_unicode(self):
"""
dn: cn=Michael Stroeder,dc=stroeder,dc=com
lastname: Ströder
""",
[
(
Expand All @@ -264,6 +272,7 @@ def test_sorted(self):
b: value_b
c: value_c
a: value_a
""",
[
(
Expand All @@ -284,6 +293,7 @@ def test_ignored_attr_types(self):
a: value_a
b: value_b
c: value_c
""",
[
(
Expand Down Expand Up @@ -374,6 +384,39 @@ def test_max_entries(self):
max_entries=2
)

def test_missing_trailing_line_separator(self):
self.check_records(
"""
dn: cn=x1,cn=y1,cn=z1
first: value_a1
middle: value_b1
last: value_c1
dn: cn=x2,cn=y2,cn=z2
first: value_a2
middle: value_b2
last: value_c2
""",
[
(
'cn=x1,cn=y1,cn=z1',
{
'first': [b'value_a1'],
'middle': [b'value_b1'],
'last': [b'value_c1'],
}
),
(
'cn=x2,cn=y2,cn=z2',
{
'first': [b'value_a2'],
'middle': [b'value_b2'],
'last': [b'value_c2'],
}
),
],
)

def test_multiple_empty_lines(self):
"""
see http://sourceforge.net/p/python-ldap/feature-requests/18/
Expand All @@ -385,9 +428,11 @@ def test_multiple_empty_lines(self):
uid: one
# after extra empty line
dn: uid=two,dc=tld
uid: two
""",
[
(
Expand Down Expand Up @@ -452,7 +497,7 @@ def test_simple(self):
],
)

def test_missing_trailing_separator(self):
def test_missing_trailing_dash_separator(self):
self.check_records(
"""
version: 1
Expand All @@ -466,6 +511,7 @@ def test_missing_trailing_separator(self):
add: attrib2
attrib2: value
attrib2: value2
""",
[
(
Expand All @@ -486,6 +532,7 @@ def test_bad_change_records(self):
replace: attrib
attrib: value
attrib: value2
""",
):
ldif_string = textwrap.dedent(bad_ldif_string).lstrip() + '\n'
Expand Down

0 comments on commit 810f3aa

Please sign in to comment.