Ejemplo n.º 1
0
def test_tile():
    # tuple

    add(method=GET,
        url=
        "https://api.mapbox.com/v4/mapbox.streets/0/0/0.png?access_token=pk.test",
        match_querystring=True,
        body="0.png",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.tile("mapbox.streets", *(0, 0, 0))

    assert response.status_code == 200

    # individual x, y, and z

    add(method=GET,
        url=
        "https://api.mapbox.com/v4/mapbox.streets/0/0/0.png?access_token=pk.test",
        match_querystring=True,
        body="0.png",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.tile("mapbox.streets", 0, 0, 0)

    assert response.status_code == 200
Ejemplo n.º 2
0
def test_object_properties():
    maps = Maps()

    assert maps.api_name
    assert maps.api_version
    assert maps.valid_file_formats
    assert maps.valid_feature_formats
    assert maps.valid_marker_names
    assert maps.base_uri
Ejemplo n.º 3
0
def test_marker():
    add(method=GET,
        url="https://api.mapbox.com/v4/marker/pin-s.png?access_token=pk.test",
        match_querystring=True,
        body="pin-s.png",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.marker(marker_name="pin-s")

    assert response.status_code == 200
Ejemplo n.º 4
0
def test_features():
    add(method=GET,
        url=
        "https://api.mapbox.com/v4/mapbox.streets/features.json?access_token=pk.test",
        match_querystring=True,
        body="{\"key\": \"value\"}",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.features("mapbox.streets", )

    assert response.status_code == 200
Ejemplo n.º 5
0
def test_features_with_different_format():
    add(method=GET,
        url=
        "https://api.mapbox.com/v4/mapbox.streets/features.kml?access_token=pk.test",
        match_querystring=True,
        body="<xml></xml>",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.features("mapbox.streets", feature_format="kml")

    assert response.status_code == 200
Ejemplo n.º 6
0
def test_metadata_with_secure():
    add(method=GET,
        url=
        "https://api.mapbox.com/v4/mapbox.streets.json?access_token=pk.test&secure",
        match_querystring=True,
        body="{\"key\": \"value\"}",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.metadata("mapbox.streets", secure=True)

    assert response.status_code == 200
Ejemplo n.º 7
0
def test_marker_with_label_and_retina():
    add(method=GET,
        url=
        "https://api.mapbox.com/v4/marker/[email protected]?access_token=pk.test",
        match_querystring=True,
        body="*****@*****.**",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.marker(marker_name="pin-s", label="label", retina=True)

    assert response.status_code == 200
Ejemplo n.º 8
0
def test_tile_with_retina():
    add(method=GET,
        url=
        "https://api.mapbox.com/v4/mapbox.streets/0/0/[email protected]?access_token=pk.test",
        match_querystring=True,
        body="*****@*****.**",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.tile("mapbox.streets", 0, 0, 0, retina=True)

    assert response.status_code == 200
Ejemplo n.º 9
0
def test_tile_with_different_file_format():
    add(method=GET,
        url=
        "https://api.mapbox.com/v4/mapbox.streets/0/0/0.grid.json?access_token=pk.test",
        match_querystring=True,
        body="0.grid.json",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.tile("mapbox.streets", 0, 0, 0, file_format="grid.json")

    assert response.status_code == 200
Ejemplo n.º 10
0
def test_validate_timestamp():
    maps = Maps()

    # invalid value

    with raises(InvalidPeriodError) as exception:
        timestamp = "invalid"
        result = maps._validate_timestamp(timestamp)

    # valid value

    timestamp = "2018-01-01T00:00:00.000Z"
    result = maps._validate_timestamp(timestamp)
    assert result == timestamp
Ejemplo n.º 11
0
def test_validate_retina():
    maps = Maps()

    # True

    retina = True
    result = maps._validate_retina(retina)
    assert result == "@2x"

    # False

    retina = False
    result = maps._validate_retina(retina)
    assert result == ""
Ejemplo n.º 12
0
def test_validate_feature_format():
    maps = Maps()

    # invalid value

    with raises(InvalidFeatureFormatError) as exception:
        feature_format = "invalid"
        result = maps._validate_feature_format(feature_format)

    # valid values

    feature_formats = ["json", "kml"]

    for feature_format in feature_formats:
        result = maps._validate_feature_format(feature_format)
        assert result == feature_format
Ejemplo n.º 13
0
def test_validate_marker_name():
    maps = Maps()

    # invalid value

    with raises(InvalidMarkerNameError) as exception:
        marker_name = "invalid"
        result = maps._validate_marker_name(marker_name)

    # valid values

    marker_names = ["pin-s", "pin-l"]

    for marker_name in marker_names:
        result = maps._validate_marker_name(marker_name)
        assert result == marker_name
Ejemplo n.º 14
0
def test_tile_error():
    maps = Maps(access_token="pk.test")

    # x = None

    with raises(ValidationError) as exception:
        response = maps.tile("mapbox.streets", None, 0, 0)

    # y = None

    with raises(ValidationError) as exception:
        response = maps.tile("mapbox.streets", 0, None, 0)

    # z = None

    with raises(ValidationError) as exception:
        response = maps.tile("mapbox.streets", 0, 0, None)
Ejemplo n.º 15
0
def test_tile_with_style():
    add(method=GET,
        url=
        "https://api.mapbox.com/v4/mapbox.streets/0/0/0.png?access_token=pk.test&style=mapbox://styles/mapbox/streets-v10@2018-01-01T00:00:00.000Z",
        match_querystring=True,
        body="0.png",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.tile("mapbox.streets",
                         0,
                         0,
                         0,
                         style_id="mapbox://styles/mapbox/streets-v10",
                         timestamp="2018-01-01T00:00:00.000Z")

    assert response.status_code == 200
Ejemplo n.º 16
0
def test_validate_label():
    maps = Maps()

    # invalid value

    with raises(InvalidLabelError) as exception:
        label = "00"
        result = maps._validate_label(label)

    # invalid value

    with raises(InvalidLabelError) as exception:
        label = "invalid_"
        result = maps._validate_label(label)

    # valid value

    label = "a"
    result = maps._validate_label(label)
    assert result == label

    # valid value

    label = "0"
    result = maps._validate_label(label)
    assert result == label

    # valid value

    label = "99"
    result = maps._validate_label(label)
    assert result == label

    # valid value

    label = "valid"
    result = maps._validate_label(label)
    assert result == label

    # valid value

    label = "valid "
    result = maps._validate_label(label)
    assert result == label
Ejemplo n.º 17
0
def test_validate_file_format():
    maps = Maps()

    # invalid value

    with raises(InvalidFileFormatError) as exception:
        file_format = "invalid"
        result = maps._validate_file_format(file_format)

    # valid values

    file_formats = [
        "grid.json", "mvt", "png", "png32", "png64", "png128", "png256",
        "jpg70", "jpg80", "jpg90"
    ]

    for file_format in file_formats:
        result = maps._validate_file_format(file_format)
        assert result == file_format
Ejemplo n.º 18
0
def test_validate_color():
    maps = Maps()

    # invalid value

    with raises(InvalidColorError) as exception:
        color = "invalid"
        result = maps._validate_color(color)

    # valid value

    color = "00f"
    result = maps._validate_color(color)
    assert result == color

    # valid value

    color = "0000ff"
    result = maps._validate_color(color)
    assert result == color
Ejemplo n.º 19
0
def test_validate_z():
    maps = Maps()

    # invalid value

    with raises(InvalidZoomError) as exception:
        z = -1
        result = maps._validate_z(z)

    # invalid value

    with raises(InvalidZoomError) as exception:
        z = 21
        result = maps._validate_z(z)

    # valid value

    z = 10
    result = maps._validate_z(z)
    assert result == z
Ejemplo n.º 20
0
def test_tile_with_style_and_retina_and_different_file_format():
    add(method=GET,
        url=
        "https://api.mapbox.com/v4/mapbox.streets/0/0/[email protected]?access_token=pk.test&style=mapbox://styles/mapbox/streets-v10@2018-01-01T00:00:00.000Z",
        match_querystring=True,
        body="*****@*****.**",
        status=200)

    maps = Maps(access_token="pk.test")

    response = maps.tile("mapbox.streets",
                         0,
                         0,
                         0,
                         retina=True,
                         file_format="grid.json",
                         style_id="mapbox://styles/mapbox/streets-v10",
                         timestamp="2018-01-01T00:00:00.000Z")

    assert response.status_code == 200
Ejemplo n.º 21
0
def test_validate_y():
    maps = Maps()

    # invalid value

    with raises(InvalidRowError) as exception:
        y = -1
        z = 10
        result = maps._validate_y(y, z)

    # invalid value

    with raises(InvalidRowError) as exception:
        y = 1024
        z = 10
        result = maps._validate_y(y, z)

    # valid value

    y = 512
    z = 10
    result = maps._validate_y(y, z)
    assert result == y
Ejemplo n.º 22
0
def test_validate_x():
    maps = Maps()

    # invalid value

    with raises(InvalidColumnError) as exception:
        x = -1
        z = 10
        result = maps._validate_x(x, z)

    # invalid value

    with raises(InvalidColumnError) as exception:
        x = 1024
        z = 10
        result = maps._validate_x(x, z)

    # valid value

    x = 512
    z = 10
    result = maps._validate_x(x, z)
    assert result == x
Ejemplo n.º 23
0
def test_marker_error():
    maps = Maps(access_token="pk.test")

    with raises(ValidationError) as exception:
        response = maps.marker()