예제 #1
0
def test_node_members_of_relation(conn):
    conn.execute('''
        INSERT INTO nodes VALUES (10000, true, false, false, 10090, ST_SetSRID(ST_MakePoint(0, 0.0), 4326), 'u1', 10080, '2018-11-15 17:20:04+00', 1, '');
        INSERT INTO nodes VALUES (10010, true, false, false, 10090, ST_SetSRID(ST_MakePoint(0, 0.0), 4326), 'u1', 10080, '2018-11-15 17:20:04+00', 1, '');
        INSERT INTO nodes VALUES (10011, true, false, false, 10090, ST_SetSRID(ST_MakePoint(0, 0.0), 4326), 'u1', 10080, '2018-11-15 17:20:04+00', 1, '');

        INSERT INTO ways VALUES (10050, true, false, false, 10090, 'u1', 10080, '2018-11-15 17:20:04+00', 1, '"comment"=>"new way", "highway"=>"secondary"');
        INSERT INTO nds VALUES (10050, 1, 0, 10010);
        INSERT INTO nds VALUES (10050, 1, 1, 10011);

        INSERT INTO relations VALUES (10070, true, false, false, 10091, 'u1', 10080, '2018-11-15 17:20:04+00', 1, '"comment"=>"new way", "type"=>"route"');

        INSERT INTO members VALUES (10070, 1, 0, 'node', 'stop',10000, null, null);
        INSERT INTO members VALUES (10070, 1, 1, 'node', 'stop', 10001, null, null); -- missing
        INSERT INTO members VALUES (10070, 1, 2, 'way', '', null, 10050, null);

        INSERT INTO changesets VALUES (10091, '2018-11-15 17:20:04+00', '2018-11-15 17:20:04+00', 1, false, 'u1', 10080, '', ST_MakeEnvelope(0, 0, 0, 0, 4326));
        ''',
                 multi=True)

    changes = collect_changeset(conn, 10091)
    assert changes['changes']['ways'] == []
    assert changes['changes']['nodes'] == []
    assert changes['changes']['relations'] == [{
        'added': True,
        'deleted': False,
        'id': 10070L,
        'key': '10070-1',
        'modified': False,
        'prevKey': None,
        'version': 1
    }]
예제 #2
0
def test_relation_members_of_relation(conn):
    conn.execute('''
        INSERT INTO nodes VALUES (10000, true, false, false, 10090, ST_SetSRID(ST_MakePoint(0, 0.0), 4326), 'u1', 10080, '2018-11-15 17:20:04+00', 1, '');

        INSERT INTO relations VALUES (10070, true, false, false, 10090, 'u1', 10080, '2018-11-15 17:20:04+00', 1, '"comment"=>"new way", "type"=>"route"');
        INSERT INTO members VALUES (10070, 1, 0, 'node', '', 10000, null, null);

        INSERT INTO relations VALUES (10071, true, false, false, 10091, 'u1', 10080, '2018-11-15 17:20:04+00', 1, '"comment"=>"new way", "type"=>"route"');
        INSERT INTO members VALUES (10071, 1, 0, 'relation', '', null, null, 10070);

        -- newer version, not to be returned
        INSERT INTO relations VALUES (10071, true, false, false, 10099, 'u1', 10080, '2018-11-15 17:20:04+00', 2, '"comment"=>"new way", "type"=>"route"');
        INSERT INTO members VALUES (10071, 2, 0, 'relation', '', null, null, 10070);

        INSERT INTO changesets VALUES (10091, '2018-11-15 17:20:04+00', '2018-11-15 17:20:04+00', 1, false, 'u1', 10080, '', ST_MakeEnvelope(0, 0, 0, 0, 4326));
        ''',
                 multi=True)

    changes = collect_changeset(conn, 10091)
    assert changes['changes']['ways'] == []
    assert changes['changes']['nodes'] == []
    assert changes['changes']['relations'] == [{
        'added': True,
        'deleted': False,
        'id': 10071L,
        'key': '10071-1',
        'modified': False,
        'prevKey': None,
        'version': 1
    }]
