<s> from __future__ import absolute_import <EOL> from io import BytesIO <EOL> from xml . dom import minidom <EOL> import zipfile <EOL> from django . conf import settings <EOL> from django . contrib . gis . geos import HAS_GEOS <EOL> from django . contrib . gis . tests . utils import HAS_SPATIAL_DB <EOL> from django . contrib . sites . models import Site <EOL> from django . test import TestCase <EOL> from django . utils . unittest import skipUnless <EOL> if HAS_GEOS : <EOL> from . models import City , Country <EOL> @ skipUnless ( HAS_GEOS and HAS_SPATIAL_DB , "<STR_LIT>" ) <EOL> class GeoSitemapTest ( TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> Site ( id = settings . SITE_ID , domain = "<STR_LIT>" , name = "<STR_LIT>" ) . save ( ) <EOL> self . old_Site_meta_installed = Site . _meta . installed <EOL> Site . _meta . installed = True <EOL> def tearDown ( self ) : <EOL> Site . _meta . installed = self . old_Site_meta_installed <EOL> def assertChildNodes ( self , elem , expected ) : <EOL> "<STR_LIT>" <EOL> actual = set ( [ n . nodeName for n in elem . childNodes ] ) <EOL> expected = set ( expected ) <EOL> self . assertEqual ( actual , expected ) <EOL> def test_geositemap_index ( self ) : <EOL> "<STR_LIT>" <EOL> doc = minidom . parseString ( self . client . get ( '<STR_LIT>' ) . content ) <EOL> index = doc . firstChild <EOL> self . assertEqual ( index . getAttribute ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( index . getElementsByTagName ( '<STR_LIT>' ) ) ) <EOL> def test_geositemap_kml ( self ) : <EOL> "<STR_LIT>" <EOL> for kml_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> doc = minidom . parseString ( self . client . get ( '<STR_LIT>' % kml_type ) . content ) <EOL> urlset = doc . firstChild <EOL> self . assertEqual ( urlset . getAttribute ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( urlset . getAttribute ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> urls = urlset . getElementsByTagName ( '<STR_LIT:url>' ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( urls ) ) <EOL> for url in urls : <EOL> self . assertChildNodes ( url , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> geo_elem = url . getElementsByTagName ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> geo_format = geo_elem . getElementsByTagName ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( kml_type , geo_format . childNodes [ <NUM_LIT:0> ] . data ) <EOL> kml_url = url . getElementsByTagName ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . childNodes [ <NUM_LIT:0> ] . data . split ( '<STR_LIT>' ) [ <NUM_LIT:1> ] <EOL> if kml_type == '<STR_LIT>' : <EOL> kml_doc = minidom . parseString ( self . client . get ( kml_url ) . content ) <EOL> elif kml_type == '<STR_LIT>' : <EOL> buf = BytesIO ( self . client . get ( kml_url ) . content ) <EOL> zf = zipfile . ZipFile ( buf ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( zf . filelist ) ) <EOL> self . assertEqual ( '<STR_LIT>' , zf . filelist [ <NUM_LIT:0> ] . filename ) <EOL> kml_doc = minidom . parseString ( zf . read ( '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in kml_url : <EOL> model = City <EOL> elif '<STR_LIT>' in kml_url : <EOL> model = Country <EOL> self . assertEqual ( model . objects . count ( ) , len ( kml_doc . getElementsByTagName ( '<STR_LIT>' ) ) ) <EOL> def test_geositemap_georss ( self ) : <EOL> "<STR_LIT>" <EOL> from . feeds import feed_dict <EOL> doc = minidom . parseString ( self . client . get ( '<STR_LIT>' ) . content ) <EOL> urlset = doc . firstChild <EOL> self . assertEqual ( urlset . getAttribute ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( urlset . getAttribute ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> urls = urlset . getElementsByTagName ( '<STR_LIT:url>' ) <EOL> self . assertEqual ( len ( feed_dict ) , len ( urls ) ) <EOL> for url in urls : <EOL> self . assertChildNodes ( url , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> geo_elem = url . getElementsByTagName ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> geo_format = geo_elem . getElementsByTagName ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( '<STR_LIT>' , geo_format . childNodes [ <NUM_LIT:0> ] . data ) </s>
