##// END OF EJS Templates
fixed ldap tests when ldap lib is installed
marcink -
r3674:ff2ea58d beta
parent child Browse files
Show More
@@ -341,10 +341,7 b' def LdapSettingsForm(tls_reqcert_choices'
341 341 ldap_base_dn = v.UnicodeString(strip=True,)
342 342 ldap_filter = v.UnicodeString(strip=True,)
343 343 ldap_search_scope = v.OneOf(search_scope_choices)
344 ldap_attr_login = All(
345 v.AttrLoginValidator(),
346 v.UnicodeString(strip=True,)
347 )
344 ldap_attr_login = v.AttrLoginValidator()(not_empty=True)
348 345 ldap_attr_firstname = v.UnicodeString(strip=True,)
349 346 ldap_attr_lastname = v.UnicodeString(strip=True,)
350 347 ldap_attr_email = v.UnicodeString(strip=True,)
@@ -723,13 +723,7 b' def AttrLoginValidator():'
723 723 'this is the name of the attribute that is equivalent '
724 724 'to "username"')
725 725 }
726
727 def validate_python(self, value, state):
728 if not value or not isinstance(value, (str, unicode)):
729 msg = M(self, 'invalid_cn', state)
730 raise formencode.Invalid(msg, value, state,
731 error_dict=dict(ldap_attr_login=msg)
732 )
726 messages['empty'] = messages['invalid_cn']
733 727
734 728 return _validator
735 729
@@ -52,7 +52,7 b' log = logging.getLogger(__name__)'
52 52
53 53 __all__ = [
54 54 'parameterized', 'environ', 'url', 'get_new_dir', 'TestController',
55 'SkipTest',
55 'SkipTest', 'ldap_lib_installed',
56 56 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO',
57 57 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS',
58 58 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS',
@@ -117,6 +117,15 b" TEST_REPO_PREFIX = 'vcs-test'"
117 117 GIT_REMOTE_REPO = jn(TESTS_TMP_PATH, GIT_REPO)
118 118 HG_REMOTE_REPO = jn(TESTS_TMP_PATH, HG_REPO)
119 119
120 #skip ldap tests if LDAP lib is not installed
121 ldap_lib_installed = False
122 try:
123 import ldap
124 ldap_lib_installed = True
125 except ImportError:
126 # means that python-ldap is not installed
127 pass
128
120 129
121 130 def get_new_dir(title):
122 131 """
@@ -1,15 +1,6 b''
1 1 from rhodecode.tests import *
2 2 from rhodecode.model.db import RhodeCodeSetting
3 3
4 skip_ldap_test = False
5 try:
6 import ldap
7 except ImportError:
8 # means that python-ldap is not installed
9 skip_ldap_test = True
10 pass
11
12
13 4 class TestLdapSettingsController(TestController):
14 5
15 6 def test_index(self):
@@ -20,7 +11,7 b' class TestLdapSettingsController(TestCon'
20 11
21 12 def test_ldap_save_settings(self):
22 13 self.log_user()
23 if skip_ldap_test:
14 if ldap_lib_installed:
24 15 raise SkipTest('skipping due to missing ldap lib')
25 16
26 17 test_url = url(controller='admin/ldap_settings',
@@ -48,9 +39,9 b' class TestLdapSettingsController(TestCon'
48 39 self.checkSessionFlash(response,
49 40 'LDAP settings updated successfully')
50 41
51 def test_ldap_error_form(self):
42 def test_ldap_error_form_wrong_port_number(self):
52 43 self.log_user()
53 if skip_ldap_test:
44 if ldap_lib_installed:
54 45 raise SkipTest('skipping due to missing ldap lib')
55 46
56 47 test_url = url(controller='admin/ldap_settings',
@@ -58,7 +49,33 b' class TestLdapSettingsController(TestCon'
58 49
59 50 response = self.app.post(url=test_url,
60 51 params={'ldap_host' : '',
61 'ldap_port' : 'i-should-be-number',
52 'ldap_port': 'i-should-be-number', # bad port num
53 'ldap_tls_kind': 'PLAIN',
54 'ldap_tls_reqcert': 'NEVER',
55 'ldap_dn_user': '',
56 'ldap_dn_pass': '',
57 'ldap_base_dn': '',
58 'ldap_filter': '',
59 'ldap_search_scope': 'BASE',
60 'ldap_attr_login': '',
61 'ldap_attr_firstname': '',
62 'ldap_attr_lastname': '',
63 'ldap_attr_email': ''})
64
65 response.mustcontain("""<span class="error-message">"""
66 """Please enter a number</span><br />""")
67
68 def test_ldap_error_form(self):
69 self.log_user()
70 if ldap_lib_installed:
71 raise SkipTest('skipping due to missing ldap lib')
72
73 test_url = url(controller='admin/ldap_settings',
74 action='ldap_settings')
75
76 response = self.app.post(url=test_url,
77 params={'ldap_host': 'Host',
78 'ldap_port': '123',
62 79 'ldap_tls_kind' : 'PLAIN',
63 80 'ldap_tls_reqcert' : 'NEVER',
64 81 'ldap_dn_user':'',
@@ -74,10 +91,6 b' class TestLdapSettingsController(TestCon'
74 91 response.mustcontain("""<span class="error-message">The LDAP Login"""
75 92 """ attribute of the CN must be specified""")
76 93
77
78 response.mustcontain("""<span class="error-message">Please """
79 """enter a number</span>""")
80
81 94 def test_ldap_login(self):
82 95 pass
83 96
@@ -220,12 +220,16 b' class TestReposGroups(unittest.TestCase)'
220 220 self.assertRaises(formencode.Invalid, validator.to_python, 'err')
221 221
222 222 def test_LdapLibValidator(self):
223 if ldap_lib_installed:
224 validator = v.LdapLibValidator()
225 self.assertEqual("DN", validator.to_python('DN'))
226 else:
223 227 validator = v.LdapLibValidator()
224 228 self.assertRaises(v.LdapImportError, validator.to_python, 'err')
225 229
226 230 def test_AttrLoginValidator(self):
227 231 validator = v.AttrLoginValidator()
228 self.assertRaises(formencode.Invalid, validator.to_python, 123)
232 self.assertEqual('DN_attr', validator.to_python('DN_attr'))
229 233
230 234 def test_NotReviewedRevisions(self):
231 235 repo_id = Repository.get_by_repo_name(HG_REPO).repo_id
General Comments 0
You need to be logged in to leave comments. Login now