def claim(self, offer_uuid, new_lease): request = pecan.request.context cdict = request.to_policy_values() offer = utils.check_offer_policy_and_retrieve(request, 'esi_leap:offer:claim', offer_uuid, statuses.AVAILABLE) utils.check_offer_lessee(cdict, offer) lease_dict = new_lease.to_dict() lease_dict['project_id'] = request.project_id lease_dict['uuid'] = uuidutils.generate_uuid() lease_dict['offer_uuid'] = offer_uuid lease_dict['resource_type'] = offer.resource_type lease_dict['resource_uuid'] = offer.resource_uuid lease_dict['owner_id'] = offer.project_id if offer.parent_lease_uuid is not None: lease_dict['parent_lease_uuid'] = offer.parent_lease_uuid if 'start_time' not in lease_dict: lease_dict['start_time'] = datetime.datetime.now() if 'end_time' not in lease_dict: q = offer.get_first_availability(lease_dict['start_time']) if q is None: lease_dict['end_time'] = offer.end_time else: lease_dict['end_time'] = q.start_time new_lease = lease_obj.Lease(**lease_dict) new_lease.create(request) return lease.Lease(**utils.lease_get_dict_with_added_info(new_lease))
def test_check_offer_lessee_non_admin_match(self, mock_gppit, mock_authorize): mock_gppit.return_value = [lessee_ctx.project_id, 'lesseeidparent'] utils.check_offer_lessee(lessee_ctx.to_policy_values(), test_offer_lessee_match) assert not mock_authorize.called mock_gppit.assert_called_once_with(lessee_ctx.project_id)
def test_check_offer_lessee_admin(self, mock_gppit, mock_authorize): mock_authorize.return_value = True mock_gppit.return_value = [admin_ctx.project_id] utils.check_offer_lessee(admin_ctx.to_policy_values(), test_offer_lessee_no_match) mock_authorize.assert_called_once_with('esi_leap:offer:offer_admin', admin_ctx.to_policy_values(), admin_ctx.to_policy_values()) mock_gppit.assert_called_once_with(admin_ctx.project_id)
def get_one(self, offer_id): request = pecan.request.context cdict = request.to_policy_values() offer = utils.check_offer_policy_and_retrieve( request, 'esi_leap:offer:get', offer_id) utils.check_offer_lessee(cdict, offer) o = utils.offer_get_dict_with_added_info(offer) return Offer(**o)
def test_check_offer_lessee_owner_match(self, mock_gppit, mock_authorize): utils.check_offer_lessee(owner_ctx.to_policy_values(), test_offer_lessee_no_match) assert not mock_authorize.called assert not mock_gppit.called
def test_check_offer_lessee_no_lessee_id(self, mock_gppit, mock_authorize): utils.check_offer_lessee(lessee_ctx.to_policy_values(), test_offer) assert not mock_authorize.called assert not mock_gppit.called