Fixed string length check in LayerMapping
This commit is contained in:
parent
7fc13178d6
commit
4dcfacb5b9
|
@ -31,6 +31,7 @@ class CountyFeat(NamedModel):
|
||||||
|
|
||||||
class City(NamedModel):
|
class City(NamedModel):
|
||||||
name_txt = models.TextField(default='')
|
name_txt = models.TextField(default='')
|
||||||
|
name_short = models.CharField(max_length=5)
|
||||||
population = models.IntegerField()
|
population = models.IntegerField()
|
||||||
density = models.DecimalField(max_digits=7, decimal_places=1)
|
density = models.DecimalField(max_digits=7, decimal_places=1)
|
||||||
dt = models.DateField()
|
dt = models.DateField()
|
||||||
|
|
|
@ -15,7 +15,7 @@ from django.utils._os import upath
|
||||||
|
|
||||||
if HAS_GDAL:
|
if HAS_GDAL:
|
||||||
from django.contrib.gis.utils.layermapping import (LayerMapping,
|
from django.contrib.gis.utils.layermapping import (LayerMapping,
|
||||||
LayerMapError, InvalidDecimal, MissingForeignKey)
|
LayerMapError, InvalidDecimal, InvalidString, MissingForeignKey)
|
||||||
from django.contrib.gis.gdal import DataSource
|
from django.contrib.gis.gdal import DataSource
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
|
@ -287,6 +287,13 @@ class LayerMapTest(TestCase):
|
||||||
source_srs=4326)
|
source_srs=4326)
|
||||||
lm.save(silent=True)
|
lm.save(silent=True)
|
||||||
|
|
||||||
|
def test_charfield_too_short(self):
|
||||||
|
mapping = copy(city_mapping)
|
||||||
|
mapping['name_short'] = 'Name'
|
||||||
|
lm = LayerMapping(City, city_shp, mapping)
|
||||||
|
with self.assertRaises(InvalidString):
|
||||||
|
lm.save(silent=True, strict=True)
|
||||||
|
|
||||||
def test_textfield(self):
|
def test_textfield(self):
|
||||||
"Tests that String content fits also in a TextField"
|
"Tests that String content fits also in a TextField"
|
||||||
mapping = copy(city_mapping)
|
mapping = copy(city_mapping)
|
||||||
|
|
Loading…
Reference in New Issue