예제 #3
0
def test_way_members_of_relation(conn):
    conn.execute('''
        -- complete way
        INSERT INTO nodes VALUES (10000, true, false, false, 10090, ST_SetSRID(ST_MakePoint(0, 0.0), 4326), 'u1', 10080, '2018-11-15 17:20:04+00', 1, '');
        INSERT INTO nodes VALUES (10001, true, false, false, 10090, ST_SetSRID(ST_MakePoint(0, 0.0), 4326), 'u1', 10080, '2018-11-15 17:20:04+00', 1, '');
        INSERT INTO ways VALUES (10050, true, false, false, 10090, 'u1', 10080, '2018-11-15 17:20:04+00', 1, '"comment"=>"new way", "highway"=>"secondary"');
        INSERT INTO nds VALUES (10050, 1, 0, 10000);
        INSERT INTO nds VALUES (10050, 1, 1, 10001);

        -- incomplete way
        INSERT INTO nodes VALUES (10002, true, false, false, 10090, ST_SetSRID(ST_MakePoint(0, 0.0), 4326), 'u1', 10080, '2018-11-15 17:20:04+00', 1, '');
        INSERT INTO ways VALUES (10051, true, false, false, 10090, 'u1', 10080, '2018-11-15 17:20:04+00', 1, '"comment"=>"new way", "highway"=>"secondary"');
        INSERT INTO nds VALUES (10051, 1, 0, 10002);
        INSERT INTO nds VALUES (10051, 1, 1, 10003); -- missing

        -- newer version, not to be returned
        INSERT INTO ways VALUES (10050, true, false, false, 10099, 'u1', 10080, '2018-11-15 17:20:04+00', 2, '"comment"=>"new way", "highway"=>"secondary"');
        INSERT INTO nds VALUES (10050, 2, 0, 10000);
        INSERT INTO nds VALUES (10050, 2, 1, 10001);

        -- relation with complete, incomplete and missing way members
        INSERT INTO relations VALUES (10070, true, false, false, 10091, 'u1', 10080, '2018-11-15 17:20:04+00', 1, '"comment"=>"new way", "type"=>"route"');
        INSERT INTO members VALUES (10070, 1, 0, 'way', '', null, 10050, null);
        INSERT INTO members VALUES (10070, 1, 1, 'way', '', null, 10051, null); -- incomplete
        INSERT INTO members VALUES (10070, 1, 2, 'way', '', null, 10052, null); -- missing

        -- newer version, not to be returned
        INSERT INTO relations VALUES (10070, true, false, false, 10099, 'u1', 10080, '2018-11-15 17:20:04+00', 2, '"comment"=>"new way", "type"=>"route"');
        INSERT INTO members VALUES (10070, 2, 0, 'way', '', null, 10051, null); -- incomplete
        INSERT INTO members VALUES (10070, 2, 2, 'way', '', null, 10050, null);
        INSERT INTO members VALUES (10070, 2, 1, 'way', '', null, 10052, null); -- missing

        INSERT INTO changesets VALUES (10091, '2018-11-15 17:20:04+00', '2018-11-15 17:20:04+00', 1, false, 'u1', 10080, '', ST_MakeEnvelope(0, 0, 0, 0, 4326));
        ''',
                 multi=True)

    changes = collect_changeset(conn, 10091)
    assert changes['changes']['ways'] == []
    assert changes['changes']['nodes'] == []
    assert changes['changes']['relations'] == [{
        'added': True,
        'deleted': False,
        'id': 10070L,
        'key': '10070-1',
        'modified': False,
        'prevKey': None,
        'version': 1
    }]
예제 #4
0
def test_missing_changeset(conn):
    changes = collect_changeset(conn, 1)
    assert changes == {
        'changeset': {
            'id': 1
        },
        'changes': {
            'nodes': [],
            'ways': [],
            'relations': []
        },
        'elements': {
            'nodes': {},
            'ways': {},
            'relations': {}
        },
    }
