tests.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from unittest import skipUnless
  4. from django.contrib.gis.geos import HAS_GEOS
  5. from django.contrib.gis.maps.google.overlays import GEvent, GOverlayBase
  6. from django.test import TestCase
  7. from django.test.utils import modify_settings, override_settings
  8. from django.utils.encoding import force_text
  9. GOOGLE_MAPS_API_KEY = 'XXXX'
  10. @skipUnless(HAS_GEOS, 'Geos is required.')
  11. @modify_settings(
  12. INSTALLED_APPS={'append': 'django.contrib.gis'},
  13. )
  14. class GoogleMapsTest(TestCase):
  15. @override_settings(GOOGLE_MAPS_API_KEY=GOOGLE_MAPS_API_KEY)
  16. def test_google_map_scripts(self):
  17. """
  18. Testing GoogleMap.scripts() output. See #20773.
  19. """
  20. from django.contrib.gis.maps.google.gmap import GoogleMap
  21. google_map = GoogleMap()
  22. scripts = google_map.scripts
  23. self.assertIn(GOOGLE_MAPS_API_KEY, scripts)
  24. self.assertIn("new GMap2", scripts)
  25. @override_settings(GOOGLE_MAPS_API_KEY=GOOGLE_MAPS_API_KEY)
  26. def test_unicode_in_google_maps(self):
  27. """
  28. Test that GoogleMap doesn't crash with non-ASCII content.
  29. """
  30. from django.contrib.gis.geos import Point
  31. from django.contrib.gis.maps.google.gmap import GoogleMap, GMarker
  32. center = Point(6.146805, 46.227574)
  33. marker = GMarker(center,
  34. title='En français !')
  35. google_map = GoogleMap(center=center, zoom=18, markers=[marker])
  36. self.assertIn("En français", google_map.scripts)
  37. def test_gevent_html_safe(self):
  38. event = GEvent('click', 'function() {location.href = "http://www.google.com"}')
  39. self.assertTrue(hasattr(GEvent, '__html__'))
  40. self.assertEqual(force_text(event), event.__html__())
  41. def test_goverlay_html_safe(self):
  42. overlay = GOverlayBase()
  43. overlay.js_params = '"foo", "bar"'
  44. self.assertTrue(hasattr(GOverlayBase, '__html__'))
  45. self.assertEqual(force_text(overlay), overlay.__html__())