Beispiel #1
0
    def post(self):
        """This API request is targeted to creating new Lot."""
        lot_id = generate_id()
        lot = self.request.validated['lot']
        lot.id = lot_id
        if not lot.get('lotID'):
            lot.lotID = generate_lot_id(get_now(), self.db, self.server_id)
        self.request.registry.notify(LotInitializeEvent(lot))

        default_status = type(lot).fields['status'].default
        status = self.request.json_body['data'].get('status', default_status)
        if status == 'draft':
            lot.status = status
        else:
            self.request.errors.add('body', 'status',
                                    'You can create only in draft status')
            self.request.errors.status = 403
            return

        acc = set_ownership(lot, self.request)
        self.request.validated['lot'] = lot
        self.request.validated['lot_src'] = {}
        if save_lot(self.request):
            self.LOGGER.info('Created lot {} ({})'.format(lot_id, lot.lotID),
                             extra=context_unpack(self.request,
                                                  {'MESSAGE_ID': 'lot_create'},
                                                  {
                                                      'lot_id': lot_id,
                                                      'lotID': lot.lotID
                                                  }))
            self.request.response.status = 201
            self.request.response.headers['Location'] = self.request.route_url(
                '{}:Lot'.format(lot.lotType), lot_id=lot_id)
            return {'data': lot.serialize(lot.status), 'access': acc}
 def post(self):
     """This API request is targeted to creating new Lot."""
     lot_id = generate_id()
     lot = self.request.validated['lot']
     lot.id = lot_id
     if not lot.get('lotID'):
         lot.lotID = generate_lot_id(get_now(), self.db, self.server_id)
     self.request.registry.notify(LotInitializeEvent(lot))
     if self.request.json_body['data'].get('status') == 'draft':
         lot.status = 'draft'
     set_ownership(lot, self.request)  # rewrite as subscriber?
     self.request.validated['lot'] = lot
     self.request.validated['lot_src'] = {}
     if save_lot(self.request):
         self.LOGGER.info('Created lot {} ({})'.format(lot_id, lot.lotID),
                          extra=context_unpack(self.request,
                                               {'MESSAGE_ID': 'lot_create'},
                                               {
                                                   'lot_id': lot_id,
                                                   'lotID': lot.lotID
                                               }))
         self.request.response.status = 201
         self.request.response.headers['Location'] = self.request.route_url(
             '{}:Lot'.format(lot.lotType), lot_id=lot_id)
         return {
             'data': lot.serialize(lot.status),
             'access': {
                 'token': lot.owner_token
             }
         }
 def post(self):
     """This API request is targeted to creating new Asset."""
     asset_id = generate_id()
     asset = self.request.validated['asset']
     asset.id = asset_id
     if not asset.get('assetID'):
         asset.assetID = generate_asset_id(get_now(), self.db,
                                           self.server_id)
     self.request.registry.notify(AssetInitializeEvent(asset))
     if self.request.json_body['data'].get('status') == 'draft':
         asset.status = 'draft'
     acc = set_ownership(asset, self.request)
     self.request.validated['asset'] = asset
     self.request.validated['asset_src'] = {}
     if save_asset(self.request):
         self.LOGGER.info(
             'Created asset {} ({})'.format(asset_id, asset.assetID),
             extra=context_unpack(self.request,
                                  {'MESSAGE_ID': 'asset_create'}, {
                                      'asset_id': asset_id,
                                      'assetID': asset.assetID
                                  }))
         self.request.response.status = 201
         self.request.response.headers['Location'] = self.request.route_url(
             '{}:Asset'.format(asset.assetType), asset_id=asset_id)
         return {'data': asset.serialize(asset.status), 'access': acc}
Beispiel #4
0
    def test_generate_id(self):
        id = generate_id()

        self.assertEqual(len(id), 32)
        self.assertEqual(type(UUID(id)), UUID)