1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed string length check in LayerMapping

This commit is contained in:
Claude Paroz 2014-09-18 18:54:38 +02:00
parent 7fc13178d6
commit 4dcfacb5b9
3 changed files with 12 additions and 4 deletions

View File

@ -31,6 +31,7 @@ class CountyFeat(NamedModel):
class City(NamedModel):
name_txt = models.TextField(default='')
name_short = models.CharField(max_length=5)
population = models.IntegerField()
density = models.DecimalField(max_digits=7, decimal_places=1)
dt = models.DateField()

View File

@ -15,7 +15,7 @@ from django.utils._os import upath
if HAS_GDAL:
from django.contrib.gis.utils.layermapping import (LayerMapping,
LayerMapError, InvalidDecimal, MissingForeignKey)
LayerMapError, InvalidDecimal, InvalidString, MissingForeignKey)
from django.contrib.gis.gdal import DataSource
from .models import (
@ -287,6 +287,13 @@ class LayerMapTest(TestCase):
source_srs=4326)
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):
"Tests that String content fits also in a TextField"
mapping = copy(city_mapping)