← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1243902] Re: glance policy unit tests should use a simple mock instead of a FakePolicyEnforcer

 

** Changed in: glance
       Status: Fix Committed => Fix Released

** Changed in: glance
    Milestone: None => icehouse-1

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to Glance.
https://bugs.launchpad.net/bugs/1243902

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

Status in OpenStack Image Registry and Delivery Service (Glance):
  Fix Released

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()

To manage notifications about this bug go to:
https://bugs.launchpad.net/glance/+bug/1243902/+subscriptions