summaryrefslogtreecommitdiffstats
path: root/testsuite/Testsrc/Testlib
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-01-03 14:42:33 -0600
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-01-03 14:42:33 -0600
commit49dd65c94f9b6a57365448a30e4248c0ff338d34 (patch)
treed39067d5d138a9ec282764aa07369800c78fb081 /testsuite/Testsrc/Testlib
parent449bd8ced5a6068e1bb514e52e7d099b90248ca7 (diff)
downloadbcfg2-49dd65c94f9b6a57365448a30e4248c0ff338d34.tar.gz
bcfg2-49dd65c94f9b6a57365448a30e4248c0ff338d34.tar.bz2
bcfg2-49dd65c94f9b6a57365448a30e4248c0ff338d34.zip
fixed unit tests
Diffstat (limited to 'testsuite/Testsrc/Testlib')
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgAuthorizedKeysGenerator.py9
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPrivateKeyCreator.py40
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPublicKeyCreator.py3
3 files changed, 27 insertions, 25 deletions
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgAuthorizedKeysGenerator.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgAuthorizedKeysGenerator.py
index 23a77d1e5..d655a20cd 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgAuthorizedKeysGenerator.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgAuthorizedKeysGenerator.py
@@ -3,7 +3,7 @@ import sys
import lxml.etree
from mock import Mock, MagicMock, patch
from Bcfg2.Server.Plugins.Cfg.CfgAuthorizedKeysGenerator import *
-from Bcfg2.Server.Plugin import PluginExecutionError
+import Bcfg2.Server.Plugins.Cfg.CfgAuthorizedKeysGenerator
# add all parent testsuite directories to sys.path to allow (most)
# relative imports in python 2.4
@@ -137,8 +137,11 @@ class TestCfgAuthorizedKeysGenerator(TestCfgGenerator, TestStructFile):
attrib={"from": pubkey, "host": host}),
"Params", foo="foo", bar="bar=bar")
akg.XMLMatch.return_value = spec
- self.assertEqual(akg.get_data(entry, metadata),
- "foo=foo,bar=bar=bar %s %s" % (host, pubkey))
+ params, actual_host, actual_pubkey = akg.get_data(entry,
+ metadata).split()
+ self.assertEqual(actual_host, host)
+ self.assertEqual(actual_pubkey, pubkey)
+ self.assertItemsEqual(params.split(","), ["foo=foo", "bar=bar=bar"])
akg.XMLMatch.assert_called_with(metadata)
akg.core.build_metadata.assert_called_with(host)
self.assertEqual(akg.core.Bind.call_args[0][0].get("name"), pubkey)
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPrivateKeyCreator.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPrivateKeyCreator.py
index dd18306cb..1181fe648 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPrivateKeyCreator.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPrivateKeyCreator.py
@@ -5,6 +5,7 @@ from mock import Mock, MagicMock, patch
from Bcfg2.Server.Plugins.Cfg import CfgCreationError
from Bcfg2.Server.Plugins.Cfg.CfgPrivateKeyCreator import *
from Bcfg2.Server.Plugin import PluginExecutionError
+import Bcfg2.Server.Plugins.Cfg.CfgPrivateKeyCreator
try:
from Bcfg2.Encryption import EVPError
HAS_CRYPTO = True
@@ -210,7 +211,14 @@ class TestCfgPrivateKeyCreator(TestCfgCreator, TestStructFile):
def test_create_data(self, mock_open, mock_rmtree):
pkc = self.get_obj()
pkc.XMLMatch = Mock()
- pkc.get_specificity = MagicMock()
+ pkc.get_specificity = Mock()
+ # in order to make ** magic work in older versions of python,
+ # get_specificity() must return an actual dict, not just a
+ # Mock object that works like a dict. in order to test that
+ # the get_specificity() return value is being used
+ # appropriately, we put some dummy data in it and test for
+ # that data
+ pkc.get_specificity.side_effect = lambda m, s: dict(group="foo")
pkc._gen_keypair = Mock()
privkey = os.path.join(datastore, "privkey")
pkc._gen_keypair.return_value = privkey
@@ -248,14 +256,10 @@ class TestCfgPrivateKeyCreator(TestCfgCreator, TestStructFile):
pkc.XMLMatch.return_value)
self.assertItemsEqual(mock_open.call_args_list,
[call(privkey + ".pub"), call(privkey)])
- pkc.pubkey_creator.get_filename.assert_called_with(
- **pkc.get_specificity.return_value)
+ pkc.pubkey_creator.get_filename.assert_called_with(group="foo")
pkc.pubkey_creator.write_data.assert_called_with(
- "ssh-rsa publickey pubkey.filename\n",
- **pkc.get_specificity.return_value)
- pkc.write_data.assert_called_with(
- "privatekey",
- **pkc.get_specificity.return_value)
+ "ssh-rsa publickey pubkey.filename\n", group="foo")
+ pkc.write_data.assert_called_with("privatekey", group="foo")
mock_rmtree.assert_called_with(datastore)
reset()
@@ -269,14 +273,11 @@ class TestCfgPrivateKeyCreator(TestCfgCreator, TestStructFile):
pkc.XMLMatch.return_value)
self.assertItemsEqual(mock_open.call_args_list,
[call(privkey + ".pub"), call(privkey)])
- pkc.pubkey_creator.get_filename.assert_called_with(
- **pkc.get_specificity.return_value)
+ pkc.pubkey_creator.get_filename.assert_called_with(group="foo")
pkc.pubkey_creator.write_data.assert_called_with(
"ssh-rsa publickey pubkey.filename\n",
- **pkc.get_specificity.return_value)
- pkc.write_data.assert_called_with(
- "privatekey",
- **pkc.get_specificity.return_value)
+ group="foo")
+ pkc.write_data.assert_called_with("privatekey", group="foo")
mock_rmtree.assert_called_with(datastore)
inner()
@@ -299,14 +300,11 @@ class TestCfgPrivateKeyCreator(TestCfgCreator, TestStructFile):
pkc.XMLMatch.return_value)
self.assertItemsEqual(mock_open.call_args_list,
[call(privkey + ".pub"), call(privkey)])
- pkc.pubkey_creator.get_filename.assert_called_with(
- **pkc.get_specificity.return_value)
+ pkc.pubkey_creator.get_filename.assert_called_with(group="foo")
pkc.pubkey_creator.write_data.assert_called_with(
- "ssh-rsa publickey pubkey.filename\n",
- **pkc.get_specificity.return_value)
- pkc.write_data.assert_called_with(
- "encryptedprivatekey",
- **pkc.get_specificity.return_value)
+ "ssh-rsa publickey pubkey.filename\n", group="foo")
+ pkc.write_data.assert_called_with("encryptedprivatekey",
+ group="foo", ext=".crypt")
mock_ssl_encrypt.assert_called_with(
"privatekey", "foo",
algorithm=mock_get_algorithm.return_value)
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPublicKeyCreator.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPublicKeyCreator.py
index 2e7b6eef4..04772cf9a 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPublicKeyCreator.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPublicKeyCreator.py
@@ -4,7 +4,8 @@ import lxml.etree
from mock import Mock, MagicMock, patch
from Bcfg2.Server.Plugins.Cfg import CfgCreationError, CfgCreator
from Bcfg2.Server.Plugins.Cfg.CfgPublicKeyCreator import *
-from Bcfg2.Server.Plugin import StructFile, PluginExecutionError
+import Bcfg2.Server.Plugins.Cfg.CfgPublicKeyCreator
+from Bcfg2.Server.Plugin import PluginExecutionError
# add all parent testsuite directories to sys.path to allow (most)
# relative imports in python 2.4