PageRenderTime 51ms CodeModel.GetById 41ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/django/contrib/gis/tests/geoapp/test_regress.py

https://code.google.com/p/mango-py/
Python | 45 lines | 39 code | 6 blank | 0 comment | 2 complexity | f6f0b31912ab13745ddf3dced21ca195 MD5 | raw file
 1from datetime import datetime
 2from django.contrib.gis.tests.utils import no_mysql, no_oracle, no_postgis, no_spatialite
 3from django.contrib.gis.shortcuts import render_to_kmz
 4from django.test import TestCase
 5from models import City, PennsylvaniaCity
 6
 7class GeoRegressionTests(TestCase):
 8
 9    def test01_update(self):
10        "Testing GeoQuerySet.update(), see #10411."
11        pnt = City.objects.get(name='Pueblo').point
12        bak = pnt.clone()
13        pnt.y += 0.005
14        pnt.x += 0.005
15
16        City.objects.filter(name='Pueblo').update(point=pnt)
17        self.assertEqual(pnt, City.objects.get(name='Pueblo').point)
18        City.objects.filter(name='Pueblo').update(point=bak)
19        self.assertEqual(bak, City.objects.get(name='Pueblo').point)
20
21    def test02_kmz(self):
22        "Testing `render_to_kmz` with non-ASCII data, see #11624."
23        name = '\xc3\x85land Islands'.decode('iso-8859-1')
24        places = [{'name' : name,
25                  'description' : name,
26                  'kml' : '<Point><coordinates>5.0,23.0</coordinates></Point>'
27                  }]
28        kmz = render_to_kmz('gis/kml/placemarks.kml', {'places' : places})
29
30    @no_spatialite
31    @no_mysql
32    def test03_extent(self):
33        "Testing `extent` on a table with a single point, see #11827."
34        pnt = City.objects.get(name='Pueblo').point
35        ref_ext = (pnt.x, pnt.y, pnt.x, pnt.y)
36        extent = City.objects.filter(name='Pueblo').extent()
37        for ref_val, val in zip(ref_ext, extent):
38            self.assertAlmostEqual(ref_val, val, 4)
39
40    def test04_unicode_date(self):
41        "Testing dates are converted properly, even on SpatiaLite, see #16408."
42        founded = datetime(1857, 5, 23)
43        mansfield = PennsylvaniaCity.objects.create(name='Mansfield', county='Tioga', point='POINT(-77.071445 41.823881)',
44                                                    founded=founded)
45        self.assertEqual(founded, PennsylvaniaCity.objects.dates('founded', 'day')[0])