|
9 | 9 | MultiPoint, MultiPolygon, Point, Polygon, fromstr, |
10 | 10 | ) |
11 | 11 | from django.core.management import call_command |
12 | | -from django.db import NotSupportedError, connection |
| 12 | +from django.db import DatabaseError, NotSupportedError, connection |
13 | 13 | from django.test import TestCase, skipUnlessDBFeature |
14 | 14 |
|
15 | 15 | from ..utils import ( |
@@ -564,6 +564,42 @@ def test_unionagg(self): |
564 | 564 | qs = City.objects.filter(name='NotACity') |
565 | 565 | self.assertIsNone(qs.aggregate(Union('point'))['point__union']) |
566 | 566 |
|
| 567 | + @unittest.skipUnless( |
| 568 | + connection.vendor == 'oracle', |
| 569 | + 'Oracle supports tolerance paremeter.', |
| 570 | + ) |
| 571 | + def test_unionagg_tolerance(self): |
| 572 | + City.objects.create( |
| 573 | + point=fromstr('POINT(-96.467222 32.751389)', srid=4326), |
| 574 | + name='Forney', |
| 575 | + ) |
| 576 | + tx = Country.objects.get(name='Texas').mpoly |
| 577 | + # Tolerance is greater than distance between Forney and Dallas, that's |
| 578 | + # why Dallas is ignored. |
| 579 | + forney_houston = GEOSGeometry( |
| 580 | + 'MULTIPOINT(-95.363151 29.763374, -96.467222 32.751389)', |
| 581 | + srid=4326, |
| 582 | + ) |
| 583 | + self.assertIs( |
| 584 | + forney_houston.equals( |
| 585 | + City.objects.filter(point__within=tx).aggregate( |
| 586 | + Union('point', tolerance=32000), |
| 587 | + )['point__union'], |
| 588 | + ), |
| 589 | + True, |
| 590 | + ) |
| 591 | + |
| 592 | + @unittest.skipUnless( |
| 593 | + connection.vendor == 'oracle', |
| 594 | + 'Oracle supports tolerance paremeter.', |
| 595 | + ) |
| 596 | + def test_unionagg_tolerance_escaping(self): |
| 597 | + tx = Country.objects.get(name='Texas').mpoly |
| 598 | + with self.assertRaises(DatabaseError): |
| 599 | + City.objects.filter(point__within=tx).aggregate( |
| 600 | + Union('point', tolerance='0.05))), (((1'), |
| 601 | + ) |
| 602 | + |
567 | 603 | def test_within_subquery(self): |
568 | 604 | """ |
569 | 605 | Using a queryset inside a geo lookup is working (using a subquery) |
|
0 commit comments