def test_update_flags(): """Test update flags (xrf and master files)""" xref_fd = join('fixtures', 'testflag.xrf') db_fd = join('fixtures', 'testflag.mst') if exists(xref_fd): remove(xref_fd) if exists(db_fd): remove(db_fd) dbtest = MasterFile(db_fd) rec = MasterRecord() rec.update(test_data) rec.save(dbtest) xrf_rec = dbtest.xrf[1] assert xrf_rec.status == 'active' assert xrf_rec.status == 'active' assert xrf_rec.new_flag == True assert xrf_rec.modified_flag == False rec = dbtest[1] rec[27] = 'Test new field' rec.save(dbtest) assert xrf_rec.new_flag == False assert xrf_rec.modified_flag == True dbtest.invertdb(expr='70 0 MHU,(V70/)') assert xrf_rec.new_flag == False assert xrf_rec.modified_flag == False
def test_delete_record(): for ext in ('.mst', '.xrf'): fname = join("..", "sample", 'one%s' % ext) if exists(fname): remove(fname) mf = MasterFile(join("..", "sample", "one.mst")) rec = MasterRecord() rec["300"] = "XXXX" rec.save(mf) print rec del mf mf = MasterFile(join("..", "sample", "one.mst")) l1 = len(mf) mf.delete(1) mf.commit() del mf mf = MasterFile(join("..", "sample", "one.mst")) l2 = len(mf) del mf print "l1=" + str(l1) print "l2=" + str(l2) assert l2 == l1 - 1, "wrong number of active records after deleting record"
def test_singlerecord_master(): """Create a MasterFile with a single record inside""" clean_start() mf = MasterFile(testmst) rec = MasterRecord() rec.update(test_data) rec.save(mf) del mf # force flush
def createRecord(params): """Create new record <?xml version='1.0'?> <methodCall> <methodName>createRecord</methodName> <params> <param> <value> <struct> <member> <name>collection</name> <value><string>sample</string></value> </member> <member> <name>database</name> <value><string>dbtest</string></value> </member> <member> <name>26</name> <value><string>^aParis^bUnesco^c-1965</string></value> </member> <member> <name>30</name> <value><string>^ap. 211-224^billus.</string></value> </member> <member> <name>50</name> <value><string>Incl. bibl.</string></value> </member> </struct> </value> </param> </params> </methodCall> """ try: colname, dbname, collection, database = get_database_info(params) recno = database.nxtmfn mstrecord = MasterRecord(recno) for tag in params.keys(): if tag in ('database', 'collection'): continue value = params[tag] if type(value) is list: mstfield = [MasterField(tag, valtag) for valtag in value] else: mstfield = MasterField(tag, value) mstrecord[tag] = mstfield mstrecord.save(database) return _("Record mfn=%s created") % recno except Exception, e: return _("** Create Record (%s)") % str(e)
def test_delete_record(): """Create 3 records and delete the one in the middle""" clean_start() size = 3 mf = MasterFile(testmst) for i in range(size): rec = MasterRecord() rec.update(test_data) rec.update({131: "flag %d" % i}) rec.save(mf) mf.delete(2)
def test_update(): """Create a record, modify it and save it and check previous""" clean_start() mf = MasterFile(testmst) r = MasterRecord() r.update(test_data) r.save(mf) r[90] = "This is a new field" r.save(mf) prev = mf.previous(r) assert prev is not None assert len(prev) + 1 == len(r)
def test_write_multiple_records(): """Write multiple records in a newly created database.""" clean_start() size = 381 mf = MasterFile(testmst) for i in range(size): rec = MasterRecord() rec.update(test_data) rec.save(mf) mf.commit() assert len(mf) == size assert mf[90].v50.data == 'Incl. bibl.' del mf
def test_undelete(): """Create a record and undelete it""" clean_start() mf = MasterFile(testmst) r = MasterRecord() r.update(test_data) r.save(mf) mf.delete(1) mf.commit() r = mf[1] assert r.status == LOGICALLY_DELETED assert mf.xrf[1].status == 'logically deleted' assert len(mf) == 0 mf.undelete(1) r = mf[1] assert r.status == ACTIVE assert mf.xrf[1].status == 'active' assert len(mf) == 1
def test_restore_previous(): """Create a record, modify it, save it and restore previous version""" clean_start() mf = MasterFile(testmst) r = MasterRecord() r.update(test_data) r.save(mf) r[90] = "This is a new field" r.save(mf) prev = mf.previous(r) prev.save(mf) old_r = mf[1] try: old_r[90] assert False, "Field with tag 90 should not exist anymore." except KeyError: pass assert r.status == ACTIVE assert len(old_r) == len(prev)
def test_resave_record(): for ext in ('.mst', '.xrf'): fname = join("..", "sample", 'one%s' % ext) if exists(fname): remove(fname) mf = MasterFile(join("..", "sample", "one.mst")) rec = MasterRecord() rec["300"] = "XXXX" rec.save(mf) print rec del mf mf = MasterFile(join("..", "sample", "one.mst")) rec = MasterRecord(mfn=2) rec["300"] = "XXXX" rec.save(mf) print rec del mf mf = MasterFile(join("..", "sample", "one.mst")) rec = mf[1] rec["300"] = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" rec.save(mf) print rec del mf
def test_update_flagsFFI(): """Test update flags (xrf and master files - FFI)""" xref_fd = join('fixtures', 'testflag.xrf') db_fd = join('fixtures', 'testflag.mst') ini_fd = join('fixtures', 'testflag.ini') if exists(xref_fd): remove(xref_fd) if exists(db_fd): remove(db_fd) f = open(ini_fd, "w") f.write( "[Engine]\nINPUT_ENCODING = cp850\nOUTPUT_ENCODING = utf-8\n[IsisDB]\nLEADER_XL=True" ) f.write("\nDIR_MASK = iii\nLEADER_MASK_XL = iiHHiiHH") f.close() dbtest = MasterFile(db_fd) rec = MasterRecord() rec.update(test_data) rec.save(dbtest) rec = dbtest[1] xrf_rec = dbtest.xrf[1] assert xrf_rec.status == 'active' assert xrf_rec.new_flag == True assert xrf_rec.modified_flag == False assert rec.mfbwb == 0 assert rec.mfbwp == 0 rec = dbtest[1] rec[27] = 'Test new field' rec.save(dbtest) rec = dbtest[1] xrf_rec = dbtest.xrf[1] assert xrf_rec.new_flag == True assert xrf_rec.modified_flag == False assert rec.mfbwb == 0 assert rec.mfbwp == 0 dbtest.invertdb(expr='70 0 MHU,(V70/)') rec = dbtest[1] xrf_rec = dbtest.xrf[1] assert xrf_rec.new_flag == False assert xrf_rec.modified_flag == False assert rec.mfbwb == 0 assert rec.mfbwp == 0 rec[100] = 'new field 100' rec.save(dbtest) rec = dbtest[1] xrf_rec = dbtest.xrf[1] assert xrf_rec.new_flag == False assert xrf_rec.modified_flag == True assert rec.mfbwb > 0 assert rec.mfbwp > 0 dbtest.invertdb(expr='70 0 MHU,(V70/)') rec = dbtest[1] xrf_rec = dbtest.xrf[1] assert xrf_rec.new_flag == False assert xrf_rec.modified_flag == False assert rec.mfbwb == 0 assert rec.mfbwp == 0