'Testing the `dwithin` lookup type.'

@no_spatialite
def test02_dwithin(self):

    tx_dists = [(7000, 22965.83), D(km=7), D(mi=4.349)]
    au_dists = [(0.5, 32000), D(km=32), D(mi=19.884)]
    tx_cities = ['Downtown    Houston', 'Southside    Place']
    au_cities = ['Mittagong', 'Shellharbour', 'Thirroul', 'Wollongong']
    for dist in tx_dists:
        if isinstance(dist, tuple):
            (dist1, dist2) = dist
        else:
            dist1 = dist2 = dist
        qs1 = SouthTexasCity.objects.filter(point__dwithin=(self.stx_pnt, dist1))
        qs2 = SouthTexasCityFt.objects.filter(point__dwithin=(self.stx_pnt, dist2))
        for qs in (qs1, qs2):
            self.assertEqual(tx_cities, self.get_names(qs))
    for dist in au_dists:
        if (isinstance(dist, D) and (not oracle)):
            type_error = True
        else:
            type_error = False
        if isinstance(dist, tuple):
            if oracle:
                dist = dist[1]
            else:
                dist = dist[0]
        qs = AustraliaCity.objects.order_by('name')
        if type_error:
            self.assertRaises(ValueError, AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, dist)).count)
        else:
            self.assertEqual(au_cities, self.get_names(qs.filter(point__dwithin=(self.au_pnt, dist))))
