Exemplo n.º 1
0
 def test_release_tenders(self):
     ten = tender.copy()
     patch = [{"op": "replace", "path": "/bids/0/status", "value": "test"}]
     ten['patches'] = [patch]
     releases = release_tenders_ext(ten, update_models_map(),
                                    update_callbacks(), 'test')
     assert len(releases) == 2
     assert 'bidUpdate' in releases[1]['tag']
     patch1 = [{"op": "replace", "path": "/description", "value": "test"}]
     ten['patches'] = [patch1]
     releases = release_tenders_ext(ten, update_models_map(),
                                    update_callbacks(), 'test')
     assert 'tenderUpdate' in releases[1]['tag']
     patch2 = [{
         'op': 'add',
         'path': '/bids/1',
         'value': {
             'status': 'test',
             'description': 'Some test bid',
         }
     }]
     ten = tender.copy()
     ten['patches'] = [patch2]
     releases = release_tenders_ext(ten, update_models_map(),
                                    update_callbacks(), 'test')
     assert 'bid' in releases[1]['tag']
Exemplo n.º 2
0
 def test_record(self):
     ten = tender.copy()
     patch = [{"op": "replace", "path": "/description", "value": "test"}]
     ten['patches'] = [patch]
     record = record_tenders_ext(ten, update_models_map(),
                                 update_callbacks(), 'test')
     assert len(record['releases']) == 2
     assert record['ocid'] == record['releases'][0]['ocid']
Exemplo n.º 3
0
def fetch_and_dump(params):
    nth, (start, end) = params
    LOGGER.info('Start packaging {}th package! Params: startdoc={},'
                ' enddoc={}'.format(nth, start, end))
    if not start and not end:
        return

    args = {'startkey': start}
    if end:
        args.update(dict(endkey=end))

    if REGISTRY['contracting']:
        args.update({'contract_storage': REGISTRY['contracts_storage']})

    result = [
        tender for tender in REGISTRY['tenders_storage'].get_tenders(**args)
    ]

    name = 'record-{0:07d}.json'.format(
        nth) if REGISTRY['record'] else 'release-{0:07d}.json'.format(nth)
    max_date = REGISTRY['max_date']
    try:

        for pack, params in zip(REGISTRY['package_funcs'],
                                [{
                                    'uri': REGISTRY['can_url'],
                                    'models': modelsMap,
                                    'callbacks': callbacks,
                                    'q': REGISTRY['zipq']
                                }, {
                                    'uri': REGISTRY['ext_url'],
                                    'models': update_models_map(),
                                    'callbacks': update_callbacks(),
                                    'q': REGISTRY['zipq_ext']
                                }]):
            LOGGER.info("Start package: {}".format(pack.__name__))
            package = pack(result[:-1], params['models'], params['callbacks'],
                           REGISTRY['config'].get('release'))
            package['uri'] = params['uri'].format(REGISTRY['bucket'].name,
                                                  max_date, name)
            if nth == 1:
                pretty_package = pack(result[:24], params['models'],
                                      params['callbacks'],
                                      REGISTRY['config'].get('release'))
                pretty_package['uri'] = params['uri'].format(
                    REGISTRY['bucket'], max_date, 'example.json')
                dump_json_to_s3('example.json', pretty_package, pretty=True)

            dump_json_to_s3(name, package)
            zip_package(name, package)
            del package
        del result
    except Exception as e:
        LOGGER.info('Error: {}'.format(e))
        return

    LOGGER.info('Done {}th package! Params: startdoc={}, enddoc={}'.format(
        nth, start, end))
Exemplo n.º 4
0
 def test_release_package(self):
     pack = package_tenders_ext([tender for _ in xrange(3)],
                                update_models_map(), update_callbacks(),
                                config)
     assert len(pack['releases']) == 3
     for field in ['license', 'publicationPolicy']:
         assert field in pack
         assert pack[field] == 'test'
     assert 'name' in pack['publisher']
     assert pack['publisher']['name'] == 'test'
Exemplo n.º 5
0
def fetch_and_dump(total):
    num = 0
    result = []
    nth = 0
    for res in REGISTRY['tenders_storage'].get_tender(
            REGISTRY['contracts_storage']):
        if num == total:
            nth += 1
            start = result[0]['id']
            end = result[-1]['id']
            LOGGER.info('Start packaging {}th package! Params: startdoc={},'
                        ' enddoc={}'.format(nth, start, end))
            name = 'record-{0:07d}.json'.format(
                nth) if REGISTRY['record'] else 'release-{0:07d}.json'.format(
                    nth)
            max_date = REGISTRY['max_date']
            try:
                for pack, params in zip(REGISTRY['package_funcs'],
                                        [{
                                            'uri': REGISTRY['can_url'],
                                            'models': modelsMap,
                                            'callbacks': callbacks,
                                            'q': REGISTRY['zipq']
                                        }, {
                                            'uri': REGISTRY['ext_url'],
                                            'models': update_models_map(),
                                            'callbacks': update_callbacks(),
                                            'q': REGISTRY['zipq_ext']
                                        }]):
                    LOGGER.info("Start package: {}".format(pack.__name__))
                    package = pack(result, params['models'],
                                   params['callbacks'],
                                   REGISTRY['config'].get('release'))
                    package['uri'] = params['uri'].format(
                        REGISTRY['config'].get("bucket"), max_date, name)
                    if nth == 1:
                        pretty_package = pack(
                            result[:24], params['models'], params['callbacks'],
                            REGISTRY['config'].get('release'))
                        pretty_package['uri'] = params['uri'].format(
                            REGISTRY['config'].get("bucket"), max_date,
                            'example.json')
                        dump_json_to_s3('example.json',
                                        pretty_package,
                                        pretty=True)

                    dump_json_to_s3(name, package)
                    zip_package(name, package)
                    del package
                result = [res]
                num = 1
            except Exception as e:
                LOGGER.info('Error: {}'.format(e))
                return

            LOGGER.info(
                'Done {}th package! Params: startdoc={}, enddoc={}'.format(
                    nth, start, end))
        else:
            result.append(res)
            num += 1
    return nth
Exemplo n.º 6
0
 def test_contract_model(self):
     new = ContractExt(contract, update_models_map(),
                       update_callbacks()).__export__()
     assert 'contractNumber' in new
     assert 'contractID' in new
Exemplo n.º 7
0
    def test_tender_model(self):

        new = TenderExt(tender, update_models_map(),
                        update_callbacks()).__export__()
        assert 'lots' in new
        assert 'tenderID' in new
Exemplo n.º 8
0
 def test_award_model(self):
     new = AwardExt(award, update_models_map(),
                    update_callbacks()).__export__()
     assert 'lotID' in new
Exemplo n.º 9
0
 def test_release_tender(self):
     release = release_tender_ext(tender, update_models_map(),
                                  update_callbacks(), 'test')
     assert 'bid' in release['tag']
Exemplo n.º 10
0
 def test_callbacks_update(self):
     assert 'bids' in update_callbacks()