示例#1
0
def maps_new():
    if ('name' not in request.json):
        abort(400)

    json = request.json
    name = json['name']

    m = Map(name)
    for key in [
            'name', 'bbox', 'description', 'place', 'attributes', 'published',
            'theme'
    ]:
        if key in json:
            setattr(m, key, json[key])

    if 'theme' in json and json['theme'] in current_app.config['MAP_RENDERER']:
        m.theme = json['theme']

    if 'datetime' in json:
        m.datetime = datetime_fromisoformat(request.json['datetime'])

    if 'lifespan' in json:
        m.lifespan = timedelta(days=request.json['lifspan'])

    db.session.add(m)
    db.session.commit()

    return make_response(jsonify(m.to_dict(secret_included=True)), 201)
示例#2
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)