From 15b7bcf24d16cb023f6bf7024bc220377f97cbfa Mon Sep 17 00:00:00 2001
From: Daniel Barreto <daniel@gia.usb.ve>
Date: Fri, 11 Feb 2011 15:11:25 -0430
Subject: [PATCH] Tests for GeometryField.to_python method
---
django/contrib/gis/tests/test_geoforms.py | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/django/contrib/gis/tests/test_geoforms.py b/django/contrib/gis/tests/test_geoforms.py
index 4d55bf5..5b4084d 100644
a
|
b
|
class GeometryFieldTest(unittest.TestCase):
|
42 | 42 | fld = forms.GeometryField(required=False) |
43 | 43 | self.assertEqual(None, fld.clean(None)) |
44 | 44 | |
45 | | def test03_geom_type(self): |
| 45 | def test03_to_python(self): |
| 46 | """Testing to_python returns a correct GEOSGeometry object or |
| 47 | a ValidationError""" |
| 48 | fld = forms.GeometryField() |
| 49 | # to_python returns the same GEOSGeometry for a WKT |
| 50 | for wkt in ('POINT(5 23)', 'MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'LINESTRING(0 0, 1 1)'): |
| 51 | self.assertEqual(GEOSGeometry(wkt), fld.to_python(wkt)) |
| 52 | # but raises a ValidationError for any other string |
| 53 | for wkt in ('POINT(5)', 'MULTI POLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'BLAH(0 0, 1 1)'): |
| 54 | self.assertRaises(forms.ValidationError, fld.to_python, wkt) |
| 55 | |
| 56 | def test04_geom_type(self): |
46 | 57 | "Testing GeometryField's handling of different geometry types." |
47 | 58 | # By default, all geometry types are allowed. |
48 | 59 | fld = forms.GeometryField() |
… |
… |
class GeometryFieldTest(unittest.TestCase):
|
51 | 62 | |
52 | 63 | pnt_fld = forms.GeometryField(geom_type='POINT') |
53 | 64 | self.assertEqual(GEOSGeometry('POINT(5 23)'), pnt_fld.clean('POINT(5 23)')) |
| 65 | # a WKT for any other geom_type will be properly transformed by `to_python` |
| 66 | self.assertEqual(GEOSGeometry('LINESTRING(0 0, 1 1)'), pnt_fld.to_python('LINESTRING(0 0, 1 1)')) |
| 67 | # but rejected by `clean` |
54 | 68 | self.assertRaises(forms.ValidationError, pnt_fld.clean, 'LINESTRING(0 0, 1 1)') |
55 | 69 | |
56 | 70 | def suite(): |