Esempio n. 1
0
    def post(self, new_contract):
        request = pecan.request.context
        cdict = request.to_policy_values()
        policy.authorize('esi_leap:contract:create', cdict, cdict)

        contract_dict = new_contract.to_dict()
        contract_dict['project_id'] = request.project_id
        contract_dict['uuid'] = uuidutils.generate_uuid()

        if new_contract.offer_uuid_or_name is None:
            raise exception.ContractNoOfferUUID()

        related_offer = utils.get_offer(new_contract.offer_uuid_or_name,
                                        statuses.AVAILABLE)

        contract_dict['offer_uuid'] = related_offer.uuid

        if 'start_time' not in contract_dict:
            contract_dict['start_time'] = datetime.datetime.now()

        if 'end_time' not in contract_dict:
            q = related_offer.get_first_availability(
                contract_dict['start_time'])
            if q is None:
                contract_dict['end_time'] = related_offer.end_time
            else:
                contract_dict['end_time'] = q.start_time

        c = contract.Contract(**contract_dict)
        c.create(request)
        return Contract(**c.to_dict())
Esempio n. 2
0
    def get_one(self, offer_id):
        request = pecan.request.context
        cdict = request.to_policy_values()
        policy.authorize('esi_leap:offer:get', cdict, cdict)

        o_object = utils.get_offer(offer_id)
        o = OffersController._add_offer_availabilities(o_object)
        return Offer(**o)
Esempio n. 3
0
    def test_get_offer_uuid_available(self, mock_offer_get, mock_is_uuid_like):

        mock_is_uuid_like.return_value = True
        mock_offer_get.return_value = test_offer

        res = utils.get_offer(test_offer.uuid, statuses.AVAILABLE)

        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)
Esempio n. 4
0
    def test_get_offer_uuid(self, mock_offer_get, mock_is_uuid_like):

        mock_is_uuid_like.return_value = True
        mock_offer_get.return_value = test_offer

        res = utils.get_offer(test_offer.uuid)

        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)
Esempio n. 5
0
    def test_get_offer_name_available(self, mock_offer_get_all,
                                      mock_is_uuid_like):

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

        res = utils.get_offer(test_offer.name, 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
        })