def test_import_cert(self): ''' Test - Import the certificate file into the given certificate store. ''' kwargs = {'name': CERT_PATH} ret = { 'name': kwargs['name'], 'changes': { 'old': None, 'new': THUMBPRINT }, 'comment': "Certificate '{0}' imported into store: {1}".format(THUMBPRINT, STORE_PATH), 'result': True } mock_cache_file = MagicMock(return_value=CERT_PATH) mock_certs = MagicMock(return_value={}) mock_cert_file = MagicMock(return_value=CERTS[THUMBPRINT]) mock_import_cert = MagicMock(return_value=True) with patch.dict(win_pki.__salt__, {'cp.cache_file': mock_cache_file, 'win_pki.get_certs': mock_certs, 'win_pki.get_cert_file': mock_cert_file, 'win_pki.import_cert': mock_import_cert}): with patch.dict(win_pki.__opts__, {'test': False}): self.assertEqual(win_pki.import_cert(**kwargs), ret) with patch.dict(win_pki.__opts__, {'test': True}): ret['comment'] = ("Certificate '{0}' will be imported into store:" " {1}").format(THUMBPRINT, STORE_PATH) ret['result'] = None self.assertEqual(win_pki.import_cert(**kwargs), ret)
def test_import_cert(): """ Test - Import the certificate file into the given certificate store. """ kwargs = {"name": CERT_PATH} ret = { "name": kwargs["name"], "changes": {"old": None, "new": THUMBPRINT}, "comment": "Certificate '{}' imported into store: {}".format( THUMBPRINT, STORE_PATH ), "result": True, } mock_cache_file = MagicMock(return_value=CERT_PATH) mock_certs = MagicMock(return_value={}) mock_cert_file = MagicMock(return_value=CERTS[THUMBPRINT]) mock_import_cert = MagicMock(return_value=True) with patch.dict( win_pki.__salt__, { "cp.cache_file": mock_cache_file, "win_pki.get_certs": mock_certs, "win_pki.get_cert_file": mock_cert_file, "win_pki.import_cert": mock_import_cert, }, ): with patch.dict(win_pki.__opts__, {"test": False}): assert win_pki.import_cert(**kwargs) == ret with patch.dict(win_pki.__opts__, {"test": True}): ret["comment"] = ( "Certificate '{}' will be imported into store: {}" ).format(THUMBPRINT, STORE_PATH) ret["result"] = None assert win_pki.import_cert(**kwargs) == ret