glance policy unit tests should use a simple mock instead of a FakePolicyEnforcer

Bug #1243902 reported by Nikhil Komawar
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Undecided
Unassigned

Bug Description

Currently, an example test in the unit test policy looks like:-

class TestImagePolicy(test_utils.BaseTestCase):
    def setUp(self):
        self.image_stub = ImageStub(UUID1)
        self.image_repo_stub = ImageRepoStub()
        self.image_factory_stub = ImageFactoryStub()
        self.policy = unit_test_utils.FakePolicyEnforcer() <- this could be a mock instead
        super(TestImagePolicy, self).setUp()

    def test_publicize_image_not_allowed(self):
        rules = {"publicize_image": False} <- this does not represent how rules are formatted
        self.policy.set_rules(rules)
        image = glance.api.policy.ImageProxy(self.image_stub, {}, self.policy)
        self.assertRaises(exception.Forbidden,
                          setattr, image, 'visibility', 'public')
        self.assertEquals(image.visibility, 'private')

----
this sample piece of code would work instead
        self.policy = mock.Mock()
        self.policy.enforce = mock.Mock()
        self.policy.enforce.side_effect = exception.Forbidden()

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to glance (master)

Reviewed: https://review.openstack.org/53451
Committed: http://github.com/openstack/glance/commit/0c1f60d06bae8e571c7accb596ad9268ac066c40
Submitter: Jenkins
Branch: master

commit 0c1f60d06bae8e571c7accb596ad9268ac066c40
Author: Nikhil Komawar <email address hidden>
Date: Wed Oct 23 16:34:48 2013 -0400

    Use mock in test_policy

    FakePolicyEnforcer is trying to imitate the real policy enforcer.
    We don't need it in the test_policy tests.

    fixes bug 1243902

    Change-Id: Id82d09dc9aafbf57b6fc968ae1ded944b8d64229

Changed in glance:
status: New → Fix Committed
Thierry Carrez (ttx)
Changed in glance:
milestone: none → icehouse-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in glance:
milestone: icehouse-1 → 2014.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.