Permalink
Browse files

Simplified test script

Instead of using a self-written context manager to replace `stdin` with a
string, the `mock` module is used to patch `sys.stdin`
  • Loading branch information...
plettich committed Nov 28, 2018
1 parent 2427347 commit 64c6c6ad4f1b7be62753a9020fe8ecbcb4d61bb0
Showing with 2 additions and 11 deletions.
  1. +2 −11 tests/test_lib_caconnector.py
@@ -4,11 +4,10 @@
"""
from .base import MyTestCase
import os
import sys
import six
import shutil
from io import StringIO
from contextlib import contextmanager
from mock import patch
from privacyidea.lib.caconnectors.localca import LocalCAConnector, ATTR
from OpenSSL import crypto
from privacyidea.lib.utils import int_to_hex
@@ -78,14 +77,6 @@
"emailAddress=steve@openssl.org"
@contextmanager
def replace_stdin(target):
orig = sys.stdin
sys.stdin = target
yield
sys.stdin = orig
class CAConnectorTestCase(MyTestCase):
"""
Test the CA connector lib functions
@@ -300,7 +291,7 @@ def test_01_create_ca(self):
if os.path.exists(workdir):
shutil.rmtree(workdir)
inputstr = six.text_type(workdir + '\n\n\n\n\n\ny\n')
with replace_stdin(StringIO(inputstr)):
with patch('sys.stdin', StringIO(inputstr)):
caconfig = LocalCAConnector.create_ca('localCA2')
self.assertEqual(caconfig.get("WorkingDir"), workdir)
cacon = LocalCAConnector('localCA2', caconfig)

0 comments on commit 64c6c6a

Please sign in to comment.