-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for ldap.strf_secs(), ldap.strp_secs() and ldap.escape_str()
- Loading branch information
stroeder
committed
Jul 24, 2016
1 parent
ab1ba33
commit 7fec6bb
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| Automatic tests for module ldap.functions | ||
| """ | ||
|
|
||
| # from Python's standard lib | ||
| import unittest | ||
|
|
||
| # from python-ldap | ||
| import ldap | ||
| from ldap.dn import escape_dn_chars | ||
| from ldap.filter import escape_filter_chars | ||
|
|
||
|
|
||
| class TestFunction(unittest.TestCase): | ||
| """ | ||
| test ldap.functions | ||
| """ | ||
|
|
||
| def test_ldap_strf_secs(self): | ||
| """ | ||
| test function ldap_strf_secs() | ||
| """ | ||
| self.assertEquals(ldap.strf_secs(0), '19700101000000Z') | ||
| self.assertEquals(ldap.strf_secs(1466947067), '20160626131747Z') | ||
|
|
||
| def test_ldap_strp_secs(self): | ||
| """ | ||
| test function ldap_strp_secs() | ||
| """ | ||
| self.assertEquals(ldap.strp_secs('19700101000000Z'), 0) | ||
| self.assertEquals(ldap.strp_secs('20160626131747Z'), 1466947067) | ||
|
|
||
| def test_escape_str(self): | ||
| """ | ||
| test function escape_string_tmpl() | ||
| """ | ||
| self.assertEquals( | ||
| ldap.escape_str( | ||
| escape_filter_chars, | ||
| '(&(objectClass=aeUser)(uid=%s))', | ||
| 'foo' | ||
| ), | ||
| '(&(objectClass=aeUser)(uid=foo))' | ||
| ) | ||
| self.assertEquals( | ||
| ldap.escape_str( | ||
| escape_filter_chars, | ||
| '(&(objectClass=aeUser)(uid=%s))', | ||
| 'foo)bar' | ||
| ), | ||
| '(&(objectClass=aeUser)(uid=foo\\29bar))' | ||
| ) | ||
| self.assertEquals( | ||
| ldap.escape_str( | ||
| escape_dn_chars, | ||
| 'uid=%s', | ||
| 'foo=bar' | ||
| ), | ||
| 'uid=foo\\=bar' | ||
| ) | ||
| self.assertEquals( | ||
| ldap.escape_str( | ||
| escape_dn_chars, | ||
| 'uid=%s,cn=%s,cn=%s,dc=example,dc=com', | ||
| 'foo=bar', | ||
| 'foo+', | ||
| '+bar', | ||
| ), | ||
| 'uid=foo\\=bar,cn=foo\\+,cn=\\+bar,dc=example,dc=com' | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |