'Testing the `Union` aggregate on related geographic models.'

@skipUnlessDBFeature('supports_union_aggr')
def test_related_union_aggregate(self):

    aggs = City.objects.aggregate(Union('location__point'))
    p1 = Point((-104.528056), 33.387222)
    p2 = Point((-97.516111), 33.058333)
    p3 = Point((-79.460734), 40.18476)
    p4 = Point((-96.801611), 32.782057)
    p5 = Point((-95.363151), 29.763374)
    ref_u1 = MultiPoint(p1, p2, p4, p5, p3, srid=4326)
    ref_u2 = MultiPoint(p2, p3, srid=4326)
    u1 = City.objects.aggregate(Union('location__point'))['location__point__union']
    u2 = City.objects.exclude(name__in=('Roswell', 'Houston', 'Dallas', 'Fort    Worth')).aggregate(Union('location__point'))['location__point__union']
    u3 = aggs['location__point__union']
    self.assertEqual(type(u1), MultiPoint)
    self.assertEqual(type(u3), MultiPoint)
    self.assertEqual({p.ewkt for p in ref_u1}, {p.ewkt for p in u1})
    self.assertEqual({p.ewkt for p in ref_u2}, {p.ewkt for p in u2})
    self.assertEqual({p.ewkt for p in ref_u1}, {p.ewkt for p in u3})
