'Testing the `Union` aggregate.'

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

    tx = Country.objects.get(name='Texas').mpoly
    union = GEOSGeometry('MULTIPOINT(-96.801611    32.782057,-95.363151    29.763374)')
    qs = City.objects.filter(point__within=tx)
    with self.assertRaises(ValueError):
        qs.aggregate(Union('name'))
    u1 = qs.aggregate(Union('point'))['point__union']
    u2 = qs.order_by('name').aggregate(Union('point'))['point__union']
    self.assertTrue(union.equals(u1))
    self.assertTrue(union.equals(u2))
    qs = City.objects.filter(name='NotACity')
    self.assertIsNone(qs.aggregate(Union('point'))['point__union'])
