Exemplo n.º 1
0
    def test_get_tiid_by_biblio(self):

        new_item = Item()
        self.db.session.add(new_item)
        new_item.biblios = item_module.create_biblio_objects([self.BIBLIO_DATA]) 
        self.db.session.commit()

        found_tiid = item_module.get_tiid_by_biblio(self.BIBLIO_DATA)
        assert_equals(found_tiid, new_item.tiid)
Exemplo n.º 2
0
    def test_get_tiid_by_biblio(self):

        new_item = Item()
        self.db.session.add(new_item)
        new_item.biblios = item_module.create_biblio_objects([self.BIBLIO_DATA]) 
        self.db.session.commit()

        found_tiid = item_module.get_tiid_by_biblio(self.BIBLIO_DATA)
        assert_equals(found_tiid, new_item.tiid)
Exemplo n.º 3
0
    def test_add_biblio(self):
        new_item = Item()
        tiid = new_item.tiid
        print new_item

        #add biblio
        self.db.session.add(new_item)
        new_biblio_objects = item_module.create_biblio_objects([self.BIBLIO_DATA]) 
        new_item.biblios = new_biblio_objects
        self.db.session.commit()

        # now poof there is biblio
        found_item = Item.from_tiid(tiid)
        expected = [u'10', u'Pitman', u"An extension of de Finetti's theorem", u'Advances in Applied Probability', [u"Pitman, J"], u'1978', u'p78', u'pitnoid', u'268 to 270']
        assert_equals([bib.biblio_value for bib in found_item.biblios], expected)
        
        assert_equals(Biblio.as_dict_by_tiid(tiid), self.BIBLIO_DATA)
Exemplo n.º 4
0
    def test_add_biblio(self):
        new_item = Item()
        tiid = new_item.tiid
        print new_item

        #add biblio
        self.db.session.add(new_item)
        new_biblio_objects = item_module.create_biblio_objects([self.BIBLIO_DATA]) 
        new_item.biblios = new_biblio_objects
        self.db.session.commit()

        # now poof there is biblio
        found_item = Item.from_tiid(tiid)
        expected = [u'10', u'Pitman', u"An extension of de Finetti's theorem", u'Advances in Applied Probability', [u"Pitman, J"], u'1978', u'p78', u'pitnoid', u'268 to 270']
        assert_equals([bib.biblio_value for bib in found_item.biblios], expected)
        
        assert_equals(Biblio.as_dict_by_tiid(tiid), self.BIBLIO_DATA)
def item_missing_biblios_on_a_page(page, skip_till_key="0000"):
    items = [row.doc for row in page]

    for item_doc in items:
        tiid = item_doc["_id"]
        if tiid > skip_till_key:
            if not "biblio" in item_doc["aliases"]:
                print tiid, "doesn't have biblio in aliases"
                if "title" in item_doc["biblio"]:
                    print "... but does have a title in biblio.  Mirroring."
                    item_obj = Item.query.filter_by(tiid=tiid).first()
                    db.session.merge(item_obj)
                    item_obj.biblios = create_biblio_objects([item_doc["biblio"]])
    try:
        db.session.commit()
    except (IntegrityError, FlushError) as e:
        db.session.rollback()
        logger.warning(u"Fails Integrity check in add_biblio_to_item_object for {tiid}, rolling back.  Message: {message}".format(
            tiid=tiid, 
            message=e.message)) 

    print "just finished", tiid
    return
Exemplo n.º 6
0
def item_missing_biblios_on_a_page(page, skip_till_key="0000"):
    items = [row.doc for row in page]

    for item_doc in items:
        tiid = item_doc["_id"]
        if tiid > skip_till_key:
            if not "biblio" in item_doc["aliases"]:
                print tiid, "doesn't have biblio in aliases"
                if "title" in item_doc["biblio"]:
                    print "... but does have a title in biblio.  Mirroring."
                    item_obj = Item.query.filter_by(tiid=tiid).first()
                    db.session.merge(item_obj)
                    item_obj.biblios = create_biblio_objects(
                        [item_doc["biblio"]])
    try:
        db.session.commit()
    except (IntegrityError, FlushError) as e:
        db.session.rollback()
        logger.warning(
            u"Fails Integrity check in add_biblio_to_item_object for {tiid}, rolling back.  Message: {message}"
            .format(tiid=tiid, message=e.message))

    print "just finished", tiid
    return