Esempio n. 1
0
def app():
    update_auctionPeriod(tender_data)
    logger = MagicMock()
    logger.name = 'some-logger'
    app_auction = Auction(tender_id=tender_data['data']['tenderID'],
                          worker_defaults=yaml.load(
                              open(worker_defaults_file_path)),
                          auction_data=tender_data,
                          lot_id=False)
    app_auction.bidders_data = tender_data['data']['bids']
    app_auction.db = MagicMock()
    app_auction.db.get.return_value = test_auction_document
    worker_app.config.update(app_auction.worker_defaults)
    worker_app.logger_name = logger.name
    worker_app._logger = logger
    worker_app.config['auction'] = app_auction
    worker_app.config['timezone'] = tz('Europe/Kiev')
    worker_app.config['SESSION_COOKIE_PATH'] = '/{}/{}'.format(
        'auctions', app_auction.auction_doc_id)
    worker_app.config['SESSION_COOKIE_NAME'] = 'auction_session'
    worker_app.oauth = MagicMock()
    worker_app.bids_form = BidsForm
    worker_app.form_handler = MagicMock()
    worker_app.form_handler.return_value = {'data': 'ok'}
    worker_app.remote_oauth = MagicMock()
    worker_app.remote_oauth.authorized_response.side_effect = [
        None, {
            u'access_token': u'aMALGpjnB1iyBwXJM6betfgT4usHqw',
            u'token_type': u'Bearer',
            u'expires_in': 86400,
            u'refresh_token': u'uoRKeSJl9UFjuMwOw6PikXuUVp7MjX',
            u'scope': u'email'
        }
    ]
    worker_app.remote_oauth.authorize.return_value = \
        redirect('https://my.test.url')
    worker_app.logins_cache[(u'aMALGpjnB1iyBwXJM6betfgT4usHqw', '')] = {
        u'bidder_id':
        u'f7c8cd1d56624477af8dc3aa9c4b3ea3',
        u'expires':
        (datetime.datetime.now(tzlocal()) + timedelta(0, 600)).isoformat()
    }
    worker_app.auction_bidders = {
        u'f7c8cd1d56624477af8dc3aa9c4b3ea3': {
            'clients': {},
            'channels': {}
        }
    }
    yield worker_app.test_client()
Esempio n. 2
0
def auction():
    update_auctionPeriod(tender_data)

    yield Auction(tender_id=tender_data['data']['tenderID'],
                  worker_defaults=yaml.load(open(worker_defaults_file_path)),
                  auction_data=tender_data,
                  lot_id=False)
Esempio n. 3
0
def universal_auction(request):
    update_auctionPeriod(request.param['tender_data'])

    yield Auction(tender_id=request.param['tender_data']['data']['tenderID'],
                  worker_defaults=yaml.load(open(worker_defaults_file_path)),
                  auction_data=request.param['tender_data'],
                  lot_id=request.param['lot_id'])
Esempio n. 4
0
def auction(request):
    defaults = {
        'time': MIN_AUCTION_START_TIME_RESERV,
        'delta_t': datetime.timedelta(seconds=10)
    }

    params = getattr(request, 'param', defaults)
    for key in defaults.keys():
        params[key] = defaults[key] if params.get(key, 'default') == 'default'\
            else params[key]

    with update_auctionPeriod(
            AUCTION_DATA['simple']['path'],
            auction_type='simple',
            time_shift=params['time']+params['delta_t']) \
            as updated_doc, open(updated_doc, 'r') as auction_updated_data:
        auction_inst = Auction(
            tender_id=AUCTION_DATA['simple']['data']['data']['tenderID'],
            worker_defaults=yaml.load(open(worker_defaults_file_path)),
            auction_data=json.load(auction_updated_data),
            lot_id=False)

    return auction_inst
def main():
    parser = argparse.ArgumentParser(description='---- Auction ----')
    parser.add_argument('cmd', type=str, help='')
    parser.add_argument('auction_doc_id', type=str, help='auction_doc_id')
    parser.add_argument('auction_worker_config',
                        type=str,
                        help='Auction Worker Configuration File')
    parser.add_argument('--auction_info', type=str, help='Auction File')
    parser.add_argument('--auction_info_from_db',
                        type=str,
                        help='Get auction data from local database')
    parser.add_argument('--with_api_version',
                        type=str,
                        help='Tender Api Version')
    parser.add_argument('--lot',
                        type=str,
                        help='Specify lot in tender',
                        default=None)
    parser.add_argument('--planning_procerude',
                        type=str,
                        help='Override planning procerude',
                        default=None,
                        choices=[
                            None, C.PLANNING_FULL, C.PLANNING_PARTIAL_DB,
                            C.PLANNING_PARTIAL_CRON
                        ])

    args = parser.parse_args()

    if os.path.isfile(args.auction_worker_config):
        worker_defaults = yaml.load(open(args.auction_worker_config))
        if args.with_api_version:
            worker_defaults['TENDERS_API_VERSION'] = args.with_api_version
        if args.cmd != 'cleanup':
            worker_defaults['handlers']['journal'][
                'TENDER_ID'] = args.auction_doc_id
            if args.lot:
                worker_defaults['handlers']['journal'][
                    'TENDER_LOT_ID'] = args.lot
        for key in (
                'TENDERS_API_VERSION',
                'TENDERS_API_URL',
        ):
            worker_defaults['handlers']['journal'][key] = worker_defaults[key]

        logging.config.dictConfig(worker_defaults)
    else:
        print "Auction worker defaults config not exists!!!"
        sys.exit(1)

    if args.auction_info_from_db:
        auction_data = {'mode': 'test'}
    elif args.auction_info:
        auction_data = json.load(open(args.auction_info))
    else:
        auction_data = None

    auction = Auction(args.auction_doc_id,
                      worker_defaults=worker_defaults,
                      auction_data=auction_data,
                      lot_id=args.lot)
    if args.cmd == 'run':
        SCHEDULER.start()
        auction.schedule_auction()
        auction.wait_to_end()
        SCHEDULER.shutdown()
    elif args.cmd == 'planning':
        auction.prepare_auction_document()
    elif args.cmd == 'announce':
        auction.post_announce()
    elif args.cmd == 'cancel':
        auction.cancel_auction()
    elif args.cmd == 'reschedule':
        auction.reschedule_auction()
Esempio n. 6
0
def features_auction():

    yield Auction(tender_id=features_tender_data['data']['tenderID'],
                  worker_defaults=yaml.load(open(worker_defaults_file_path)),
                  auction_data=features_tender_data,
                  lot_id=False)
Esempio n. 7
0
def multilot_auction():

    yield Auction(tender_id=lot_tender_data['data']['tenderID'],
                  worker_defaults=yaml.load(open(worker_defaults_file_path)),
                  auction_data=lot_tender_data,
                  lot_id=lot_tender_data['data']['lots'][0]['id'])