diff options
Diffstat (limited to 'ironic/tests/unit/common/test_policy.py')
-rw-r--r-- | ironic/tests/unit/common/test_policy.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ironic/tests/unit/common/test_policy.py b/ironic/tests/unit/common/test_policy.py index 97d337558..db0a3e437 100644 --- a/ironic/tests/unit/common/test_policy.py +++ b/ironic/tests/unit/common/test_policy.py @@ -15,6 +15,10 @@ # License for the specific language governing permissions and limitations # under the License. +import sys + +import mock +from oslo_config import cfg from oslo_policy import policy as oslo_policy from ironic.common import exception @@ -119,3 +123,34 @@ class PolicyTestCase(base.TestCase): exception.IronicException, policy.enforce, 'has_foo_role', creds, creds, True, exception.IronicException) + + @mock.patch.object(cfg, 'CONF', autospec=True) + @mock.patch.object(policy, 'get_enforcer', autospec=True) + def test_get_oslo_policy_enforcer_no_args(self, mock_gpe, mock_cfg): + mock_gpe.return_value = mock.Mock() + args = [] + with mock.patch.object(sys, 'argv', args): + policy.get_oslo_policy_enforcer() + mock_cfg.assert_called_once_with([], project='ironic') + self.assertEqual(1, mock_gpe.call_count) + + @mock.patch.object(cfg, 'CONF', autospec=True) + @mock.patch.object(policy, 'get_enforcer', autospec=True) + def test_get_oslo_policy_enforcer_namespace(self, mock_gpe, mock_cfg): + mock_gpe.return_value = mock.Mock() + args = ['opg', '--namespace', 'ironic'] + with mock.patch.object(sys, 'argv', args): + policy.get_oslo_policy_enforcer() + mock_cfg.assert_called_once_with([], project='ironic') + self.assertEqual(1, mock_gpe.call_count) + + @mock.patch.object(cfg, 'CONF', autospec=True) + @mock.patch.object(policy, 'get_enforcer', autospec=True) + def test_get_oslo_policy_enforcer_config_file(self, mock_gpe, mock_cfg): + mock_gpe.return_value = mock.Mock() + args = ['opg', '--namespace', 'ironic', '--config-file', 'my.cfg'] + with mock.patch.object(sys, 'argv', args): + policy.get_oslo_policy_enforcer() + mock_cfg.assert_called_once_with(['--config-file', 'my.cfg'], + project='ironic') + self.assertEqual(1, mock_gpe.call_count) |