Exemplo n.º 1
0
def test_geo_field_dict_type():
    field = GeoPointField(field_name='test')
    value = {
        "lat": 40.722,
        "lon": -73.989
    }
    assert field.to_dict(value) == value
Exemplo n.º 2
0
def test_geo_field_dict_invalid_type():
    field = GeoPointField(field_name='test')
    value = [-73.989, 40.722]
    with pytest.raises(FieldTypeMismatch) as ex:
        field.to_dict(value)
    assert str(ex.value) == "`test` expected `" + str(
        dict) + "`, actual `" + str(list) + "`"  # noqa
Exemplo n.º 3
0
def test_geo_field_dict_lat_missing():
    field = GeoPointField(field_name='test')
    value = {
        "lon": -40.722
    }
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == "test: lat requires a float"
Exemplo n.º 4
0
def test_geo_field_array_type_multi_invalid_type():
    field = GeoPointField(field_name='test', mode='array', multi=True)
    value = [[40.715, -74.011], [40.715], list]
    with pytest.raises(FieldTypeMismatch) as ex:
        field.to_dict(value)
    assert str(
        ex.value
    ) == "`test` expected `<type 'float'>`, actual `<type 'type'>`"  # noqa
Exemplo n.º 5
0
def test_geo_field_array_invalid_type():
    field = GeoPointField(field_name='test', mode='array')
    value = [40.715, list]
    with pytest.raises(FieldTypeMismatch) as ex:
        field.to_dict(value)
    msg = "`test` expected `<type 'float'>`, actual `<type 'type'>`"
    if sys.version_info > (3, ):
        msg = "`test` expected `<class 'float'>`, actual `<class 'type'>`"
    assert str(ex.value) == msg
Exemplo n.º 6
0
def test_geo_field_dict_invalid_lon_type():
    field = GeoPointField(field_name='test')
    value = {
        "lat": 40.722,
        "lon": list
    }
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == "test: lon requires a float"
Exemplo n.º 7
0
def test_geo_field_string_invalid_type():
    field = GeoPointField(field_name='test', mode='string')
    value = u"asdf, error"
    with pytest.raises(ValueError) as ex:
        field.to_dict(value)
    msg = 'could not convert string to float: asdf'
    if sys.version_info > (3, ):
        msg = "could not convert string to float: 'asdf'"
    assert str(ex.value) == msg
Exemplo n.º 8
0
def test_geo_field_dict_multi():
    field = GeoPointField(field_name='test', multi=True)
    value = [{
        "lat": 40.722,
        "lon": -73.989
    }, {
        "lat": 40.722,
        "lon": -73.989
    }, {
        "lat": 40.722,
        "lon": -73.989
    }]
    assert field.to_dict(value) == value
Exemplo n.º 9
0
def test_geo_field_dict_multi_invalid():
    field = GeoPointField(field_name='test', multi=True)
    value = [{
        "lat": 40.722,
        "lon": -73.989
    }, {
        "lat": 40.722,
        "lon": -73.989
    }, {
        "lat": 40.722
    }]
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == "test: lon requires a float"
Exemplo n.º 10
0
def test_geo_field_dict_multi():
    field = GeoPointField(field_name='test', multi=True)
    value = [
        {
           "lat": 40.722,
           "lon": -73.989
        },
        {
           "lat": 40.722,
           "lon": -73.989
        },
        {
           "lat": 40.722,
           "lon": -73.989
        }
    ]
    assert field.to_dict(value) == value
Exemplo n.º 11
0
def test_geo_field_dict_multi_invalid():
    field = GeoPointField(field_name='test', multi=True)
    value = [
        {
           "lat": 40.722,
           "lon": -73.989
        },
        {
           "lat": 40.722,
           "lon": -73.989
        },
        {
           "lat": 40.722
        }
    ]
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == "test: lon requires a float"
Exemplo n.º 12
0
def test_geo_field_array_type_multi():
    field = GeoPointField(field_name='test', mode='array', multi=True)
    value = [[40.715, -74.011], [40.715, -74.011], [40.715, -74.011]]
    assert field.to_dict(value) == value
Exemplo n.º 13
0
def test_geo_field_string_type_multi():
    field = GeoPointField(field_name='test', mode='string', multi=True)
    value = [u"40.715, -74.011", u"40.715, -74.011", u"40.715, -74.011"]
    assert field.to_dict(value) == value
Exemplo n.º 14
0
def test_geo_field_array_value_missing():
    field = GeoPointField(field_name='test', mode='array')
    value = [40.715]
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == '2 elements [lon, lat] required in test'
Exemplo n.º 15
0
def test_geo_field_array_type():
    field = GeoPointField(field_name='test', mode='array')
    value = [40.715, -74.011]
    assert field.to_dict(value) == value
