Skip to content

Commit a37977d

Browse files
committed
Address review
1 parent fc3bf2c commit a37977d

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

django_mongodb_backend/gis/lookups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66

77
def gis_lookup(self, compiler, connection, as_expr=False):
8+
if as_expr:
9+
raise NotSupportedError("MongoDB does not support GIS lookups as expressions.")
810
lhs_mql = process_lhs(self, compiler, connection, as_expr=as_expr)
911
rhs_mql = process_rhs(self, compiler, connection, as_expr=as_expr)
1012
try:

tests/gis_tests_/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class City(models.Model):
55
name = models.CharField(max_length=30)
66
point = models.PointField()
77

8+
def __str__(self):
9+
return self.name
10+
811

912
class Zipcode(models.Model):
1013
code = models.CharField(max_length=10)

tests/gis_tests_/tests.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def test_unsupported(self):
1818
def test_contains(self):
1919
houston = City.objects.get(name="Houston")
2020
qs = City.objects.filter(point__contains=Point(-95.363151, 29.763374))
21-
self.assertEqual(qs.count(), 1)
22-
self.assertEqual(houston, qs.first())
21+
self.assertCountEqual(qs, [houston])
2322

2423
def test_disjoint(self):
2524
houston = City.objects.get(name="Houston")
@@ -43,25 +42,21 @@ def test_distance_gte(self):
4342
def test_distance_lt(self):
4443
houston = City.objects.get(name="Houston")
4544
qs = City.objects.filter(point__distance_lt=(houston.point, 362825))
46-
self.assertEqual(qs.count(), 1)
47-
self.assertEqual(houston, qs.first())
45+
self.assertCountEqual(qs, [houston])
4846

4947
def test_distance_lte(self):
5048
houston = City.objects.get(name="Houston")
5149
dallas = City.objects.get(name="Dallas") # Roughly ~363 km from Houston
5250
qs = City.objects.filter(point__distance_lte=(houston.point, 362826))
53-
self.assertEqual(qs.count(), 2)
54-
self.assertEqual([houston, dallas], list(qs))
51+
self.assertCountEqual(list(qs), [houston, dallas])
5552

5653
def test_distance_units(self):
5754
chicago = City.objects.get(name="Chicago")
5855
lawrence = City.objects.get(name="Lawrence")
5956
qs = City.objects.filter(point__distance_lt=(chicago.point, Distance(km=720)))
60-
self.assertEqual(qs.count(), 2)
61-
self.assertEqual([lawrence, chicago], list(qs))
57+
self.assertCountEqual(list(qs), [lawrence, chicago])
6258
qs = City.objects.filter(point__distance_lt=(chicago.point, Distance(mi=447)))
63-
self.assertEqual(qs.count(), 2)
64-
self.assertEqual([lawrence, chicago], list(qs))
59+
self.assertCountEqual(list(qs), [lawrence, chicago])
6560

6661
def test_dwithin(self):
6762
houston = City.objects.get(name="Houston")
@@ -70,10 +65,8 @@ def test_dwithin(self):
7065

7166
def test_dwithin_unsupported_units(self):
7267
qs = City.objects.filter(point__dwithin=(Point(40.7670, -73.9820), Distance(km=1)))
73-
with self.assertRaisesMessage(
74-
ValueError,
75-
"Only numeric values of radian units are allowed on geodetic distance queries.",
76-
):
68+
message = "Only numeric values of radian units are allowed on geodetic distance queries."
69+
with self.assertRaisesMessage(ValueError, message):
7770
qs.first()
7871

7972
def test_intersects(self):
@@ -85,4 +78,4 @@ def test_intersects(self):
8578
def test_within(self):
8679
zipcode = Zipcode.objects.get(code="77002")
8780
qs = City.objects.filter(point__within=zipcode.poly).values_list("name", flat=True)
88-
self.assertEqual(["Houston"], list(qs))
81+
self.assertEqual(list(qs), ["Houston"])

0 commit comments

Comments
 (0)