Exemplo n.º 1
0
def test_map_delete_private(app, db):
    m = Map('foo', bbox=[1, 1, 1, 1])
    db.session.add(m)
    db.session.commit()

    token = m.gen_token()
    resp = _get_map(app, m.uuid, token)
    assert (resp.status_code == 200)

    with app.test_client() as client:
        point = GeoFeature(geometry=GeoPoint([1, 1]))
        f = Feature(point)
        m.features.append(f)
        db.session.add(m)
        db.session.commit()

        url = '/api/maps/{}'.format(m.uuid)
        resp = client.delete(url)
        assert (resp.status_code == 401
                )  # TODO: should be 404 for private maps

        headers = {'X-MAP': m.uuid, 'X-TOKEN': token}
        resp = client.delete(url, headers=headers)
        assert (resp.status_code == 204)

    assert (not Map.get(m.uuid))
    resp = _get_map(app, m.uuid, token)
    assert (resp.status_code == 404)
Exemplo n.º 2
0
def test_maps_new_public(app, db):
    m = Map('foo-new-public', bbox=[1, 1, 1, 1])
    db.session.add(m)
    db.session.commit()

    assert (not m.published)

    m.published = True
    db.session.add(m)
    db.session.commit()

    resp = _get_map(app, m.uuid)
    assert (resp.status_code == 200)

    resp = _get_map(app, m.uuid, m.gen_token())
    assert (resp.status_code == 200)
Exemplo n.º 3
0
def test_map_lifespan(app, db):
    now = datetime.datetime.utcnow()
    m = Map('foo-lifespan', datetime=now, published=True, bbox=[1, 1, 1, 1])
    db.session.add(m)
    db.session.commit()
    assert (not m.outdated)

    token = m.gen_token()
    resp = _get_map(app, m.uuid, token)
    assert (resp.status_code == 200)

    m.datetime = now - datetime.timedelta(days=31)
    db.session.add(m)
    db.session.commit()

    assert (m.outdated)

    resp = _get_map(app, m.uuid, token)
    assert (resp.status_code == 404)