def test_kml(self):
        # Only PostGIS and Spatialite (>=2.4.0-RC4) support KML serialization
        if not (postgis or (spatialite and connection.ops.kml)):
            self.assertRaises(NotImplementedError, State.objects.all().kml, field_name='poly')
            return

        # Should throw a TypeError when trying to obtain KML from a
        #  non-geometry field.
        qs = City.objects.all()
        self.assertRaises(TypeError, qs.kml, 'name')

        # The reference KML depends on the version of PostGIS used
        # (the output stopped including altitude in 1.3.3).
        if connection.ops.spatial_version >= (1, 3, 3):
            ref_kml =  '<Point><coordinates>-104.609252,38.255001</coordinates></Point>'
        else:
            ref_kml = '<Point><coordinates>-104.609252,38.255001,0</coordinates></Point>'

        # Ensuring the KML is as expected.
        ptown1 = City.objects.kml(field_name='point', precision=9).get(name='Pueblo')
        ptown2 = City.objects.kml(precision=9).get(name='Pueblo')
        for ptown in [ptown1, ptown2]:
            self.assertEqual(ref_kml, ptown.kml)

    # Only PostGIS has support for the MakeLine aggregate.
Testing KML output from the database using GeoQuerySet.kml().
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/django/contrib/gis/tests/geoapp/tests.py/GeoQuerySetTest.test_kml