Exemplo n.º 1
0
def test_getinfoloc_happy_default():
    db_conn = get_db()
    u_me = db.user_with_pk(db_conn, U1.pk)
    u_other = db.user_with_pk(db_conn, U2.pk)
    insert_many_locs(db_conn, u_other)
    ecred = get_cred(u_me)
    gi = SignedMessage.sign(getinfo.GetInfoLocation(u_other.pk, ecred), SK1)
    gir = server.handle_getinfo(db_conn, gi)
    assert gir.ok
    assert gir.err is None
    assert len(gir.locs) == 1
Exemplo n.º 2
0
def test_getinfoloc_multiple_count_correct_3():
    db_conn = get_db()
    u_me = db.user_with_pk(db_conn, U1.pk)
    u_other = db.user_with_pk(db_conn, U2.pk)
    num_locs = insert_many_locs(db_conn, u_other)
    ecred = get_cred(u_me)
    gi = SignedMessage.sign(
        getinfo.GetInfoLocation(u_other.pk, ecred, count=num_locs + 10), SK1)
    gir = server.handle_getinfo(db_conn, gi)
    assert gir.ok
    assert gir.err is None
    assert len(gir.locs) == num_locs
Exemplo n.º 3
0
def test_getinfoloc_multiple_order_correct_2():
    db_conn = get_db()
    u_me = db.user_with_pk(db_conn, U1.pk)
    u_other = db.user_with_pk(db_conn, U2.pk)
    insert_many_locs(db_conn, u_other)
    # when asking for newest=False, we should get the oldest location first,
    # thus it should have the min time of all locations
    min_time = min(
        [loc.time for loc in db.locations_for_user(db_conn, u_other)])
    ecred = get_cred(u_me)
    gi = SignedMessage.sign(
        getinfo.GetInfoLocation(u_other.pk, ecred, count=1, newest=False), SK1)
    gir = server.handle_getinfo(db_conn, gi)
    assert gir.ok
    assert gir.err is None
    assert len(gir.locs) == 1
    assert gir.locs[0].time == min_time
Exemplo n.º 4
0
def test_getinfoloc_multiple_order_correct_3():
    db_conn = get_db()
    u_me = db.user_with_pk(db_conn, U1.pk)
    u_other = db.user_with_pk(db_conn, U2.pk)
    num_locs = insert_many_locs(db_conn, u_other)
    # when not asking for a specfic order, we get the newest location first,
    # every subsequent location should have a smaller time
    ecred = get_cred(u_me)
    gi = SignedMessage.sign(
        getinfo.GetInfoLocation(u_other.pk, ecred, count=num_locs), SK1)
    gir = server.handle_getinfo(db_conn, gi)
    assert gir.ok
    assert gir.err is None
    assert len(gir.locs) == num_locs
    last_time = 999999999999999
    for loc in gir.locs:
        assert loc.time < last_time
        last_time = loc.time
Exemplo n.º 5
0
def test_getinfo_location(client):
    u_us = db.user_with_pk(flask.g.db, U1.pk)
    u_them = db.user_with_pk(flask.g.db, U2.pk)
    ecred = get_cred(u_us)
    loc = loca.Location(u_them, loca.Coords(12, 34), time.time())
    db.insert_location(flask.g.db, loc)
    gil = getinfo.GetInfoLocation(u_them.pk, ecred, count=1)
    req = SignedMessage.sign(gil, SK1)
    rv = client.post(
        '/getinfo/location',
        json=req.to_dict(),
    )
    assert rv.status_code == 200
    resp = Message.from_dict(rv.json)
    assert isinstance(resp, getinfo.GetInfoRespLocation)
    assert resp.ok
    assert resp.err is None
    assert len(resp.locs) == 1
    assert resp.locs[0] == loc