Example #1
0
    def test_make_new_brain(self):
        with mock.patch.object(policy, "Brain") as fake_brain:
            fake_brain.check.return_value = True

            result = policy.enforce("match", "target", "credentials")

            self.assertNotEqual(policy._BRAIN, None)
            self.assertEqual(result, True)
Example #2
0
    def test_make_new_brain(self):
        with mock.patch.object(policy, "Brain") as fake_brain:
            fake_brain.check.return_value = True

            result = policy.enforce("match", "target", "credentials")

            self.assertNotEqual(policy._BRAIN, None)
            self.assertEqual(result, True)
Example #3
0
    def test_fail_with_exc(self):
        class TestException(Exception):
            def __init__(self, *args, **kwargs):
                self.args = args
                self.kwargs = kwargs

        self.fake_brain.check_result = False
        try:
            result = policy.enforce("match", "target", "credentials",
                                    TestException, "arg1", "arg2",
                                    kw1="kwarg1", kw2="kwarg2")
        except TestException as exc:
            self.assertEqual(exc.args, ("arg1", "arg2"))
            self.assertEqual(exc.kwargs, dict(kw1="kwarg1", kw2="kwarg2"))
        else:
            self.fail("policy.enforce() failed to raise requested exception")
Example #4
0
    def test_fail_with_exc(self):
        class TestException(Exception):
            def __init__(self, *args, **kwargs):
                self.args = args
                self.kwargs = kwargs

        self.fake_brain.check_result = False
        try:
            result = policy.enforce("match",
                                    "target",
                                    "credentials",
                                    TestException,
                                    "arg1",
                                    "arg2",
                                    kw1="kwarg1",
                                    kw2="kwarg2")
        except TestException as exc:
            self.assertEqual(exc.args, ("arg1", "arg2"))
            self.assertEqual(exc.kwargs, dict(kw1="kwarg1", kw2="kwarg2"))
        else:
            self.fail("policy.enforce() failed to raise requested exception")
Example #5
0
    def test_fail_no_exc(self):
        self.fake_brain.check_result = False
        result = policy.enforce("match", "target", "credentials")

        self.assertEqual(result, False)
        self.check_args("match", "target", "credentials")
Example #6
0
    def test_use_existing_brain(self):
        result = policy.enforce("match", "target", "credentials")

        self.assertNotEqual(policy._BRAIN, None)
        self.assertEqual(result, True)
        self.check_args("match", "target", "credentials")
Example #7
0
    def test_fail_no_exc(self):
        self.fake_brain.check_result = False
        result = policy.enforce("match", "target", "credentials")

        self.assertEqual(result, False)
        self.check_args("match", "target", "credentials")
Example #8
0
    def test_use_existing_brain(self):
        result = policy.enforce("match", "target", "credentials")

        self.assertNotEqual(policy._BRAIN, None)
        self.assertEqual(result, True)
        self.check_args("match", "target", "credentials")