Esempio n. 1
0
def test_user_dict_identity():
    for n in NICK_VALS:
        for pk in [Pubkey(v.to_bytes(32, byteorder='big')) for v in PK_VALS]:
            for rowid in {None, 44}:
                first = User(n, pk, rowid=rowid)
                second = User.from_dict(first.to_dict())
                assert first == second
Esempio n. 2
0
def test_user_from_dict():
    for n in NICK_VALS:
        for pk in [Pubkey(v.to_bytes(32, byteorder='big')) for v in PK_VALS]:
            u_expect = User(n, pk)
            pk_b64_bytes = b64encode(bytes(pk)).decode('utf-8')
            u_actual = User.from_dict({'nick': n, 'pk': pk_b64_bytes})
            assert u_expect == u_actual
Esempio n. 3
0
def test_user_init():
    for n in NICK_VALS:
        for pk in [Pubkey(v.to_bytes(32, byteorder='big')) for v in PK_VALS]:
            u = User(n, pk)
            assert u.nick == n
            assert u.pk == pk
            assert u.rowid is None
Esempio n. 4
0
def test_accountreq_from_dict():
    d = {
        'nick': U.nick,
        'pk': b64encode(bytes(U.pk)).decode('utf-8'),
    }
    ar = account.AccountReq.from_dict(d)
    assert ar.nick == d['nick']
    assert ar.pk == Pubkey(b64decode(d['pk']))
from rela.lib.messages.location import LocationUpdate, LocationUpdateResp,\
    LocationUpdateRespErr
from rela.lib.messages.account import AccountCred
from rela.lib.messages import EncryptedMessage, Stub
from rela.lib.location import Location, Coords
from rela.lib.user import User
from rela.lib.crypto import Pubkey, Enckey
import time

U = User('Foo', Pubkey((1).to_bytes(32, byteorder='big')), rowid=420)
C = Coords(4, 20)
LOC = Location(U, C, time.time())


def fake_cred():
    cred = AccountCred(U, time.time())
    return EncryptedMessage.enc(cred, Enckey.gen())


def test_locationupdate_init():
    cred = fake_cred()
    lu = LocationUpdate(LOC, cred)
    assert lu.loc == LOC
    assert lu.cred == cred


def test_locationupdate_str():
    cred = fake_cred()
    lu = LocationUpdate(LOC, cred)
    s = 'LocationUpdate<%s %s>' % (LOC, cred)
    assert str(lu) == s
Esempio n. 6
0
from rela.lib.location import Coords, Location
from rela.lib.user import User
from rela.lib.crypto import Pubkey
import pytest
import time

U = User('Sam', Pubkey((1).to_bytes(32, byteorder='big')))

TEST_COORDS_GOOD = [
    (44, 0), (-44, 0),
    (0, 44), (0, -44),
    (-90, -180), (-90, 180),
    (90, 180), (90, -180),
    (0, 0),
    (0.00001, 0), (0.00001, 0.00001), (0, 0.00001),
]

TEST_COORDS_BAD = [
    (-90.00001, 0), (90.00001, 0),
    (0, 180.000001), (0, -180.000001),
]


def test_coords_init_happy():
    for lat, long in TEST_COORDS_GOOD:
        loc = Coords(lat, long)
        assert loc.lat == lat
        assert loc.long == long


def test_coords_init_bad():
Esempio n. 7
0
def test_accountreq_to_dict():
    ar = account.AccountReq(U.nick, U.pk)
    d = ar.to_dict()
    assert d['nick'] == U.nick
    assert Pubkey(b64decode(d['pk'])) == U.pk
Esempio n. 8
0
def test_user_dict_no_pk():
    d = User('', Pubkey((0).to_bytes(32, byteorder='big'))).to_dict()
    del d['pk']
    assert User.from_dict(d) is None
Esempio n. 9
0
def test_user_str():
    for n in NICK_VALS:
        for pk in [Pubkey(v.to_bytes(32, byteorder='big')) for v in PK_VALS]:
            s = 'User<%s %s %s>' % (None, n, pk)
            u = User(n, pk)
            assert str(u) == s