Mercurial > kallithea
changeset 3674:ff2ea58debb5 beta
fixed ldap tests when ldap lib is installed
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 04 Apr 2013 18:31:15 +0200 |
parents | 28305020a4ed |
children | 7a5b11c23288 |
files | rhodecode/model/forms.py rhodecode/model/validators.py rhodecode/tests/__init__.py rhodecode/tests/functional/test_admin_ldap_settings.py rhodecode/tests/test_validators.py |
diffstat | 5 files changed, 74 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/model/forms.py Thu Apr 04 17:49:03 2013 +0200 +++ b/rhodecode/model/forms.py Thu Apr 04 18:31:15 2013 +0200 @@ -341,10 +341,7 @@ ldap_base_dn = v.UnicodeString(strip=True,) ldap_filter = v.UnicodeString(strip=True,) ldap_search_scope = v.OneOf(search_scope_choices) - ldap_attr_login = All( - v.AttrLoginValidator(), - v.UnicodeString(strip=True,) - ) + ldap_attr_login = v.AttrLoginValidator()(not_empty=True) ldap_attr_firstname = v.UnicodeString(strip=True,) ldap_attr_lastname = v.UnicodeString(strip=True,) ldap_attr_email = v.UnicodeString(strip=True,)
--- a/rhodecode/model/validators.py Thu Apr 04 17:49:03 2013 +0200 +++ b/rhodecode/model/validators.py Thu Apr 04 18:31:15 2013 +0200 @@ -723,13 +723,7 @@ 'this is the name of the attribute that is equivalent ' 'to "username"') } - - def validate_python(self, value, state): - if not value or not isinstance(value, (str, unicode)): - msg = M(self, 'invalid_cn', state) - raise formencode.Invalid(msg, value, state, - error_dict=dict(ldap_attr_login=msg) - ) + messages['empty'] = messages['invalid_cn'] return _validator
--- a/rhodecode/tests/__init__.py Thu Apr 04 17:49:03 2013 +0200 +++ b/rhodecode/tests/__init__.py Thu Apr 04 18:31:15 2013 +0200 @@ -52,7 +52,7 @@ __all__ = [ 'parameterized', 'environ', 'url', 'get_new_dir', 'TestController', - 'SkipTest', + 'SkipTest', 'ldap_lib_installed', 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS', 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS', @@ -117,6 +117,15 @@ GIT_REMOTE_REPO = jn(TESTS_TMP_PATH, GIT_REPO) HG_REMOTE_REPO = jn(TESTS_TMP_PATH, HG_REPO) +#skip ldap tests if LDAP lib is not installed +ldap_lib_installed = False +try: + import ldap + ldap_lib_installed = True +except ImportError: + # means that python-ldap is not installed + pass + def get_new_dir(title): """
--- a/rhodecode/tests/functional/test_admin_ldap_settings.py Thu Apr 04 17:49:03 2013 +0200 +++ b/rhodecode/tests/functional/test_admin_ldap_settings.py Thu Apr 04 18:31:15 2013 +0200 @@ -1,15 +1,6 @@ from rhodecode.tests import * from rhodecode.model.db import RhodeCodeSetting -skip_ldap_test = False -try: - import ldap -except ImportError: - # means that python-ldap is not installed - skip_ldap_test = True - pass - - class TestLdapSettingsController(TestController): def test_index(self): @@ -20,26 +11,26 @@ def test_ldap_save_settings(self): self.log_user() - if skip_ldap_test: + if ldap_lib_installed: raise SkipTest('skipping due to missing ldap lib') test_url = url(controller='admin/ldap_settings', action='ldap_settings') response = self.app.post(url=test_url, - params={'ldap_host' : u'dc.example.com', - 'ldap_port' : '999', - 'ldap_tls_kind' : 'PLAIN', - 'ldap_tls_reqcert' : 'NEVER', - 'ldap_dn_user':'test_user', - 'ldap_dn_pass':'test_pass', - 'ldap_base_dn':'test_base_dn', - 'ldap_filter':'test_filter', - 'ldap_search_scope':'BASE', - 'ldap_attr_login':'test_attr_login', - 'ldap_attr_firstname':'ima', - 'ldap_attr_lastname':'tester', - 'ldap_attr_email':'test@example.com' }) + params={'ldap_host': u'dc.example.com', + 'ldap_port': '999', + 'ldap_tls_kind': 'PLAIN', + 'ldap_tls_reqcert': 'NEVER', + 'ldap_dn_user': 'test_user', + 'ldap_dn_pass': 'test_pass', + 'ldap_base_dn': 'test_base_dn', + 'ldap_filter': 'test_filter', + 'ldap_search_scope': 'BASE', + 'ldap_attr_login': 'test_attr_login', + 'ldap_attr_firstname': 'ima', + 'ldap_attr_lastname': 'tester', + 'ldap_attr_email': 'test@example.com' }) new_settings = RhodeCodeSetting.get_ldap_settings() self.assertEqual(new_settings['ldap_host'], u'dc.example.com', @@ -48,36 +39,58 @@ self.checkSessionFlash(response, 'LDAP settings updated successfully') - def test_ldap_error_form(self): + def test_ldap_error_form_wrong_port_number(self): self.log_user() - if skip_ldap_test: + if ldap_lib_installed: raise SkipTest('skipping due to missing ldap lib') test_url = url(controller='admin/ldap_settings', action='ldap_settings') response = self.app.post(url=test_url, - params={'ldap_host' : '', - 'ldap_port' : 'i-should-be-number', - 'ldap_tls_kind' : 'PLAIN', - 'ldap_tls_reqcert' : 'NEVER', - 'ldap_dn_user':'', - 'ldap_dn_pass':'', - 'ldap_base_dn':'', - 'ldap_filter':'', - 'ldap_search_scope':'BASE', - 'ldap_attr_login':'', # <----- missing required input - 'ldap_attr_firstname':'', - 'ldap_attr_lastname':'', - 'ldap_attr_email':'' }) + params={'ldap_host': '', + 'ldap_port': 'i-should-be-number', # bad port num + 'ldap_tls_kind': 'PLAIN', + 'ldap_tls_reqcert': 'NEVER', + 'ldap_dn_user': '', + 'ldap_dn_pass': '', + 'ldap_base_dn': '', + 'ldap_filter': '', + 'ldap_search_scope': 'BASE', + 'ldap_attr_login': '', + 'ldap_attr_firstname': '', + 'ldap_attr_lastname': '', + 'ldap_attr_email': ''}) + + response.mustcontain("""<span class="error-message">""" + """Please enter a number</span><br />""") + + def test_ldap_error_form(self): + self.log_user() + if ldap_lib_installed: + raise SkipTest('skipping due to missing ldap lib') + + test_url = url(controller='admin/ldap_settings', + action='ldap_settings') + + response = self.app.post(url=test_url, + params={'ldap_host': 'Host', + 'ldap_port': '123', + 'ldap_tls_kind': 'PLAIN', + 'ldap_tls_reqcert': 'NEVER', + 'ldap_dn_user': '', + 'ldap_dn_pass': '', + 'ldap_base_dn': '', + 'ldap_filter': '', + 'ldap_search_scope': 'BASE', + 'ldap_attr_login': '', # <----- missing required input + 'ldap_attr_firstname': '', + 'ldap_attr_lastname': '', + 'ldap_attr_email': ''}) response.mustcontain("""<span class="error-message">The LDAP Login""" """ attribute of the CN must be specified""") - - response.mustcontain("""<span class="error-message">Please """ - """enter a number</span>""") - def test_ldap_login(self): pass
--- a/rhodecode/tests/test_validators.py Thu Apr 04 17:49:03 2013 +0200 +++ b/rhodecode/tests/test_validators.py Thu Apr 04 18:31:15 2013 +0200 @@ -220,12 +220,16 @@ self.assertRaises(formencode.Invalid, validator.to_python, 'err') def test_LdapLibValidator(self): - validator = v.LdapLibValidator() - self.assertRaises(v.LdapImportError, validator.to_python, 'err') + if ldap_lib_installed: + validator = v.LdapLibValidator() + self.assertEqual("DN", validator.to_python('DN')) + else: + validator = v.LdapLibValidator() + self.assertRaises(v.LdapImportError, validator.to_python, 'err') def test_AttrLoginValidator(self): validator = v.AttrLoginValidator() - self.assertRaises(formencode.Invalid, validator.to_python, 123) + self.assertEqual('DN_attr', validator.to_python('DN_attr')) def test_NotReviewedRevisions(self): repo_id = Repository.get_by_repo_name(HG_REPO).repo_id