Example #1
0
    def test_get_offer_authorized_uuid_available_admin(self, mock_offer_get,
                                                       mock_is_uuid_like,
                                                       mock_authorize):

        mock_is_uuid_like.return_value = True
        mock_offer_get.return_value = test_offer

        utils.get_offer_authorized(test_offer.uuid,
                                   admin_ctx.to_policy_values(),
                                   statuses.AVAILABLE)

        mock_is_uuid_like.assert_called_once_with(test_offer.uuid)
        mock_offer_get.assert_called_once_with(test_offer.uuid)
        mock_authorize.assert_called_once_with('esi_leap:offer:offer_admin',
                                               admin_ctx.to_policy_values(),
                                               admin_ctx.to_policy_values())
Example #2
0
    def delete(self, offer_id):
        request = pecan.request.context
        cdict = request.to_policy_values()
        policy.authorize('esi_leap:offer:delete', cdict, cdict)

        o_object = utils.get_offer_authorized(offer_id, cdict,
                                              statuses.AVAILABLE)

        o_object.cancel()
Example #3
0
    def test_get_offer_authorized_uuid_owner(self, mock_offer_get,
                                             mock_is_uuid_like,
                                             mock_authorize):

        mock_is_uuid_like.return_value = True
        mock_offer_get.return_value = test_offer

        res = utils.get_offer_authorized(test_offer.uuid,
                                         owner_ctx.to_policy_values())

        self.assertEqual(res, test_offer)

        mock_is_uuid_like.assert_called_once_with(test_offer.uuid)
        mock_offer_get.assert_called_once_with(test_offer.uuid)
        assert not mock_authorize.called
Example #4
0
    def test_get_offer_authorized_name_available_owner(self,
                                                       mock_offer_get_all,
                                                       mock_is_uuid_like,
                                                       mock_authorize):

        mock_is_uuid_like.return_value = False
        mock_offer_get_all.return_value = [test_offer]

        res = utils.get_offer_authorized(test_offer.name,
                                         owner_ctx.to_policy_values(),
                                         statuses.AVAILABLE)

        self.assertEqual(res, test_offer)

        mock_is_uuid_like.assert_called_once_with(test_offer.name)
        mock_offer_get_all.assert_called_once_with({
            'name': test_offer.name,
            'status': statuses.AVAILABLE
        })
        mock_authorize.assert_called_once()