Skip to content

Commit

Permalink
Allow testing without gssapi and ipaclient
Browse files Browse the repository at this point in the history
Make tests pass without presence of requests_gssapi or ipaclient
package.

Signed-off-by: Christian Heimes <[email protected]>
  • Loading branch information
tiran authored and simo5 committed Jun 25, 2018
1 parent c9463ad commit bb92dee
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 24 deletions.
14 changes: 9 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ addons:
matrix:
include:
- python: 2.7
env: TOXENV=py27
env: TOXENV=py27-extras
- python: 2.7
env: TOXENV=py27-noextras
- python: 3.5
env: TOXENV=py35
env: TOXENV=py35-extras
- python: 3.6
env: TOXENV=py36-extras
- python: 3.6
env: TOXENV=py36-noextras
- python: 3.6
env: TOXENV=py36
- python: 3.5
env: TOXENV=doc
- python: 3.6
env: TOXENV=lint
- python: 2.7
env: TOXENV=pep8py2
- python: 3.5
- python: 3.6
env: TOXENV=pep8py3

before_install:
Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ cscope:
git ls-files | xargs pycscope

test: clean_socket clean_coverage
$(TOX) --skip-missing-interpreters -e py27
$(TOX) --skip-missing-interpreters -e py34
$(TOX) --skip-missing-interpreters -e py35
$(TOX) --skip-missing-interpreters -e py36
$(TOX) --skip-missing-interpreters -e py27-extra,py27-noextra
$(TOX) --skip-missing-interpreters -e py35-extra,py35-noextra
$(TOX) --skip-missing-interpreters -e py36-extra,py36-noextra
$(TOX) --skip-missing-interpreters -e doc
$(TOX) -e coverage-report

Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ def run(self):
]

# test requirements
test_requires = [
'coverage', 'pytest'
] + gssapi_requires + ipa_requires
test_requires = ['coverage', 'pytest']
test_extras_requires = test_requires + gssapi_requires + ipa_requires

extras_require = {
'gssapi': gssapi_requires,
'ipa': ipa_requires,
'test': test_requires,
'test_extras': test_extras_requires,
'test_docs': ['docutils', 'markdown', 'sphinx-argparse',
'sphinxcontrib-spelling'] + ipa_requires,
'test_pep8': ['flake8', 'flake8-import-order', 'pep8-naming'],
'test_pylint': ['pylint'] + test_requires,
'test_pylint': ['pylint'] + test_extras_requires,
}

# backwards compatibility with old setuptools
Expand Down
9 changes: 8 additions & 1 deletion tests/test_custodia.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

import requests.exceptions

import requests_gssapi
try:
import requests_gssapi
except ImportError:
requests_gssapi = None

import six

Expand Down Expand Up @@ -529,6 +532,10 @@ def test_C_client_cert_auth(self):
self.client.del_secret('test/key')


@pytest.mark.skipif(
requests_gssapi is None,
reason="requests_gssapi not available"
)
class CustodiaGSSAPITests(unittest.TestCase):
def test_set_gssapi_auth(self):
client = CustodiaSimpleClient('http://local.example')
Expand Down
27 changes: 19 additions & 8 deletions tests/test_ipa.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization

import ipaclient.plugins.vault

import ipalib
from ipalib.errors import NotFound

import pkg_resources

import pytest

from custodia.compat import configparser
from custodia.ipa.certrequest import IPACertRequest
from custodia.ipa.interface import IPAInterface, IPA_SECTIONNAME
from custodia.ipa.vault import IPAVault, krb5_unparse_principal_name

try:
import ipaclient.plugins.vault
import ipalib
except ImportError:
HAS_IPA = False
NotFound = None
IPACertRequest = None
IPAInterface = IPA_SECTIONNAME = None
IPAVault = krb5_unparse_principal_name = None
else:
HAS_IPA = True
from ipalib.errors import NotFound
from custodia.ipa.certrequest import IPACertRequest
from custodia.ipa.interface import IPAInterface, IPA_SECTIONNAME
from custodia.ipa.vault import IPAVault, krb5_unparse_principal_name

try:
from unittest import mock
Expand Down Expand Up @@ -172,6 +180,7 @@


@pytest.mark.skipif(mock is None, reason='requires mock')
@pytest.mark.skipif(not HAS_IPA, reason='requires ipaclient package')
class BaseTest(object):
def setup_method(self, method):
# pylint: disable=attribute-defined-outside-init
Expand Down Expand Up @@ -399,6 +408,7 @@ def test_get(self):
certreq.get('keys/HTTP/client1.ipa.example')


@pytest.mark.skipif(not HAS_IPA, reason='requires ipaclient package')
@pytest.mark.parametrize('group,name,cls', [
('custodia.stores', 'IPAVault', IPAVault),
('custodia.stores', 'IPACertRequest', IPACertRequest),
Expand All @@ -415,6 +425,7 @@ def test_plugins(group, name, cls, dist='custodia'):
assert resolved is cls


@pytest.mark.skipif(not HAS_IPA, reason='requires ipaclient package')
@pytest.mark.parametrize('principal,result', [
('[email protected]',
(None, 'john', 'IPA.EXAMPLE')),
Expand Down
11 changes: 11 additions & 0 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
from custodia.client import CustodiaHTTPClient
from custodia.plugin import CSStore, HTTPAuthenticator, HTTPAuthorizer

try:
# pylint: disable=unused-import
import ipaclient # noqa: F401
except ImportError:
HAS_IPA = False
else:
HAS_IPA = True


class TestCustodiaPlugins(unittest.TestCase):
project_name = 'custodia'
Expand All @@ -18,6 +26,9 @@ def get_entry_points(self, group):
if e.dist.project_name != self.project_name:
# only interested in our own entry points
continue
if not HAS_IPA and e.module_name.startswith('custodia.ipa'):
# skip IPA plugins when ipaclient isn't installed
continue
eps.append(e)
return eps

Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 2.3.1
envlist = lint,py27,py35,py36,pep8py2,pep8py3,doc,coverage-report
envlist = lint,py{27,35,36}-{extras,noextras},pep8py2,pep8py3,doc,coverage-report
skip_missing_interpreters = true

[testenv]
Expand All @@ -9,7 +9,8 @@ skip_missing_interpreters = true
# CUSTODIAPYTHON = {envpython} -m coverage run --parallel
# passenv = CUSTODIAPYTHON
deps =
.[test]
extras: .[test_extras]
noextras: .[test]
# Makefile and RPM spec set sitepackages=True
sitepackages = False
commands =
Expand Down

0 comments on commit bb92dee

Please sign in to comment.