Skip to content

Commit 86b1e75

Browse files
committed
Add tests for lookups
1 parent 462a54d commit 86b1e75

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/gis_tests_/tests.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,43 @@ def test_unsupported_lookups(self):
1111
msg = "MongoDB does not support the 'same_as' lookup."
1212
with self.assertRaisesMessage(NotSupportedError, msg):
1313
City.objects.get(point__same_as=Point(95, 30))
14+
15+
def test_within_lookup(self):
16+
city = City.objects.create(point=Point(95, 30))
17+
qs = City.objects.filter(point__within=Point(95, 30).buffer(10))
18+
self.assertIn(city, qs)
19+
20+
def test_intersects_lookup(self):
21+
city = City.objects.create(point=Point(95, 30))
22+
qs = City.objects.filter(point__intersects=Point(95, 30).buffer(10))
23+
self.assertIn(city, qs)
24+
25+
def test_disjoint_lookup(self):
26+
city = City.objects.create(point=Point(50, 30))
27+
qs = City.objects.filter(point__disjoint=Point(100, 50))
28+
self.assertIn(city, qs)
29+
30+
def test_contains_lookup(self):
31+
city = City.objects.create(point=Point(95, 30))
32+
qs = City.objects.filter(point__contains=Point(95, 30))
33+
self.assertIn(city, qs)
34+
35+
def test_distance_gt_lookup(self):
36+
city = City.objects.create(point=Point(95, 30))
37+
qs = City.objects.filter(point__distance_gt=(Point(0, 0), 100))
38+
self.assertIn(city, qs)
39+
40+
def test_distance_lt_lookup(self):
41+
city = City.objects.create(point=Point(40.7589, -73.9851))
42+
qs = City.objects.filter(point__distance_lt=(Point(40.7670, -73.9820), 1000))
43+
self.assertIn(city, qs)
44+
45+
def test_distance_gte_lookup(self):
46+
city = City.objects.create(point=Point(95, 30))
47+
qs = City.objects.filter(point__distance_gt=(Point(0, 0), 100))
48+
self.assertIn(city, qs)
49+
50+
def test_distance_lte_lookup(self):
51+
city = City.objects.create(point=Point(40.7589, -73.9851))
52+
qs = City.objects.filter(point__distance_lt=(Point(40.7670, -73.9820), 1000))
53+
self.assertIn(city, qs)

0 commit comments

Comments
 (0)