Exemple #1
0
    def test_response_xml(self):
        url, t = new_server_thread(HandleResponseXML)

        api = overpy.Overpass()
        api.url = url
        result = api.query("[out:xml];node(50.745,7.17,50.75,7.18);out;")
        t.join()
        assert len(result.nodes) > 0
    def test_overpass_gateway_timeout(self):
        url, server = new_server_thread(HandleOverpassGatewayTimeout)

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassGatewayTimeout):
            api.query(("way(1);" "out body;"))
        stop_server_thread(server)
    def test_overpass_too_many_requests(self):
        url, server = new_server_thread(HandleOverpassTooManyRequests)

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassTooManyRequests):
            api.query(("way(1);" "out body;"))
        stop_server_thread(server)
Exemple #4
0
    def test_chunk_size(self):
        url, t = new_server_thread(HandleResponseJSON)

        api = overpy.Overpass(read_chunk_size=128)
        api.url = url
        result = api.query("[out:json];node(50.745,7.17,50.75,7.18);out;")
        t.join()
        assert len(result.nodes) > 0
Exemple #5
0
    def test_response_unknown(self):
        url, t = new_server_thread(HandleResponseUnknown)

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassUnknownContentType):
            api.query("[out:xml];node(50.745,7.17,50.75,7.18);out;")
        t.join()
    def test_response_json(self):
        url, server = new_server_thread(HandleResponseJSON)

        api = overpy.Overpass()
        api.url = url
        result = api.query("[out:json];node(50.745,7.17,50.75,7.18);out;")
        stop_server_thread(server)
        assert len(result.nodes) > 0
    def test_overpass_unknown_status_code(self):
        url, server = new_server_thread(HandleOverpassUnknownHTTPStatusCode)

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassUnknownHTTPStatusCode):
            api.query(("way(1);" "out body;"))
        stop_server_thread(server)
    def test_overpass_syntax_error(self):
        url, server = new_server_thread(HandleOverpassBadRequest)

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassBadRequest):
            # Missing ; after way(1)
            api.query(("way(1)" "out body;"))
        stop_server_thread(server)
    def test_chunk_size(self):
        url, t = new_server_thread(HandleResponseJSON)
        t.start()

        api = overpy.Overpass(read_chunk_size=128)
        api.url = url
        result = api.query("[out:json];node(50.745,7.17,50.75,7.18);out;")
        t.join()
        assert len(result.nodes) > 0
    def test_response_xml(self):
        url, t = new_server_thread(HandleResponseXML)
        t.start()

        api = overpy.Overpass()
        api.url = url
        result = api.query("[out:xml];node(50.745,7.17,50.75,7.18);out;")
        t.join()
        assert len(result.nodes) > 0
    def test_response_unknown(self):
        url, t = new_server_thread(HandleResponseUnknown)
        t.start()

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassUnknownContentType):
            api.query("[out:xml];node(50.745,7.17,50.75,7.18);out;")
        t.join()
    def test_retry(self):
        url, server = new_server_thread(HandleRetry)

        api = overpy.Overpass()
        # HandleRetry.default_handler_cls should contain at least 2 classes to process
        api.max_retry_count = len(HandleRetry.default_handler_func) - 1
        api.url = url
        with pytest.raises(overpy.exception.MaxRetriesReached):
            api.query(("way(1);" "out body;"))
        stop_server_thread(server)
    def test_missing_unresolvable(self):
        url, server = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_node(123, resolve_missing=True)
        stop_server_thread(server)
    def test_missing_unresolvable(self):
        url, t = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_node(123, resolve_missing=True)
        t.join()
    def test_overpass_unknown_status_code(self):
        url, t = new_server_thread(HandleOverpassUnknownHTTPStatusCode)
        t.start()

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassUnknownHTTPStatusCode):
            api.query((
                "way(1);"
                "out body;"
            ))
        t.join()
    def test_overpass_gateway_timeout(self):
        url, t = new_server_thread(HandleOverpassGatewayTimeout)
        t.start()

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassGatewayTimeout):
            api.query((
                "way(1);"
                "out body;"
            ))
        t.join()
    def test_overpass_too_many_requests(self):
        url, t = new_server_thread(HandleOverpassTooManyRequests)
        t.start()

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassTooManyRequests):
            api.query((
                "way(1);"
                "out body;"
            ))
        t.join()
    def test_overpass_syntax_error(self):
        url, t = new_server_thread(HandleOverpassBadRequest)
        t.start()

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassBadRequest):
            # Missing ; after way(1)
            api.query((
                "way(1)"
                "out body;"
            ))
        t.join()
    def test_overpass_syntax_error_encoding_error(self):
        with pytest.raises(UnicodeDecodeError):
            # File should be encoded with iso8859-15 and will raise an exception
            tmp = read_file("response/bad-request-encoding.html", "rb")
            tmp.decode("utf-8")

        url, server = new_server_thread(HandleOverpassBadRequestEncoding)

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassBadRequest):
            # Missing ; after way(1)
            api.query(("way(1)" "out body;"))
        stop_server_thread(server)
    def test_missing_resolvable(self):
        url, server = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Relation must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_relation(2046898)

        # Relation must be available
        relation = result1.get_relation(2046898, resolve_missing=True)

        assert isinstance(relation, overpy.Relation)
        assert relation.id == 2046898

        stop_server_thread(server)
    def test_missing_resolvable(self):
        url, server = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Node must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_area(3605945176)

        # Node must be available
        area = result1.get_area(3605945176, resolve_missing=True)

        assert isinstance(area, overpy.Area)
        assert area.id == 3605945176

        stop_server_thread(server)
    def test_missing_resolvable(self):
        url, server = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Way must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_way(317146078)

        # Way must be available
        way = result1.get_way(317146078, resolve_missing=True)

        assert isinstance(way, overpy.Way)
        assert way.id == 317146078

        stop_server_thread(server)
    def test_missing_resolvable(self):
        url, t = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Node must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_node(3233854235)

        # Node must be available
        node = result1.get_node(3233854235, resolve_missing=True)

        assert isinstance(node, overpy.Node)
        assert node.id == 3233854235

        t.join()
    def test_missing_resolvable(self):
        url, t = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Node must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_area(3605945176)

        # Node must be available
        area = result1.get_area(3605945176, resolve_missing=True)

        assert isinstance(area, overpy.Area)
        assert area.id == 3605945176

        t.join()
    def test_missing_resolvable(self):
        url, t = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Way must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_way(317146078)

        # Way must be available
        way = result1.get_way(317146078, resolve_missing=True)

        assert isinstance(way, overpy.Way)
        assert way.id == 317146078

        t.join()
    def test_missing_resolvable(self):
        url, t = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Relation must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_relation(2046898)

        # Relation must be available
        relation = result1.get_relation(2046898, resolve_missing=True)

        assert isinstance(relation, overpy.Relation)
        assert relation.id == 2046898

        t.join()
    def test_missing_resolvable(self):
        url, server = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Node must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_node(3233854235)

        # Node must be available
        node = result1.get_node(3233854235, resolve_missing=True)

        assert isinstance(node, overpy.Node)
        assert node.id == 3233854235

        stop_server_thread(server)
    def test_overpass_syntax_error_encoding_error(self):
        with pytest.raises(UnicodeDecodeError):
            # File should be encoded with iso8859-15 and will raise an exception
            tmp = read_file("response/bad-request-encoding.html", "rb")
            tmp.decode("utf-8")

        url, t = new_server_thread(HandleOverpassBadRequestEncoding)
        t.start()

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassBadRequest):
            # Missing ; after way(1)
            api.query((
                "way(1)"
                "out body;"
            ))
        t.join()
Exemple #29
0
    def test_missing_resolvable(self):
        url, server = new_server_thread(HandleResponseJSON03)

        api = overpy.Overpass()
        api.url = url
        result = api.parse_json(read_file("json/result-way-01.json"))

        assert len(result.nodes) == 0
        assert len(result.ways) == 1

        way = result.ways[0]
        assert isinstance(way, overpy.Way)

        with pytest.raises(overpy.exception.DataIncomplete):
            way.get_nodes()

        nodes = way.get_nodes(resolve_missing=True)

        assert len(nodes) == 2

        stop_server_thread(server)