예제 #5
0
def test_multiple_node_versions(conn):
    conn.execute('''
        INSERT INTO nodes VALUES (10000, true, false, false, 10090, ST_SetSRID(ST_MakePoint(0, 0.0), 4326), 'u1', 10080, '2018-11-15 17:20:04+00', 1, '');
        INSERT INTO nodes VALUES (10001, true, false, false, 10090, ST_SetSRID(ST_MakePoint(0, 0.1), 4326), 'u1', 10080, '2018-11-15 17:20:04+00', 1, '"comment"=>"created"');
        INSERT INTO nodes VALUES (10001, false, true, false, 10092, ST_SetSRID(ST_MakePoint(0, 0.2), 4326), 'u1', 10080, '2018-11-15 17:22:04+00', 2, '"comment"=>"mod 2"');
        INSERT INTO nodes VALUES (10001, false, true, false, 10093, ST_SetSRID(ST_MakePoint(0, 0.3), 4326), 'u1', 10080, '2018-11-15 17:23:04+00', 3, '"comment"=>"mod 3"');
        INSERT INTO nodes VALUES (10001, false, true, false, 10094, ST_SetSRID(ST_MakePoint(0, 0.4), 4326), 'u1', 10080, '2018-11-15 17:24:04+00', 4, '"comment"=>"mod 4"');
        INSERT INTO nodes VALUES (10001, false, true, false, 10095, ST_SetSRID(ST_MakePoint(0, 0.5), 4326), 'u1', 10080, '2018-11-15 17:25:04+00', 5, '"comment"=>"mod 5"');
        INSERT INTO nodes VALUES (10001, false, false, true, 10096, ST_SetSRID(ST_MakePoint(0, 0.5), 4326), 'u1', 10080, '2018-11-15 17:26:04+00', 6, '"comment"=>"delete"');

        INSERT INTO ways VALUES (10050, true, false, false, 10090, 'u1', 10080, '2018-11-15 17:20:04+00', 1, '"comment"=>"new way", "highway"=>"secondary"');
        INSERT INTO nds VALUES (10050, 1, 0, 10000);
        INSERT INTO nds VALUES (10050, 1, 1, 10001);

        INSERT INTO ways VALUES (10050, false, true, false, 10091, 'u1', 10080, '2018-11-15 17:20:04+00', 2, '"comment"=>"mod way", "highway"=>"secondary"');
        INSERT INTO nds VALUES (10050, 2, 0, 10000);
        INSERT INTO nds VALUES (10050, 2, 1, 10001);

        INSERT INTO ways VALUES (10050, false, true, false, 10094, 'u1', 10080, '2018-11-15 17:20:04+00', 3, '"comment"=>"mod way", "highway"=>"secondary"');
        INSERT INTO nds VALUES (10050, 3, 0, 10000);
        INSERT INTO nds VALUES (10050, 3, 1, 10001);

        INSERT INTO changesets VALUES (10090, '2018-11-15 17:20:04+00', '2018-11-15 17:20:04+00', 1, false, 'u1', 10080, '', ST_MakeEnvelope(0, 0, 0, 0, 4326));
        INSERT INTO changesets VALUES (10091, '2018-11-15 17:20:04+00', '2018-11-15 17:20:04+00', 1, false, 'u1', 10080, '', ST_MakeEnvelope(0, 0, 0, 0, 4326));
        INSERT INTO changesets VALUES (10094, '2018-11-15 17:20:04+00', '2018-11-15 17:20:04+00', 1, false, 'u1', 10080, '', ST_MakeEnvelope(0, 0, 0, 0, 4326));
        INSERT INTO changesets VALUES (10096, '2018-11-15 17:20:04+00', '2018-11-15 17:20:04+00', 1, false, 'u1', 10080, '', ST_MakeEnvelope(0, 0, 0, 0, 4326));
        ''',
                 multi=True)

    changes = collect_changeset(conn, 10090)
    assert changes['changes']['ways'] == [{
        'added': True,
        'deleted': False,
        'id': 10050L,
        'key': '10050-1',
        'modified': False,
        'prevKey': None,
        'version': 1
    }]
예제 #6
0
def test_missing_nodes_of_way(conn):
    conn.execute('''
        INSERT INTO nodes VALUES (10000, true, false, false, 10090, ST_SetSRID(ST_MakePoint(0, 0.0), 4326), 'u1', 10080, '2018-11-15 17:20:04+00', 1, '');

        INSERT INTO ways VALUES (10050, true, false, false, 10090, 'u1', 10080, '2018-11-15 17:20:04+00', 1, '"comment"=>"new way", "highway"=>"secondary"');
        INSERT INTO nds VALUES (10050, 1, 0, 10000);
        INSERT INTO nds VALUES (10050, 1, 1, 10001);

        INSERT INTO changesets VALUES (10090, '2018-11-15 17:20:04+00', '2018-11-15 17:20:04+00', 1, false, 'u1', 10080, '', ST_MakeEnvelope(0, 0, 0, 0, 4326));
        ''',
                 multi=True)

    changes = collect_changeset(conn, 10090)
    assert changes['changes']['ways'] == [{
        'added': True,
        'deleted': False,
        'id': 10050L,
        'key': '10050-1',
        'modified': False,
        'prevKey': None,
        'version': 1
    }]
예제 #7
0
    changes = collect_changeset(conn, 10090)
    assert changes['changes']['ways'] == [{
        'added': True,
        'deleted': False,
        'id': 10050L,
        'key': '10050-1',
        'modified': False,
        'prevKey': None,
        'version': 1
    }]
    assert changes['elements']['ways']['10050-1']['nds'] == [
        '10000-1', '10001-1'
    ]

    changes = collect_changeset(conn, 10091)
    assert changes['changes']['ways'] == [{
        'added': False,
        'deleted': False,
        'id': 10050L,
        'key': '10050-2',
        'modified': True,
        'prevKey': '10050-1',
        'version': 2
    }]
    assert changes['elements']['ways']['10050-1']['nds'] == [
        '10000-1', '10001-1'
    ]
    assert changes['elements']['ways']['10050-2']['nds'] == [
        '10000-1', '10001-1'
    ]  # nodes were not changed
예제 #8
0
def changeset_changes(changeset_id):
    result = collect_changeset(current_app.changeset_connection, changeset_id)
    return jsonify(result)