Exemplo n.º 16
0
def test_geo_field_string_invalid_type():
    field = GeoPointField(field_name='test', mode='string')
    value = u"test, error"
    with pytest.raises(ValueError) as ex:
        field.to_dict(value)
    assert str(ex.value) == 'could not convert string to float: test'
Exemplo n.º 17
0
def test_geo_field_string_type_multi():
    field = GeoPointField(field_name='test', mode='string', multi=True)
    value = [u"40.715, -74.011", u"40.715, -74.011", u"40.715, -74.011"]
    assert field.to_dict(value) == value
Exemplo n.º 18
0
def test_geo_field_array_type_multi_invalid():
    field = GeoPointField(field_name='test', mode='array', multi=True)
    value = [[40.715, -74.011], [40.715], [40.715, -74.011]]
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == '2 elements [lon, lat] required in test'
Exemplo n.º 19
0
def test_geo_field_dict_invalid_lon_type():
    field = GeoPointField(field_name='test')
    value = {"lat": 40.722, "lon": list}
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == "test: lon requires a float"
Exemplo n.º 20
0
def test_geo_field_dict_lat_missing():
    field = GeoPointField(field_name='test')
    value = {"lon": -40.722}
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == "test: lat requires a float"
Exemplo n.º 21
0
def test_geo_field_dict_type():
    field = GeoPointField(field_name='test')
    value = {"lat": 40.722, "lon": -73.989}
    assert field.to_dict(value) == value
Exemplo n.º 22
0
def test_geo_field_array_type_multi_invalid():
    field = GeoPointField(field_name='test', mode='array', multi=True)
    value = [[40.715, -74.011], [40.715], [40.715, -74.011]]
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == '2 elements [lon, lat] required in test'
Exemplo n.º 23
0
def test_geo_field_string_type_multi_invalid():
    field = GeoPointField(field_name='test', mode='string', multi=True)
    value = [u"40.715, -74.011", u"40.715, -74.011", u"40.715"]
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == '2 elements "lat,lon" required in test'
Exemplo n.º 24
0
def test_geo_field_array_type_multi():
    field = GeoPointField(field_name='test', mode='array', multi=True)
    value = [[40.715, -74.011], [40.715, -74.011], [40.715, -74.011]]
    assert field.to_dict(value) == value
Exemplo n.º 25
0
def test_geo_field_string_type_multi_invalid():
    field = GeoPointField(field_name='test', mode='string', multi=True)
    value = [u"40.715, -74.011", u"40.715, -74.011", u"40.715"]
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == '2 elements "lat,lon" required in test'
Exemplo n.º 26
0
def test_geo_field_array_value_missing():
    field = GeoPointField(field_name='test', mode='array')
    value = [40.715]
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == '2 elements [lon, lat] required in test'
Exemplo n.º 27
0
def test_geo_field_array_type_multi_invalid_type():
    field = GeoPointField(field_name='test', mode='array', multi=True)
    value = [[40.715, -74.011], [40.715], list]
    with pytest.raises(FieldTypeMismatch) as ex:
        field.to_dict(value)
    assert str(ex.value) == "`test` expected `<type 'float'>`, actual `<type 'type'>`"  # noqa
Exemplo n.º 28
0
def test_geo_field_string_invalid_type():
    field = GeoPointField(field_name='test', mode='string')
    value = u"test, error"
    with pytest.raises(ValueError) as ex:
        field.to_dict(value)
    assert str(ex.value) == 'could not convert string to float: test'
Exemplo n.º 29
0
def test_geo_field_string_type():
    field = GeoPointField(field_name='test', mode='string')
    value = u"40.715, -74.011"
    assert field.to_dict(value) == value
Exemplo n.º 30
0
def test_geo_field_array_type():
    field = GeoPointField(field_name='test', mode='array')
    value = [40.715, -74.011]
    assert field.to_dict(value) == value
Exemplo n.º 31
0
def test_geo_field_dict_invalid_type():
    field = GeoPointField(field_name='test')
    value = [-73.989, 40.722]
    with pytest.raises(FieldTypeMismatch) as ex:
        field.to_dict(value)
    assert str(ex.value) == "`test` expected `<type 'dict'>`, actual `<type 'list'>`"  # noqa
Exemplo n.º 32
0
def test_geo_field_string_type():
    field = GeoPointField(field_name='test', mode='string')
    value = u"40.715, -74.011"
    assert field.to_dict(value) == value
Exemplo n.º 33
0
def test_geo_field_string_value_missing():
    field = GeoPointField(field_name='test', mode='string')
    value = u"40.715"
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == '2 elements "lat,lon" required in test'
Exemplo n.º 34
0
def test_geo_field_string_value_missing():
    field = GeoPointField(field_name='test', mode='string')
    value = u"40.715"
    with pytest.raises(ValidationError) as ex:
        field.to_dict(value)
    assert str(ex.value) == '2 elements "lat,lon" required in test'