Skip to content

Commit c5ad802

Browse files
tiranencukou
authored andcommitted
Run tests without SASL and TLS bindings
Also fixes tests when _ldap extension is compiled without SASL support. #91 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 9f86c06 commit c5ad802

File tree

8 files changed

+72
-10
lines changed

8 files changed

+72
-10
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ matrix:
3434
env:
3535
- TOXENV=py36
3636
- WITH_GCOV=1
37+
- python: 2.7
38+
env:
39+
- TOXENV=py2-nosasltls
40+
- WITH_GCOV=1
41+
- python: 3.6
42+
env:
43+
- TOXENV=py3-nosasltls
44+
- WITH_GCOV=1
3745
- python: 3.6
3846
env: TOXENV=doc
3947

Doc/contributing.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ for checking things independent of the Python version:
146146
* ``doc`` checks syntax and spelling of the documentation
147147
* ``coverage-report`` generates a test coverage report for Python code.
148148
It must be used last, e.g. ``tox -e py27,py36,coverage-report``.
149+
* ``py2-nosasltls`` and ``py3-nosasltls`` check functionality without
150+
SASL and TLS bindings compiled in.
149151

150152

151153
When your change is ready, commit to Git, and submit a pull request on GitHub.

Lib/slapdtest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
__version__ = '3.0.0b1'
99

1010
from slapdtest._slapdtest import SlapdObject, SlapdTestCase, SysLogHandler
11-
from slapdtest._slapdtest import skip_unless_ci, requires_tls
11+
from slapdtest._slapdtest import skip_unless_ci, requires_sasl, requires_tls

Lib/slapdtest/_slapdtest.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,16 @@ def identity(test_item):
6464
return test_item
6565

6666

67-
def skip_unless_ci(reason):
67+
def skip_unless_ci(reason, feature=None):
6868
"""Skip test unless test case is executed on CI like Travis CI
6969
"""
70-
if os.environ.get('CI', False):
71-
return identity
72-
else:
70+
if not os.environ.get('CI', False):
71+
return unittest.skip(reason)
72+
elif feature in os.environ.get('CI_DISABLED', '').split(':'):
7373
return unittest.skip(reason)
74+
else:
75+
# Don't skip on Travis
76+
return identity
7477

7578

7679
def requires_tls(skip_nss=False):
@@ -81,16 +84,25 @@ def requires_tls(skip_nss=False):
8184
:param skip_nss: Skip test when libldap is compiled with NSS as TLS lib
8285
"""
8386
if not ldap.TLS_AVAIL:
84-
return skip_unless_ci("test needs ldap.TLS_AVAIL")
87+
return skip_unless_ci("test needs ldap.TLS_AVAIL", feature='TLS')
8588
elif skip_nss and ldap.get_option(ldap.OPT_X_TLS_PACKAGE) == 'MozNSS':
8689
return skip_unless_ci(
8790
"Test doesn't work correctly with Mozilla NSS, see "
88-
"https://bugzilla.redhat.com/show_bug.cgi?id=1519167"
91+
"https://bugzilla.redhat.com/show_bug.cgi?id=1519167",
92+
feature="NSS"
8993
)
9094
else:
9195
return identity
9296

9397

98+
def requires_sasl():
99+
if not ldap.SASL_AVAIL:
100+
return skip_unless_ci(
101+
"test needs ldap.SASL_AVAIL", feature='SASL')
102+
else:
103+
return identity
104+
105+
94106
def combined_logger(
95107
log_name,
96108
log_level=logging.WARN,

Tests/t_cext.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,21 @@ def test_constants(self):
212212
self.assertNotNone(_ldap.URL_ERR_BADSCOPE)
213213
self.assertNotNone(_ldap.URL_ERR_MEM)
214214

215+
def test_test_flags(self):
216+
# test flag, see slapdtest and tox.ini
217+
disabled = os.environ.get('CI_DISABLED')
218+
if not disabled:
219+
self.skipTest("No CI_DISABLED env var")
220+
disabled = set(disabled.split(':'))
221+
if 'TLS' in disabled:
222+
self.assertFalse(_ldap.TLS_AVAIL)
223+
else:
224+
self.assertFalse(_ldap.TLS_AVAIL)
225+
if 'SASL' in disabled:
226+
self.assertFalse(_ldap.SASL_AVAIL)
227+
else:
228+
self.assertFalse(_ldap.SASL_AVAIL)
229+
215230
def test_simple_bind(self):
216231
l = self._open_conn()
217232

Tests/t_ldap_sasl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from ldap.ldapobject import SimpleLDAPObject
1616
import ldap.sasl
17-
from slapdtest import SlapdTestCase, requires_tls
17+
from slapdtest import SlapdTestCase, requires_sasl, requires_tls
1818

1919

2020
LDIF = """
@@ -39,6 +39,7 @@
3939
"""
4040

4141

42+
@requires_sasl()
4243
class TestSasl(SlapdTestCase):
4344
ldap_object_class = SimpleLDAPObject
4445
# from Tests/certs/client.pem

Tests/t_ldapobject.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import os
2020
import unittest
2121
import pickle
22-
from slapdtest import SlapdTestCase
22+
from slapdtest import SlapdTestCase, requires_sasl
2323

2424
# Switch off processing .ldaprc or ldap.conf before importing _ldap
2525
os.environ['LDAPNOINIT'] = '1'
@@ -298,6 +298,7 @@ def test005_invalid_credentials(self):
298298
else:
299299
self.fail("expected INVALID_CREDENTIALS, got %r" % r)
300300

301+
@requires_sasl()
301302
def test006_sasl_extenal_bind_s(self):
302303
l = self.ldap_object_class(self.server.ldapi_uri)
303304
l.sasl_external_bind_s()
@@ -322,6 +323,7 @@ class Test01_ReconnectLDAPObject(Test00_SimpleLDAPObject):
322323

323324
ldap_object_class = ReconnectLDAPObject
324325

326+
@requires_sasl()
325327
def test101_reconnect_sasl_external(self):
326328
l = self.ldap_object_class(self.server.ldapi_uri)
327329
l.sasl_external_bind_s()

tox.ini

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
[tox]
77
# Note: when updating Python versions, also change setup.py and .travis.yml
8-
envlist = py27,py33,py34,py35,py36,doc,coverage-report
8+
envlist = py27,py33,py34,py35,py36,{py2,py3}-nosasltls,doc,coverage-report
9+
minver = 1.8
910

1011
[testenv]
1112
deps = coverage
@@ -21,9 +22,30 @@ commands = {envpython} -bb -Werror \
2122

2223
[testenv:py27]
2324
# No warnings with Python 2.7
25+
passenv = {[testenv]passenv}
2426
commands = {envpython} \
2527
-m coverage run --parallel setup.py test
2628

29+
[testenv:py2-nosasltls]
30+
basepython = python2
31+
deps = {[testenv]deps}
32+
passenv = {[testenv]passenv}
33+
setenv =
34+
CI_DISABLED=TLS:SASL
35+
# rebuild without SASL and TLS
36+
commands = {envpython} \
37+
-m coverage run --parallel setup.py \
38+
clean --all \
39+
build_ext -UHAVE_SASL,HAVE_TLS \
40+
test
41+
42+
[testenv:py3-nosasltls]
43+
basepython = python3
44+
deps = {[testenv]deps}
45+
passenv = {[testenv]passenv}
46+
setenv = {[testenv:py2-nosasltls]setenv}
47+
commands = {[testenv:py2-nosasltls]commands}
48+
2749
[testenv:coverage-report]
2850
deps = coverage
2951
skip_install = true

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy