def test_datify(): """ Test convert dict to dataclass dataclass, astuple, asdict, fields, """ @dataclass class Point: x: float y: float @dataclass class Line: a: Point b: Point line = Line(Point(1, 2), Point(3, 4)) assert line == datify(Line, asdict(line)) assert asdict(line) == {'a': {'x': 1, 'y': 2}, 'b': {'x': 3, 'y': 4}} pdict = dict(x=3, y=4) pdata = datify(Point, pdict) assert isinstance(pdata, Point) """End Test"""
def test_deserialization(): @dataclass class Record: first: str # first name last: str # last name street: str # street address city: str # city name state: str # state code zip: int # zip code msgp = b'\x86\xa5first\xa3Jim\xa4last\xa5Black\xa6street\xaf100 Main Street\xa4city\xa8Riverton\xa5state\xa2UT\xa3zip\xce\x00\x01HZ' cbor = b'\xa6efirstcJimdlasteBlackfstreeto100 Main StreetdcityhRivertonestatebUTczip\x1a\x00\x01HZ' json = b'{"first": "Jim", "last": "Black", "street": "100 Main Street", "city": "Riverton", "state": "UT", "zip": 84058}' with dbing.openLMDB() as db: k = basing.Komer(db=db, schema=Record, subdb='records.') desrl = k._deserializer(Serials.mgpk) actual = helping.datify(Record, desrl(msgp)) assert actual.first == "Jim" assert actual.last == "Black" assert actual.street == "100 Main Street" assert actual.city == "Riverton" assert actual.state == "UT" assert actual.zip == 84058 desrl = k._deserializer(Serials.json) actual = helping.datify(Record, desrl(json)) assert actual.first == "Jim" assert actual.last == "Black" assert actual.street == "100 Main Street" assert actual.city == "Riverton" assert actual.state == "UT" assert actual.zip == 84058 desrl = k._deserializer(Serials.cbor) actual = helping.datify(Record, desrl(cbor)) assert actual.first == "Jim" assert actual.last == "Black" assert actual.street == "100 Main Street" assert actual.city == "Riverton" assert actual.state == "UT" assert actual.zip == 84058
def test_datify(): """ Test convert dict to dataclass dataclass, astuple, asdict, fields, """ @dataclass class Point: x: float y: float @dataclass class Line: a: Point b: Point line = Line(Point(1, 2), Point(3, 4)) assert line == datify(Line, asdict(line)) assert asdict(line) == {'a': {'x': 1, 'y': 2}, 'b': {'x': 3, 'y': 4}} pdict = dict(x=3, y=4) pdata = datify(Point, pdict) assert isinstance(pdata, Point) @dataclass class Circle: radius: float @staticmethod def _der(d): p = d["perimeter"] r = p / 2 / 3.14 return Circle(radius=r) d = {'area': 50.24, 'perimeter': 25.12} c = datify(Circle, d) assert c.radius == 4 """End Test"""
def test_manager(): """ test Manager class """ manager = keeping.Manager() assert isinstance(manager, keeping.Manager) assert isinstance(manager.keeper, keeping.Keeper) assert manager.keeper.opened manager.keeper.close(clear=True) assert not os.path.exists(manager.keeper.path) assert not manager.keeper.opened raw = b'0123456789abcdef' salt = coring.Salter(raw=raw).qb64 stem = "red" assert salt == '0AMDEyMzQ1Njc4OWFiY2RlZg' ser = bytes( b'{"vs":"KERI10JSON0000fb_","pre":"EvEnZMhz52iTrJU8qKwtDxzmypyosgG' b'70m6LIjkiCdoI","sn":"0","ilk":"icp","sith":"1","keys":["DSuhyBcP' b'ZEZLK-fcw5tzHn2N46wRCG_ZOoeKtWTOunRA"],"nxt":"EPYuj8mq_PYYsoBKkz' b'X1kxSPGYBWaIya3slgCOyOtlqU","toad":"0","wits":[],"cnfg":[]}-AABA' b'ApYcYd1cppVg7Inh2YCslWKhUwh59TrPpIoqWxN2A38NCbTljvmBPBjSGIFDBNOv' b'VjHpdZlty3Hgk6ilF8pVpAQ') with keeping.openKS() as keeper: manager = keeping.Manager(keeper=keeper, salt=salt) assert manager.keeper.opened assert manager._pidx == 0 assert manager._salt == '' # zeroed out assert manager._tier == coring.Tiers.low # salty algorithm incept verfers, digers, cst, nst = manager.incept( salt=salt, temp=True) # algo default salty assert len(verfers) == 1 assert len(digers) == 1 assert cst == '1' assert nst == '1' assert manager.getPidx() == 1 spre = verfers[0].qb64b assert spre == b'DVG3IcCNK4lpFfpMM-9rfkY3XVUcCu5o5cxzv1lgMqxM' pp = json.loads(bytes(manager.keeper.getPrm(key=spre)).decode("utf-8")) pp = helping.datify(keeping.PrePrm, pp) assert pp.pidx == 0 assert pp.algo == keeping.Algos.salty assert pp.salt == salt assert pp.stem == '' assert pp.tier == coring.Tiers.low ps = json.loads(bytes(manager.keeper.getSit(key=spre)).decode("utf-8")) ps = helping.datify(keeping.PreSit, ps) assert ps.old.pubs == [] assert len(ps.new.pubs) == 1 assert ps.new.pubs == ['DVG3IcCNK4lpFfpMM-9rfkY3XVUcCu5o5cxzv1lgMqxM'] assert ps.new.ridx == 0 assert ps.new.kidx == 0 assert len(ps.nxt.pubs) == 1 assert ps.nxt.pubs == ['DcHJWO4GszUP0rvVO4Tl2rUdUM1Ln5osP7BwiUeJWhdc'] assert ps.nxt.ridx == 1 assert ps.nxt.kidx == 1 keys = [verfer.qb64 for verfer in verfers] assert keys == ps.new.pubs # test .pubs db pl = json.loads( bytes(manager.keeper.getPubs( key=keeping.riKey(spre, ps.new.ridx))).decode("utf-8")) assert pl == ps.new.pubs pl = json.loads( bytes(manager.keeper.getPubs( key=keeping.riKey(spre, ps.nxt.ridx))).decode("utf-8")) assert pl == ps.nxt.pubs digs = [diger.qb64 for diger in digers] assert digs == ['E8UYvbKn7KYw9e4F2DR-iduGtdA1o16ePAYjpyCYSeYo'] oldspre = spre spre = b'DCu5o5cxzv1lgMqxMVG3IcCNK4lpFfpMM-9rfkY3XVUc' manager.move(old=oldspre, new=spre) # test .pubs db after move pl = json.loads( bytes(manager.keeper.getPubs( key=keeping.riKey(spre, ps.new.ridx))).decode("utf-8")) assert pl == ps.new.pubs pl = json.loads( bytes(manager.keeper.getPubs( key=keeping.riKey(spre, ps.nxt.ridx))).decode("utf-8")) assert pl == ps.nxt.pubs psigers = manager.sign(ser=ser, pubs=ps.new.pubs) for siger in psigers: assert isinstance(siger, coring.Siger) vsigers = manager.sign(ser=ser, verfers=verfers) psigs = [siger.qb64 for siger in psigers] vsigs = [siger.qb64 for siger in vsigers] assert psigs == vsigs assert psigs == [ 'AAGu9G-EJ0zrRjrDKnHszLVcwhbkSRxniDJFmB2eWcRiFzNFw1QM5GHQnmnXz385SgunZH4sLidCMyzhJWmp1IBw' ] # Test sign with indices indices = [3] # Test with pubs list psigers = manager.sign(ser=ser, pubs=ps.new.pubs, indices=indices) for siger in psigers: assert isinstance(siger, coring.Siger) assert psigers[0].index == indices[0] psigs = [siger.qb64 for siger in psigers] assert psigs == [ 'ADGu9G-EJ0zrRjrDKnHszLVcwhbkSRxniDJFmB2eWcRiFzNFw1QM5GHQnmnXz385SgunZH4sLidCMyzhJWmp1IBw' ] # Test with verfers list vsigers = manager.sign(ser=ser, verfers=verfers, indices=indices) for siger in vsigers: assert isinstance(siger, coring.Siger) assert psigers[0].index == indices[0] vsigs = [siger.qb64 for siger in vsigers] assert vsigs == psigs pcigars = manager.sign(ser=ser, pubs=ps.new.pubs, indexed=False) for cigar in pcigars: assert isinstance(cigar, coring.Cigar) vcigars = manager.sign(ser=ser, verfers=verfers, indexed=False) psigs = [cigar.qb64 for cigar in pcigars] vsigs = [cigar.qb64 for cigar in vcigars] assert psigs == vsigs assert psigs == [ '0BGu9G-EJ0zrRjrDKnHszLVcwhbkSRxniDJFmB2eWcRiFzNFw1QM5GHQnmnXz385SgunZH4sLidCMyzhJWmp1IBw' ] # salty algorithm rotate oldpubs = [verfer.qb64 for verfer in verfers] verfers, digers, cst, nst = manager.rotate(pre=spre.decode("utf-8")) assert len(verfers) == 1 assert len(digers) == 1 assert cst == '1' assert nst == '1' pp = json.loads(bytes(manager.keeper.getPrm(key=spre)).decode("utf-8")) pp = helping.datify(keeping.PrePrm, pp) assert pp.pidx == 0 assert pp.algo == keeping.Algos.salty assert pp.salt == salt assert pp.stem == '' assert pp.tier == coring.Tiers.low ps = json.loads(bytes(manager.keeper.getSit(key=spre)).decode("utf-8")) ps = helping.datify(keeping.PreSit, ps) assert ps.old.pubs == ['DVG3IcCNK4lpFfpMM-9rfkY3XVUcCu5o5cxzv1lgMqxM'] assert len(ps.new.pubs) == 1 assert ps.new.pubs == ['DcHJWO4GszUP0rvVO4Tl2rUdUM1Ln5osP7BwiUeJWhdc'] assert ps.new.ridx == 1 assert ps.new.kidx == 1 assert len(ps.nxt.pubs) == 1 assert ps.nxt.pubs == ['DRpGly44ejh01ur4ltL_LVrYcyqVCQyVLJnqWrVa57Yc'] assert ps.nxt.ridx == 2 assert ps.nxt.kidx == 2 keys = [verfer.qb64 for verfer in verfers] assert keys == ps.new.pubs digs = [diger.qb64 for diger in digers] assert digs == ['EJUzDm_HbdIZDp94OlIoZH1gcaSdWLZhJwqKz2rVJZrc'] assert oldpubs == ps.old.pubs # salty algorithm rotate oldpubs = [verfer.qb64 for verfer in verfers] deadpubs = ps.old.pubs verfers, digers, cst, nst = manager.rotate(pre=spre.decode("utf-8")) assert cst == '1' assert nst == '1' pp = json.loads(bytes(manager.keeper.getPrm(key=spre)).decode("utf-8")) pp = helping.datify(keeping.PrePrm, pp) assert pp.pidx == 0 ps = json.loads(bytes(manager.keeper.getSit(key=spre)).decode("utf-8")) ps = helping.datify(keeping.PreSit, ps) assert oldpubs == ps.old.pubs for pub in deadpubs: assert not manager.keeper.getPri(key=pub.encode("utf-8")) # test .pubs db pl = json.loads( bytes(manager.keeper.getPubs( key=keeping.riKey(spre, ps.new.ridx))).decode("utf-8")) assert pl == ps.new.pubs pl = json.loads( bytes(manager.keeper.getPubs( key=keeping.riKey(spre, ps.nxt.ridx))).decode("utf-8")) assert pl == ps.nxt.pubs # salty algorithm rotate to null verfers, digers, cst, nst = manager.rotate(pre=spre.decode("utf-8"), count=0) assert cst == '1' assert nst == '0' pp = json.loads(bytes(manager.keeper.getPrm(key=spre)).decode("utf-8")) pp = helping.datify(keeping.PrePrm, pp) assert pp.pidx == 0 ps = json.loads(bytes(manager.keeper.getSit(key=spre)).decode("utf-8")) ps = helping.datify(keeping.PreSit, ps) assert digers == [] assert ps.nxt.pubs == [] # attempt to rotate after null with pytest.raises(ValueError) as ex: # attempt to reincept same pre verfers, digers, cst, nst = manager.rotate( pre=spre.decode("utf-8")) assert ex.value.args[0].startswith( 'Attempt to rotate nontransferable ') # randy algo incept verfers, digers, cst, nst = manager.incept(algo=keeping.Algos.randy) assert len(verfers) == 1 assert len(digers) == 1 assert cst == '1' assert nst == '1' assert manager.getPidx() == 2 rpre = verfers[0].qb64b pp = json.loads(bytes(manager.keeper.getPrm(key=rpre)).decode("utf-8")) pp = helping.datify(keeping.PrePrm, pp) assert pp.pidx == 1 assert pp.algo == keeping.Algos.randy assert pp.salt == '' assert pp.stem == '' assert pp.tier == '' ps = json.loads(bytes(manager.keeper.getSit(key=rpre)).decode("utf-8")) ps = helping.datify(keeping.PreSit, ps) assert ps.old.pubs == [] assert len(ps.new.pubs) == 1 assert ps.new.ridx == 0 assert ps.new.kidx == 0 assert len(ps.nxt.pubs) == 1 assert ps.nxt.ridx == 1 assert ps.nxt.kidx == 1 keys = [verfer.qb64 for verfer in verfers] for key in keys: val = bytes(manager.keeper.getPri(key.encode("utf-8"))) digs = [diger.qb64 for diger in digers] assert len(digs) == 1 oldrpre = rpre rpre = b'DMqxMVG3IcCNK4lpFfCu5o5cxzv1lgpMM-9rfkY3XVUc' manager.move(old=oldrpre, new=rpre) # randy algorithm rotate oldpubs = [verfer.qb64 for verfer in verfers] verfers, digers, cst, nst = manager.rotate(pre=rpre.decode("utf-8")) assert cst == '1' assert nst == '1' pp = json.loads(bytes(manager.keeper.getPrm(key=rpre)).decode("utf-8")) pp = helping.datify(keeping.PrePrm, pp) assert pp.pidx == 1 ps = json.loads(bytes(manager.keeper.getSit(key=rpre)).decode("utf-8")) ps = helping.datify(keeping.PreSit, ps) assert oldpubs == ps.old.pubs # randy algo incept with null nxt verfers, digers, cst, nst = manager.incept(algo=keeping.Algos.randy, ncount=0) assert manager.getPidx() == 3 rpre = verfers[0].qb64b assert cst == '1' assert nst == '0' pp = json.loads(bytes(manager.keeper.getPrm(key=rpre)).decode("utf-8")) pp = helping.datify(keeping.PrePrm, pp) assert pp.pidx == 2 ps = json.loads(bytes(manager.keeper.getSit(key=rpre)).decode("utf-8")) ps = helping.datify(keeping.PreSit, ps) assert digers == [] assert ps.nxt.pubs == [] # attempt to rotate after null with pytest.raises(ValueError) as ex: # attempt to reincept same pre verfers, digers, cst, nst = manager.rotate( pre=rpre.decode("utf-8")) # salty algorithm incept with stem verfers, digers, cst, nst = manager.incept( salt=salt, stem=stem, temp=True) # algo default salty assert len(verfers) == 1 assert len(digers) == 1 assert cst == '1' assert nst == '1' assert manager.getPidx() == 4 spre = verfers[0].qb64b assert spre == b'D627iBfehzh966wPzBYjKQuGOSmIkdcR7b14nZv_ULIw' pp = json.loads(bytes(manager.keeper.getPrm(key=spre)).decode("utf-8")) pp = helping.datify(keeping.PrePrm, pp) assert pp.pidx == 3 assert pp.algo == keeping.Algos.salty assert pp.salt == salt assert pp.stem == stem == 'red' assert pp.tier == coring.Tiers.low ps = json.loads(bytes(manager.keeper.getSit(key=spre)).decode("utf-8")) ps = helping.datify(keeping.PreSit, ps) assert ps.old.pubs == [] assert len(ps.new.pubs) == 1 assert ps.new.pubs == ['D627iBfehzh966wPzBYjKQuGOSmIkdcR7b14nZv_ULIw'] assert ps.new.ridx == 0 assert ps.new.kidx == 0 assert len(ps.nxt.pubs) == 1 assert ps.nxt.pubs == ['DHNnq96NI0Bmle_VINGcgX8_VSpxbl3am7ZT6_66Fe8Q'] assert ps.nxt.ridx == 1 assert ps.nxt.kidx == 1 keys = [verfer.qb64 for verfer in verfers] assert keys == ps.new.pubs digs = [diger.qb64 for diger in digers] assert digs == ['EAQ7QvfBLj0OrGTqzJZGutLJowUht_zBA6213agRQ8hA'] # attempt to reincept same first pub with pytest.raises(ValueError) as ex: # attempt to reincept same pre verfers, digers, cst, nst = manager.incept(salt=salt, stem=stem, temp=True) assert ex.value.args[0].startswith('Already incepted pre') oldspre = spre spre = b'DCNK4lpFfpMM-9rfkY3XVUcCu5o5cxzv1lgMqxMVG3Ic' manager.move(old=oldspre, new=spre) # attempt to reincept same first pub after move pre with pytest.raises(ValueError) as ex: # attempt to reincept same pre verfers, digers, cst, nst = manager.incept(salt=salt, stem=stem, temp=True) assert ex.value.args[0].startswith('Already incepted pre') # Create nontransferable keys that are nontransferable identifier prefixes verfers, digers, cst, nst = manager.incept(ncount=0, salt=salt, stem="wit0", transferable=False, temp=True) assert cst == '1' assert nst == '0' wit0pre = verfers[0].qb64 assert verfers[ 0].qb64 == 'B5M0jhHM3vTo15w12pOUYRwxJNaIVS96wSqbFZH-inyc' assert verfers[0].code == coring.MtrDex.Ed25519N assert not digers verfers, digers, cst, nst = manager.incept(ncount=0, salt=salt, stem="wit1", transferable=False, temp=True) assert cst == '1' assert nst == '0' wit1pre = verfers[0].qb64 assert verfers[ 0].qb64 == 'BAH_nE1cfiGjEMK0Ac8U8N51npjBOjyZt3D-_QA4c4y0' assert verfers[0].code == coring.MtrDex.Ed25519N assert not digers assert wit0pre != wit1pre # test .ingest of sequences of keys secrecies = [ ['ArwXoACJgOleVZ2PY7kXn7rA0II0mHYDhc6WrBH8fDAc'], ['A6zz7M08-HQSFq92sJ8KJOT2cZ47x7pXFQLPB0pckB3Q'], ['AcwFTk-wgk3ZT2buPRIbK-zxgPx-TKbaegQvPEivN90Y'], ['Alntkt3u6dDgiQxTATr01dy8M72uuaZEf9eTdM-70Gk8'], ['A1-QxDkso9-MR1A8rZz_Naw6fgaAtayda8hrbkRVVu1E'], ['AKuYMe09COczwf2nIoD5AE119n7GLFOVFlNLxZcKuswc'], ['AxFfJTcSuEE11FINfXMqWttkZGnUZ8KaREhrnyAXTsjw'], ['ALq-w1UKkdrppwZzGTtz4PWYEeWm0-sDHzOv5sq96xJY'], ] pidx, rsalt, rtier = manager.setup() # verify current state assert pidx == 6 assert rsalt == salt == '0AMDEyMzQ1Njc4OWFiY2RlZg' assert rtier == coring.Tiers.low verferies, digers = manager.ingest(secrecies=secrecies) publicies = [] for verfers in verferies: publicies.append([verfer.qb64 for verfer in verfers]) assert publicies == [['DSuhyBcPZEZLK-fcw5tzHn2N46wRCG_ZOoeKtWTOunRA'], ['DVcuJOOJF1IE8svqEtrSuyQjGTd2HhfAkt9y2QkUtFJI'], ['DT1iAhBWCkvChxNWsby2J0pJyxBIxbAtbLA0Ljx-Grh8'], ['DKPE5eeJRzkRTMOoRGVd2m18o8fLqM2j9kaxLhV3x8AQ'], ['D1kcBE7h0ImWW6_Sp7MQxGYSshZZz6XM7OiUE5DXm0dU'], ['D4JDgo3WNSUpt-NG14Ni31_GCmrU0r38yo7kgDuyGkQM'], ['DVjWcaNX2gCkHOjk6rkmqPBCxkRCqwIJ-3OjdYmMwxf4'], ['DT1nEDepd6CSAMCE7NY_jlLdG6_mKUlKS_mW-2HJY1hg']] ipre = publicies[0][0] # test .pris db for i, pubs in enumerate(publicies): pri0 = bytes(manager.keeper.getPri(key=pubs[0])) assert pri0.decode("utf-8") == secrecies[i][0] for pub in pubs: pri = bytes(manager.keeper.getPri(key=pub)) assert pri pp = json.loads(bytes(manager.keeper.getPrm(key=ipre)).decode("utf-8")) pp = helping.datify(keeping.PrePrm, pp) assert pp.pidx == 6 assert manager.getPidx() == 7 ps = json.loads(bytes(manager.keeper.getSit(key=ipre)).decode("utf-8")) ps = helping.datify(keeping.PreSit, ps) assert ps.new.ridx == 7 assert ps.new.pubs == publicies[ps.new.ridx] # test .pubs db for i, pubs in enumerate(publicies): pl = json.loads( bytes(manager.keeper.getPubs( key=keeping.riKey(ipre, i))).decode("utf-8")) assert pl == pubs # nxt pubs pl = json.loads( bytes(manager.keeper.getPubs( key=keeping.riKey(ipre, i + 1))).decode("utf-8")) assert pl assert [diger.qb64 for diger in digers ] == ['Ewt_7B0gfSE7DnMtmNEHiy8BGPVw5at2-e_JgJ1jAfEc'] for i in range(len(publicies)): verfers, digers, cst, nst = manager.replay(ipre, i) assert verfers[0].qb64 == publicies[i][0] assert digers assert cst == nst == '1' with pytest.raises(IndexError): # Test end of replay verfers, digers = manager.replay(ipre, i + 1) with pytest.raises(ValueError): # Test past end of replay verfers, digers = manager.replay(ipre, i + 2) # test .ingest multi-sig of sequences of keys secrecies = [[ 'AgjD4nRlycmM5cPcAkfOATAp8wVldRsnc9f1tiwctXlw', 'AKUotEE0eAheKdDJh9QvNmSEmO_bjIav8V_GmctGpuCQ', 'AK-nVhMMJciMPvmF5VZE_9H-nhrgng9aJWf7_UHPtRNM' ], ['AT2cx-P5YUjIw_SLCHQ0pqoBWGk9s4N1brD-4pD_ANbs'], [ 'Ap5waegfnuP6ezC18w7jQiPyQwYYsp9Yv9rYMlKAYL8k', 'Aqlc_FWWrxpxCo7R12uIz_Y2pHUH2prHx1kjghPa8jT8', 'AagumsL8FeGES7tYcnr_5oN6qcwJzZfLKxoniKUpG4qc' ], ['ADW3o9m3udwEf0aoOdZLLJdf1aylokP0lwwI_M2J9h0s']] pidx, rsalt, rtier = manager.setup() # verify current state assert pidx == 7 assert rsalt == salt == '0AMDEyMzQ1Njc4OWFiY2RlZg' assert rtier == coring.Tiers.low verferies, digers = manager.ingest(secrecies=secrecies, ncount=3) publicies = [] for verfers in verferies: publicies.append([verfer.qb64 for verfer in verfers]) assert publicies == [ [ 'D8KY1sKmgyjAiUDdUBPNPyrSz_ad_Qf9yzhDNZlEKiMc', 'DbWeWTNGXPMQrVuJmScNQn81YF7T2fhh2kXwT8E_NbeI', 'Dmis7BM1brr-1r4DgdO5KMcCf8AnGcUUPhZYUxprI97s' ], ['DfHMsSg0CJCou4erOqaJDr3OyDEikBp5QRp7HjcJGdgw'], [ 'DOaXCkU3Qd0oBSYxGfYtJxUbN6U7VjZiKthPHIHbzabs', 'DLOmEabR-cYJLMrAd0HvQC4lecbF-j2r7w3UQIY3mGMQ', 'DAIyL2yT9nU6kChGXWce8d6q07l0vBLPNImw_f9bazeQ' ], ['D69EflciVP9zgsihNU14Dbm2bPXoNGxKHK_BBVFMQ-YU'] ] ipre = publicies[0][0] # test .pris db for i, pubs in enumerate(publicies): pri0 = bytes(manager.keeper.getPri(key=pubs[0])) assert pri0.decode("utf-8") == secrecies[i][0] for pub in pubs: pri = bytes(manager.keeper.getPri(key=pub)) assert pri pp = json.loads(bytes(manager.keeper.getPrm(key=ipre)).decode("utf-8")) pp = helping.datify(keeping.PrePrm, pp) assert pp.pidx == 7 assert manager.getPidx() == 8 ps = json.loads(bytes(manager.keeper.getSit(key=ipre)).decode("utf-8")) ps = helping.datify(keeping.PreSit, ps) assert ps.new.ridx == 3 assert ps.new.kidx == 7 assert ps.new.pubs == publicies[ps.new.ridx] assert len(ps.nxt.pubs) == 3 # test .pubs db for i, pubs in enumerate(publicies): pl = json.loads( bytes(manager.keeper.getPubs( key=keeping.riKey(ipre, i))).decode("utf-8")) assert pl == pubs # nxt pubs pl = json.loads( bytes(manager.keeper.getPubs( key=keeping.riKey(ipre, i + 1))).decode("utf-8")) assert pl assert [diger.qb64 for diger in digers] == [ 'E7Ch-T3dCZZ_i0u1ACi_Yv1lyyAMoQCT5ar81eUGoPYY', 'EhwPuWbyrJRyU5HpJaoJrq04biTLWx3heNY3TvQrlbU8', 'EJKLXis7QLnodqvtkbkTUKdciTuM-yzhEPUzS9jtxS6Y' ] for i in range(len(publicies)): verfers, digers, cst, nst = manager.replay(ipre, i) assert verfers[0].qb64 == publicies[i][0] assert digers with pytest.raises(IndexError): # Test end of replay verfers, digers = manager.replay(ipre, i + 1) with pytest.raises(ValueError): # Test past end of replay verfers, digers = manager.replay(ipre, i + 2) assert not os.path.exists(manager.keeper.path) assert not manager.keeper.opened """End Test"""
def test_publot_pubsit(): """ test key set tracking and creation parameters """ pre = b'BWzwEHHzq7K0gzQPYGGwTmuupUhPx5_yZ-Wk1x4ejhcc' pub = b'EGAPkzNZMtX-QiVgbRbyAIZGoXvbGv9IPb0foWTZvI_4' pri = b'AaOa6eOCJQcgEozYb1GgV9zE2yPgBXiP6h_J2cZeCy4M' seed = '0AZxWJGkCkpDcHuVG4GM1KVw' pl = keeping.PubLot() assert isinstance(pl, keeping.PubLot) assert pl.pubs == [] assert pl.ridx == 0 assert pl.kidx == 0 assert pl.st == '0' assert pl.dt == '' assert asdict(pl) == dict(pubs=[], ridx=0, kidx=0, st='0', dt='') pl = helping.datify(keeping.PubLot, dict(pubs=[], ridx=0, kidx=0, st=0, dt='')) assert pl.pubs == [] assert pl.ridx == 0 assert pl.kidx == 0 assert pl.st == 0 assert pl.dt == '' # st = coring.Tholder(sith=[["1/2", "1/2", "1/4", "1/4", "1/4"], ["1", "1"]]).limen st = [["1/2", "1/2", "1/4", "1/4", "1/4"], ["1", "1"]] # dt = helping.nowIso8601() dt = '2020-11-16T22:30:34.812526+00:00' pl = keeping.PubLot(pubs=[], ridx=1, kidx=3, st=st, dt=dt) assert pl.pubs == [] assert pl.ridx == 1 assert pl.kidx == 3 # assert pl.st == st == '1/2,1/2,1/4,1/4,1/4&1,1' assert pl.st == st == [["1/2", "1/2", "1/4", "1/4", "1/4"], ["1", "1"]] assert pl.dt == dt == '2020-11-16T22:30:34.812526+00:00' pp = keeping.PrePrm() assert isinstance(pp, keeping.PrePrm) assert pp.pidx == 0 assert pp.algo == keeping.Algos.salty == 'salty' assert pp.stem == '' assert pp.salt == '' assert pp.tier == '' assert asdict(pp) == dict( pidx=0, algo=keeping.Algos.salty, salt='', stem='', tier='', ) pp = helping.datify( keeping.PrePrm, dict( pidx=0, algo=keeping.Algos.salty, salt='', stem='', tier='', )) assert isinstance(pp, keeping.PrePrm) assert pp.pidx == 0 assert pp.algo == keeping.Algos.salty == 'salty' assert pp.stem == '' assert pp.salt == '' assert pp.tier == '' pp = keeping.PrePrm(pidx=1, algo=keeping.Algos.randy) assert pp.pidx == 1 assert pp.algo == keeping.Algos.randy assert pp.salt == '' assert pp.stem == '' assert pp.tier == '' ps = keeping.PreSit() assert isinstance(ps, keeping.PreSit) assert isinstance(ps.old, keeping.PubLot) assert isinstance(ps.new, keeping.PubLot) assert isinstance(ps.nxt, keeping.PubLot) assert ps.old.pubs == [] assert ps.old.ridx == 0 assert ps.old.kidx == 0 assert ps.old.dt == '' assert ps.new.pubs == [] assert ps.new.ridx == 0 assert ps.new.kidx == 0 assert ps.new.dt == '' assert ps.nxt.pubs == [] assert ps.nxt.ridx == 0 assert ps.nxt.kidx == 0 assert ps.nxt.dt == '' assert asdict(ps) == { 'old': { 'pubs': [], 'ridx': 0, 'kidx': 0, 'st': '0', 'dt': '' }, 'new': { 'pubs': [], 'ridx': 0, 'kidx': 0, 'st': '0', 'dt': '' }, 'nxt': { 'pubs': [], 'ridx': 0, 'kidx': 0, 'st': '0', 'dt': '' } } ps = helping.datify( keeping.PreSit, dict( old=dict(pubs=[], ridx=0, kidx=0, st='0', dt=''), new=dict(pubs=[], ridx=0, kidx=0, st='0', dt=''), nxt=dict(pubs=[], ridx=0, kidx=0, st='0', dt=''), )) assert isinstance(ps, keeping.PreSit) assert isinstance(ps.old, keeping.PubLot) assert isinstance(ps.new, keeping.PubLot) assert isinstance(ps.nxt, keeping.PubLot) assert ps.old.pubs == [] assert ps.old.ridx == 0 assert ps.old.kidx == 0 assert ps.old.st == '0' assert ps.old.dt == '' assert ps.new.pubs == [] assert ps.new.ridx == 0 assert ps.new.kidx == 0 assert ps.new.st == '0' assert ps.new.dt == '' assert ps.nxt.pubs == [] assert ps.nxt.ridx == 0 assert ps.nxt.kidx == 0 assert ps.nxt.st == '0' assert ps.nxt.dt == '' old = keeping.PubLot(ridx=0, kidx=0) new = keeping.PubLot(ridx=1, kidx=3) nxt = keeping.PubLot(ridx=2, kidx=6) ps = keeping.PreSit(old=old, new=new, nxt=nxt) assert ps.old.ridx == 0 assert ps.old.kidx == 0 assert ps.new.ridx == 1 assert ps.new.kidx == 3 assert ps.nxt.ridx == 2 assert ps.nxt.kidx == 6 """End Test"""
def test_happy_path(): """ Test Komer object class """ @dataclass class Record: first: str # first name last: str # last name street: str # street address city: str # city name state: str # state code zip: int # zip code def __iter__(self): return iter(asdict(self)) jim = Record(first="Jim", last="Black", street="100 Main Street", city="Riverton", state="UT", zip=84058) jimser = json.dumps(asdict(jim)).encode("utf-8") jim = helping.datify(Record, json.loads(bytes(jimser).decode("utf-8"))) assert isinstance(jim, Record) with dbing.openLMDB() as db: assert isinstance(db, dbing.LMDBer) assert db.name == "test" assert db.opened mydb = basing.Komer(db=db, schema=Record, subdb='records.') assert isinstance(mydb, basing.Komer) sue = Record(first="Susan", last="Black", street="100 Main Street", city="Riverton", state="UT", zip=84058) keys = ("test_key", "0001") mydb.put(keys=keys, data=sue) actual = mydb.get(keys=keys) assert actual.first == "Susan" assert actual.last == "Black" assert actual.street == "100 Main Street" assert actual.city == "Riverton" assert actual.state == "UT" assert actual.zip == 84058 mydb.rem(keys) actual = mydb.get(keys=keys) assert actual is None assert not os.path.exists(db.path) assert not db.opened
def test_kom_happy_path(): """ Test Komer object class """ @dataclass class Record: first: str # first name last: str # last name street: str # street address city: str # city name state: str # state code zip: int # zip code def __iter__(self): return iter(asdict(self)) jim = Record(first="Jim", last="Black", street="100 Main Street", city="Riverton", state="UT", zip=84058) jimser = json.dumps(asdict(jim)).encode("utf-8") jim = helping.datify(Record, json.loads(bytes(jimser).decode("utf-8"))) assert isinstance(jim, Record) with dbing.openLMDB() as db: assert isinstance(db, dbing.LMDBer) assert db.name == "test" assert db.opened mydb = koming.Komer(db=db, schema=Record, subkey='records.') assert isinstance(mydb, koming.Komer) sue = Record(first="Susan", last="Black", street="100 Main Street", city="Riverton", state="UT", zip=84058) keys = ("test_key", "0001") mydb.put(keys=keys, data=sue) actual = mydb.get(keys=keys) assert actual.first == "Susan" assert actual.last == "Black" assert actual.street == "100 Main Street" assert actual.city == "Riverton" assert actual.state == "UT" assert actual.zip == 84058 mydb.rem(keys) actual = mydb.get(keys=keys) assert actual is None keys = ("test_key", "0001") mydb.put(keys=keys, data=sue) actual = mydb.get(keys=keys) assert actual == sue kip = Record(first="Kip", last="Thorne", street="200 Center Street", city="Bluffdale", state="UT", zip=84043) result = mydb.put(keys=keys, data=kip) assert not result actual = mydb.get(keys=keys) assert actual == sue result = mydb.pin(keys=keys, data=kip) assert result actual = mydb.get(keys=keys) assert actual == kip # test with keys as string not tuple keys = "keystr" bob = Record(first="Bob", last="Brown", street="100 Center Street", city="Bluffdale", state="UT", zip=84043) mydb.put(keys=keys, data=bob) actual = mydb.get(keys=keys) assert actual.first == "Bob" assert actual.last == "Brown" assert actual.street == "100 Center Street" assert actual.city == "Bluffdale" assert actual.state == "UT" assert actual.zip == 84043 mydb.rem(keys) actual = mydb.get(keys=keys) assert actual is None assert not os.path.exists(db.path) assert not db.opened