cherrypy-foundation 1.0.0a11__py3-none-any.whl → 1.0.0a12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,7 +63,7 @@ def first_attribute(attributes, keys, default=None):
63
63
  value = attributes[attr]
64
64
  if isinstance(value, list):
65
65
  if len(value) == 0:
66
- pass
66
+ continue
67
67
  return value[0]
68
68
  else:
69
69
  return value
@@ -19,13 +19,13 @@ Created on Oct 17, 2015
19
19
  @author: Patrik Dufresne <patrik@ikus-soft.com>
20
20
  """
21
21
  import os
22
- from unittest import mock, skipUnless
22
+ from unittest import TestCase, mock, skipUnless
23
23
 
24
24
  import cherrypy
25
25
  import ldap3
26
26
  from cherrypy.test import helper
27
27
 
28
- from .. import ldap # noqa
28
+ from ..ldap import all_attribute, first_attribute # noqa
29
29
 
30
30
  original_connection = ldap3.Connection
31
31
 
@@ -35,6 +35,79 @@ def mock_ldap_connection(*args, **kwargs):
35
35
  return original_connection(*args, client_strategy=ldap3.MOCK_ASYNC, **kwargs)
36
36
 
37
37
 
38
+ class LdapFirstAttributeTest(TestCase):
39
+
40
+ def test_no_keys_returns_default(self):
41
+ attributes = {"cn": ["John Doe"]}
42
+ self.assertIsNone(first_attribute(attributes, None))
43
+ self.assertEqual(first_attribute(attributes, [], default="fallback"), "fallback")
44
+
45
+ def test_single_key_with_scalar_value(self):
46
+ attributes = {"uid": "jdoe"}
47
+ self.assertEqual(first_attribute(attributes, "uid"), "jdoe")
48
+
49
+ def test_single_key_with_list_value(self):
50
+ attributes = {"mail": ["john@example.com", "alt@example.com"]}
51
+ self.assertEqual(first_attribute(attributes, "mail"), "john@example.com")
52
+
53
+ def test_empty_list_value_is_skipped(self):
54
+ attributes = {
55
+ "mail": [],
56
+ "uid": ["jdoe"],
57
+ }
58
+ self.assertEqual(first_attribute(attributes, ["mail", "uid"]), "jdoe")
59
+
60
+ def test_missing_first_key_uses_next_key(self):
61
+ attributes = {"cn": ["John Doe"]}
62
+ self.assertEqual(first_attribute(attributes, ["sn", "cn"]), "John Doe")
63
+
64
+ def test_all_keys_missing_returns_default(self):
65
+ attributes = {"cn": ["John Doe"]}
66
+ self.assertEqual(first_attribute(attributes, ["sn", "uid"], default="unknown"), "unknown")
67
+
68
+ def test_key_not_found_without_default_returns_none(self):
69
+ attributes = {"cn": ["John Doe"]}
70
+ self.assertIsNone(first_attribute(attributes, "uid"))
71
+
72
+
73
+ class LdapAllAttributeTest(TestCase):
74
+
75
+ def test_no_keys_returns_default(self):
76
+ attributes = {"cn": ["John Doe"]}
77
+ self.assertIsNone(all_attribute(attributes, None))
78
+ self.assertEqual(all_attribute(attributes, [], default="fallback"), "fallback")
79
+
80
+ def test_single_key_with_scalar_value(self):
81
+ attributes = {"uid": "jdoe"}
82
+ self.assertEqual(all_attribute(attributes, "uid"), ["jdoe"])
83
+
84
+ def test_single_key_with_list_value(self):
85
+ attributes = {"mail": ["john@example.com", "alt@example.com"]}
86
+ self.assertEqual(all_attribute(attributes, "mail"), ["john@example.com"])
87
+
88
+ def test_multiple_keys_collect_values(self):
89
+ attributes = {
90
+ "uid": "jdoe",
91
+ "cn": ["John Doe"],
92
+ }
93
+ self.assertEqual(all_attribute(attributes, ["uid", "cn"]), ["jdoe", "John Doe"])
94
+
95
+ def test_missing_keys_are_skipped(self):
96
+ attributes = {"cn": ["John Doe"]}
97
+ self.assertEqual(all_attribute(attributes, ["sn", "cn", "uid"]), ["John Doe"])
98
+
99
+ def test_all_keys_missing_returns_default(self):
100
+ attributes = {"cn": ["John Doe"]}
101
+ self.assertEqual(all_attribute(attributes, ["sn", "uid"], default=[]), [])
102
+
103
+ def test_empty_list_value_is_appended_as_empty_list(self):
104
+ attributes = {
105
+ "mail": [],
106
+ "uid": "jdoe",
107
+ }
108
+ self.assertEqual(all_attribute(attributes, ["mail", "uid"]), [[], "jdoe"])
109
+
110
+
38
111
  class LdapPluginTest(helper.CPWebCase):
39
112
 
40
113
  @classmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cherrypy-foundation
3
- Version: 1.0.0a11
3
+ Version: 1.0.0a12
4
4
  Summary: CherryPy Foundation
5
5
  Author-email: Patrik Dufresne <patrik@ikus-soft.com>
6
6
  License: GPLv3
@@ -81,13 +81,13 @@ cherrypy_foundation/components/vendor/typeahead/jquery.typeahead.min.css,sha256=
81
81
  cherrypy_foundation/components/vendor/typeahead/jquery.typeahead.min.js,sha256=eFBtgouYdW587kYINWsjkN-UR8GVWAG_fQe1fpJfjOw,47828
82
82
  cherrypy_foundation/plugins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
83
83
  cherrypy_foundation/plugins/db.py,sha256=46S-2kR9BHVYRN9cxWwYfzY2WkpEVBCpx1ubsJolYfA,10108
84
- cherrypy_foundation/plugins/ldap.py,sha256=hehNXGYWLSh_tqqbI_sZdFGjC9uJAyeZ-vMNPai9s_w,9909
84
+ cherrypy_foundation/plugins/ldap.py,sha256=PxZp-2tHy73CegiIV5pKnfWe0WOCqNRIYQR8aIh1UEs,9913
85
85
  cherrypy_foundation/plugins/restapi.py,sha256=S5GIxHL0M3Wcs33fyVOb0RfX1FXbp2fqUxJ_ufqBrD4,2843
86
86
  cherrypy_foundation/plugins/scheduler.py,sha256=McTR72GGTuW7UZKco_Czmp09PfqJ-aHXJxh7h9BFZvA,10777
87
87
  cherrypy_foundation/plugins/smtp.py,sha256=yTCUj2XzrJEJ84CIbYcrCUAP6Mg59aZfu6OZDGQyJbQ,7479
88
88
  cherrypy_foundation/plugins/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
89
89
  cherrypy_foundation/plugins/tests/test_db.py,sha256=PELi5ojj8VqcXyPbpaig2Ac4ZqlR_gEPGUYrWJPANWg,3921
90
- cherrypy_foundation/plugins/tests/test_ldap.py,sha256=7EhFvhxwDCCBoNlAD5XpZxLtKvkrjpQxrtCHMT9wkQ4,14393
90
+ cherrypy_foundation/plugins/tests/test_ldap.py,sha256=j0QUIxqeEBgN4VLvczUlw0xMM_ldPWVHCceAJzU71Jg,17269
91
91
  cherrypy_foundation/plugins/tests/test_scheduler.py,sha256=I-ZuQhMvCCvqFDwukwsyz_UkdJJ8JSLTkAanUo24GCE,3564
92
92
  cherrypy_foundation/plugins/tests/test_scheduler_db.py,sha256=-iZnLgb3qsJzs0p7JAw6TQswRtExCmHAtYXqRNPZn7U,3101
93
93
  cherrypy_foundation/plugins/tests/test_smtp.py,sha256=qs5yezIpSXkBmLmFlqckfPW7NmntHZxQjDSkdQG_dNE,4183
@@ -126,8 +126,8 @@ cherrypy_foundation/tools/tests/locales/fr/LC_MESSAGES/messages.po,sha256=6_Sk9I
126
126
  cherrypy_foundation/tools/tests/templates/test_jinja2.html,sha256=v9AHxksbBvzE7sesPqE61HMhsvU4juXt3E0ZQo-zXVQ,190
127
127
  cherrypy_foundation/tools/tests/templates/test_jinja2_i18n.html,sha256=98S51dgG7Vb4rvMZNZvomw1D9pBiM4g6pdlxAgvrxXA,373
128
128
  cherrypy_foundation/tools/tests/templates/test_jinjax.html,sha256=NT19UaUzm8FRKOIc6H6HNGPDJU6KATnakd8zf3BCeAs,153
129
- cherrypy_foundation-1.0.0a11.dist-info/licenses/LICENSE.md,sha256=trSLYs5qlaow_bBwsLTRKpmTXsXzFksM_YUCMqrgAJQ,35149
130
- cherrypy_foundation-1.0.0a11.dist-info/METADATA,sha256=01n5K1GISPi32NOQ8r3x1eV6qNd5x7ZS0tpJON9mUe4,2023
131
- cherrypy_foundation-1.0.0a11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
132
- cherrypy_foundation-1.0.0a11.dist-info/top_level.txt,sha256=B1vQPTLYhpKJ6W0JkRCWyAf8RPcnwJWdYxixv75-4ew,20
133
- cherrypy_foundation-1.0.0a11.dist-info/RECORD,,
129
+ cherrypy_foundation-1.0.0a12.dist-info/licenses/LICENSE.md,sha256=trSLYs5qlaow_bBwsLTRKpmTXsXzFksM_YUCMqrgAJQ,35149
130
+ cherrypy_foundation-1.0.0a12.dist-info/METADATA,sha256=bVj-ivyQaks7eDS4cxGDbq0I1OhKXejr5Rq9EUo81xc,2023
131
+ cherrypy_foundation-1.0.0a12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
132
+ cherrypy_foundation-1.0.0a12.dist-info/top_level.txt,sha256=B1vQPTLYhpKJ6W0JkRCWyAf8RPcnwJWdYxixv75-4ew,20
133
+ cherrypy_foundation-1.0.0a12.dist-info/RECORD,,