示例#1
0
def from0to1(registry):
    class Request(object):
        def __init__(self, registry):
            self.registry = registry

    results = registry.db.iterview('auctions/all', 2**10, include_docs=True)
    docs = []
    request = Request(registry)
    root = Root(request)
    pmtConfigurator = registry.pmtConfigurator
    procurement_method_types = [
        pmt for pmt in pmtConfigurator
        if pmtConfigurator[pmt] == "belowThreshold"
    ]
    for i in results:
        doc = i.doc
        if doc['procurementMethodType'] not in procurement_method_types:
            continue
        auction = Auction(doc)
        auction.__parent__ = root
        docs.append(auction.to_primitive())
        if len(docs) >= 2**7:
            result = registry.db.update(docs)
            docs = []
    if docs:
        registry.db.update(docs)
def migrate_from0to1(self):
    set_db_schema_version(self.db, 0)
    u = Auction(test_auction_data)
    u.auctionID = "UA-X"
    u.store(self.db)
    data = self.db.get(u.id)
    data["documents"] = [{
        "id":
        "ebcb5dd7f7384b0fbfbed2dc4252fa6e",
        "title":
        "name.txt",
        "url":
        "/tenders/{}/documents/ebcb5dd7f7384b0fbfbed2dc4252fa6e?download=10367238a2964ee18513f209d9b6d1d3"
        .format(u.id),
        "datePublished":
        "2016-06-01T00:00:00+03:00",
        "dateModified":
        "2016-06-01T00:00:00+03:00",
        "format":
        "text/plain",
    }]
    _id, _rev = self.db.save(data)
    self.app.app.registry.docservice_url = 'http://localhost'
    migrate_data(self.app.app.registry, 1)
    migrated_item = self.db.get(u.id)
    self.assertIn('http://localhost/get/10367238a2964ee18513f209d9b6d1d3?',
                  migrated_item['documents'][0]['url'])
    self.assertIn('Prefix={}%2Febcb5dd7f7384b0fbfbed2dc4252fa6e'.format(u.id),
                  migrated_item['documents'][0]['url'])
    self.assertIn('KeyID=', migrated_item['documents'][0]['url'])
    self.assertIn('Signature=', migrated_item['documents'][0]['url'])
def from0to1(registry):
    class Request(object):
        def __init__(self, registry):
            self.registry = registry
    results = registry.db.iterview('auctions/all', 2 ** 10, include_docs=True)
    docs = []
    request = Request(registry)
    root = Root(request)
    for i in results:
        doc = i.doc
        if doc['procurementMethodType'] != 'belowThreshold':
            continue
        auction = Auction(doc)
        auction.__parent__ = root
        docs.append(auction.to_primitive())
        if len(docs) >= 2 ** 7:
            result = registry.db.update(docs)
            docs = []
    if docs:
        registry.db.update(docs)
 def test_migrate_from0to1(self):
     set_db_schema_version(self.db, 0)
     u = Auction(test_auction_data)
     u.auctionID = "UA-X"
     u.store(self.db)
     data = self.db.get(u.id)
     data["documents"] = [
         {
             "id": "ebcb5dd7f7384b0fbfbed2dc4252fa6e",
             "title": "name.txt",
             "url": "/tenders/{}/documents/ebcb5dd7f7384b0fbfbed2dc4252fa6e?download=10367238a2964ee18513f209d9b6d1d3".format(u.id),
             "datePublished": "2016-06-01T00:00:00+03:00",
             "dateModified": "2016-06-01T00:00:00+03:00",
             "format": "text/plain",
         }
     ]
     _id, _rev = self.db.save(data)
     self.app.app.registry.docservice_url = 'http://localhost'
     migrate_data(self.app.app.registry, 1)
     migrated_item = self.db.get(u.id)
     self.assertIn('http://localhost/get/10367238a2964ee18513f209d9b6d1d3?', migrated_item['documents'][0]['url'])
     self.assertIn('Prefix={}%2Febcb5dd7f7384b0fbfbed2dc4252fa6e'.format(u.id), migrated_item['documents'][0]['url'])
     self.assertIn('KeyID=', migrated_item['documents'][0]['url'])
     self.assertIn('Signature=', migrated_item['documents'][0]['url'])