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