This repository has been archived by the owner on Jan 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make mock optional and use unittest.mock
The mock package is not available on some target platforms. An optional dependenyc allows us to run a subset of tests on these platforms. Starting with Python 3.3, the mock package is available as unittest.mock. The variant in stdlib is a bit more strict, too. Signed-off-by: Christian Heimes <[email protected]>
- Loading branch information
Showing
2 changed files
with
34 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,6 @@ | |
import ipalib | ||
from ipalib.errors import NotFound | ||
|
||
import mock | ||
|
||
import pkg_resources | ||
|
||
import pytest | ||
|
@@ -22,6 +20,14 @@ | |
from custodia.ipa.interface import IPAInterface | ||
from custodia.ipa.vault import IPAVault, krb5_unparse_principal_name | ||
|
||
try: | ||
from unittest import mock | ||
except ImportError: | ||
try: | ||
import mock | ||
except ImportError: | ||
mock = None | ||
|
||
|
||
CONFIG = u""" | ||
[store:ipa_service] | ||
|
@@ -150,7 +156,6 @@ | |
-----END CERTIFICATE----- | ||
""" | ||
|
||
|
||
vault_parametrize = pytest.mark.parametrize( | ||
'plugin,vault_type,vault_args', | ||
[ | ||
|
@@ -161,6 +166,7 @@ | |
) | ||
|
||
|
||
@pytest.mark.skipif(mock is None, reason='requires mock') | ||
class BaseTest(object): | ||
def setup_method(self, method): | ||
self.parser = configparser.ConfigParser( | ||
|
@@ -218,9 +224,9 @@ def test_api_init(self): | |
|
||
m_api.Backend.rpcclient.isconnected.return_value = False | ||
with ipa: | ||
m_api.Backend.rpcclient.connect.assert_called() | ||
m_api.Backend.rpcclient.connect.assert_any_call() | ||
m_api.Backend.rpcclient.isconnected.return_value = True | ||
m_api.Backend.rpcclient.disconnect.assert_called() | ||
m_api.Backend.rpcclient.disconnect.assert_any_call() | ||
|
||
assert os.environ == dict( | ||
NSS_STRICT_NOFORK='DISABLED', | ||
|
@@ -262,7 +268,7 @@ def test_vault_set(self, plugin, vault_type, vault_args): | |
ipa = self.mkinstance('[email protected]', 'store:ipa_autodiscover') | ||
ipa = IPAVault(self.parser, plugin) | ||
assert ipa.vault_type == vault_type | ||
self.m_api.Command.ping.assert_called_once() | ||
self.m_api.Command.ping.assert_called_once_with() | ||
ipa.set('directory/testkey', 'testvalue') | ||
self.m_api.Command.vault_add.assert_called_once_with( | ||
'directory__testkey', | ||
|