Skip to content

Commit 0f6a6e7

Browse files
committed
adapt GIS tests for MongoDB
1 parent 3d1d7c8 commit 0f6a6e7

File tree

13 files changed

+122
-72
lines changed

13 files changed

+122
-72
lines changed

django/contrib/gis/db/backends/base/operations.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ def select_extent(self):
3939
"AsGML",
4040
"AsKML",
4141
"AsSVG",
42+
"AsWKB",
43+
"AsWKT",
4244
"Azimuth",
4345
"BoundingCircle",
4446
"Centroid",
4547
"ClosestPoint",
4648
"Difference",
4749
"Distance",
4850
"Envelope",
51+
"ForcePolygonCW",
4952
"FromWKB",
5053
"FromWKT",
5154
"GeoHash",

django/core/management/commands/loaddata.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
DEFAULT_DB_ALIAS,
1919
DatabaseError,
2020
IntegrityError,
21+
connection,
2122
connections,
2223
router,
2324
transaction,
@@ -251,7 +252,24 @@ def load_label(self, fixture_label):
251252

252253
for obj in objects:
253254
objects_in_fixture += 1
255+
256+
# Workaround for MongoDB to ignore unsupported SRIDs in test
257+
# fixtures.
258+
if connection.features.gis_enabled:
259+
from django.contrib.gis.db.models import GeometryField
260+
261+
invalid_srid = False
262+
for field in obj.object._meta.fields:
263+
if isinstance(field, GeometryField):
264+
val = getattr(obj.object, field.name)
265+
if val and val.srid in {32140, 2278}:
266+
invalid_srid = True
267+
break
268+
if invalid_srid:
269+
continue
270+
254271
if self.save_obj(obj):
272+
255273
loaded_objects_in_fixture += 1
256274
if show_progress:
257275
self.stdout.write(

tests/gis_tests/distapp/fixtures/initial.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"pk": 1,
3+
"pk": "000000000000000000000001",
44
"model": "distapp.southtexascity",
55
"fields": {
66
"name": "Downtown Houston",
@@ -32,47 +32,47 @@
3232
}
3333
},
3434
{
35-
"pk": 5,
35+
"pk": "000000000000000000000005",
3636
"model": "distapp.southtexascity",
3737
"fields": {
3838
"name": "Pearland",
3939
"point": "SRID=32140;POINT (959674.6165056140162051 4197465.6525986101478338)"
4040
}
4141
},
4242
{
43-
"pk": 6,
43+
"pk": "000000000000000000000006",
4444
"model": "distapp.southtexascity",
4545
"fields": {
4646
"name": "Galveston",
4747
"point": "SRID=32140;POINT (1008151.1600717274704948 4170027.4765489147976041)"
4848
}
4949
},
5050
{
51-
"pk": 7,
51+
"pk": "000000000000000000000007",
5252
"model": "distapp.southtexascity",
5353
"fields": {
5454
"name": "Sealy",
5555
"point": "SRID=32140;POINT (874859.2868079885374755 4219186.8640952249988914)"
5656
}
5757
},
5858
{
59-
"pk": 8,
59+
"pk": "000000000000000000000008",
6060
"model": "distapp.southtexascity",
6161
"fields": {
6262
"name": "San Antonio",
6363
"point": "SRID=32140;POINT (649173.9104827501578256 4176413.2778564509935677)"
6464
}
6565
},
6666
{
67-
"pk": 9,
67+
"pk": "000000000000000000000009",
6868
"model": "distapp.southtexascity",
6969
"fields": {
7070
"name": "Saint Hedwig",
7171
"point": "SRID=32140;POINT (677644.6499522707890719 4175467.0674387565813959)"
7272
}
7373
},
7474
{
75-
"pk": 1,
75+
"pk": "000000000000000000000001",
7676
"model": "distapp.southtexascityft",
7777
"fields": {
7878
"name": "Downtown Houston",
@@ -104,47 +104,47 @@
104104
}
105105
},
106106
{
107-
"pk": 5,
107+
"pk": "000000000000000000000005",
108108
"model": "distapp.southtexascityft",
109109
"fields": {
110110
"name": "Pearland",
111111
"point": "SRID=2278;POINT (3148532.4709855038672686 13771185.2282339502125978)"
112112
}
113113
},
114114
{
115-
"pk": 6,
115+
"pk": "000000000000000000000006",
116116
"model": "distapp.southtexascityft",
117117
"fields": {
118118
"name": "Galveston",
119119
"point": "SRID=2278;POINT (3307575.9310019947588444 13681165.1456442419439554)"
120120
}
121121
},
122122
{
123-
"pk": 7,
123+
"pk": "000000000000000000000007",
124124
"model": "distapp.southtexascityft",
125125
"fields": {
126126
"name": "Sealy",
127127
"point": "SRID=2278;POINT (2870267.5101358774118125 13842448.9029524270445108)"
128128
}
129129
},
130130
{
131-
"pk": 8,
131+
"pk": "000000000000000000000008",
132132
"model": "distapp.southtexascityft",
133133
"fields": {
134134
"name": "San Antonio",
135135
"point": "SRID=2278;POINT (2129831.4046421577222645 13702115.8954340498894453)"
136136
}
137137
},
138138
{
139-
"pk": 9,
139+
"pk": "000000000000000000000009",
140140
"model": "distapp.southtexascityft",
141141
"fields": {
142142
"name": "Saint Hedwig",
143143
"point": "SRID=2278;POINT (2223239.1557184099219739 13699011.5367553308606148)"
144144
}
145145
},
146146
{
147-
"pk": 1,
147+
"pk": "000000000000000000000001",
148148
"model": "distapp.australiacity",
149149
"fields": {
150150
"name": "Wollongong",
@@ -176,63 +176,63 @@
176176
}
177177
},
178178
{
179-
"pk": 5,
179+
"pk": "000000000000000000000005",
180180
"model": "distapp.australiacity",
181181
"fields": {
182182
"name": "Batemans Bay",
183183
"point": "SRID=4326;POINT (150.1750000000000114 -35.7081999999999979)"
184184
}
185185
},
186186
{
187-
"pk": 6,
187+
"pk": "000000000000000000000006",
188188
"model": "distapp.australiacity",
189189
"fields": {
190190
"name": "Canberra",
191191
"point": "SRID=4326;POINT (144.9629999999999939 -37.8143000000000029)"
192192
}
193193
},
194194
{
195-
"pk": 7,
195+
"pk": "000000000000000000000007",
196196
"model": "distapp.australiacity",
197197
"fields": {
198198
"name": "Melbourne",
199199
"point": "SRID=4326;POINT (145.9629999999999939 -37.8143000000000029)"
200200
}
201201
},
202202
{
203-
"pk": 8,
203+
"pk": "000000000000000000000008",
204204
"model": "distapp.australiacity",
205205
"fields": {
206206
"name": "Sydney",
207207
"point": "SRID=4326;POINT (151.2607099999999889 -33.8870339999999999)"
208208
}
209209
},
210210
{
211-
"pk": 9,
211+
"pk": "000000000000000000000009",
212212
"model": "distapp.australiacity",
213213
"fields": {
214214
"name": "Hobart",
215215
"point": "SRID=4326;POINT (147.3300000000000125 -42.8826999999999998)"
216216
}
217217
},
218218
{
219-
"pk": 10,
219+
"pk": "000000000000000000000011",
220220
"model": "distapp.australiacity",
221221
"fields": {
222222
"name": "Adelaide",
223223
"point": "SRID=4326;POINT (138.5999999999999943 -34.9258000000000024)"
224224
}
225225
},
226226
{
227-
"pk": 11,
227+
"pk": "000000000000000000000012",
228228
"model": "distapp.australiacity",
229229
"fields": {
230230
"name": "Hillsdale",
231231
"point": "SRID=4326;POINT (151.2313409999999863 -33.9526850000000024)"
232232
}
233233
},
234234
{
235-
"pk": 1,
235+
"pk": "000000000000000000000001",
236236
"model": "distapp.censuszipcode",
237237
"fields": {
238238
"name": "77002",
@@ -264,7 +264,7 @@
264264
}
265265
},
266266
{
267-
"pk": 1,
267+
"pk": "000000000000000000000001",
268268
"model": "distapp.southtexaszipcode",
269269
"fields": {
270270
"name": "77002",
@@ -296,15 +296,15 @@
296296
}
297297
},
298298
{
299-
"pk": 1,
299+
"pk": "000000000000000000000001",
300300
"model": "distapp.interstate",
301301
"fields": {
302302
"path": "SRID=4326;LINESTRING (-104.4780170766107972 36.6669879187069370, -104.4468522338494978 36.7992540939338610, -104.4621269262599981 36.9372149776075034, -104.5126119783767962 37.0816326882088703, -104.5247764602161027 37.2930049989204804, -104.7084397427667994 37.4915025992539768, -104.8126599016281943 37.6951428562186308, -104.8452887035466006 37.8761339565947921, -104.7160169341002955 38.0595176333779932, -104.6165437927668052 38.3043204585510608, -104.6437227858174026 38.5397998656473675, -104.7596170387259065 38.7322907594295032, -104.8380078676821938 38.8999846060434109, -104.8501253693505930 39.0998018921335770, -104.8791648316464062 39.2436877645750286, -104.8635041274215070 39.3785278162751027, -104.8894471170052043 39.5929228239604996, -104.9721242843343987 39.6952848241968468, -105.0112104500356054 39.7273080432393968, -105.0010368577104032 39.7667760781157114, -104.9818356189999946 39.8146650412196692, -104.9858891550477011 39.8880691125083189, -104.9873548059578070 39.9811723457101635, -104.9766220487419019 40.0979642345069180, -104.9818565932953049 40.3605653066288426, -104.9912746373996981 40.7490448444765576)",
303303
"name": "I-25"
304304
}
305305
},
306306
{
307-
"pk": 1,
307+
"pk": "000000000000000000000001",
308308
"model": "distapp.southtexasinterstate",
309309
"fields": {
310310
"path": "SRID=32140;LINESTRING (924952.5000000000000000 4220931.5999999996274710, 925065.3000000000465661 4220931.5999999996274710, 929568.4000000000232831 4221057.7999999998137355)",
7 Bytes
Binary file not shown.

tests/gis_tests/geoapp/test_expressions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def test_update_from_other_field(self):
5454
obj.point3.equals_exact(p1.transform(3857, clone=True), 0.1)
5555
)
5656

57+
@skipUnlessDBFeature("has_Distance_function")
5758
def test_multiple_annotation(self):
5859
multi_field = MultiFields.objects.create(
5960
point=Point(1, 1),

tests/gis_tests/geoapp/test_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def test_memsize(self):
559559
# Exact value depends on database and version.
560560
self.assertTrue(20 <= ptown.size <= 105)
561561

562-
@skipUnlessDBFeature("has_NumGeom_function")
562+
@skipUnlessDBFeature("has_NumGeometries_function")
563563
def test_num_geom(self):
564564
# Both 'countries' only have two geometries.
565565
for c in Country.objects.annotate(num_geom=functions.NumGeometries("mpoly")):
@@ -576,7 +576,7 @@ def test_num_geom(self):
576576
else:
577577
self.assertEqual(1, city.num_geom)
578578

579-
@skipUnlessDBFeature("has_NumPoint_function")
579+
@skipUnlessDBFeature("has_NumPoints_function")
580580
def test_num_points(self):
581581
coords = [(-95.363151, 29.763374), (-95.448601, 29.713803)]
582582
Track.objects.create(name="Foo", line=LineString(coords))

tests/gis_tests/geoapp/tests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,10 @@ def test_null_geometries(self):
507507
self.assertIsNone(nmi.poly)
508508

509509
# Assigning a geometry and saving -- then UPDATE back to NULL.
510-
nmi.poly = "POLYGON((0 0,1 0,1 1,1 0,0 0))"
510+
511+
# Edited from "POLYGON((0 0,1 0,1 1,1 0,0 0))"
512+
# MongoDB: Duplicate vertices: 1 and 3
513+
nmi.poly = "POLYGON((0 0,1 0,1 1,0 0))"
511514
nmi.save()
512515
State.objects.filter(name="Northern Mariana Islands").update(poly=None)
513516
self.assertIsNone(State.objects.get(name="Northern Mariana Islands").poly)

tests/gis_tests/geogapp/fixtures/initial.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"pk": 1,
3+
"pk": "000000000000000000000001",
44
"model": "geogapp.city",
55
"fields": {
66
"name": "Houston",
@@ -32,39 +32,39 @@
3232
}
3333
},
3434
{
35-
"pk": 5,
35+
"pk": "000000000000000000000005",
3636
"model": "geogapp.city",
3737
"fields": {
3838
"name": "Pueblo",
3939
"point": "POINT (-104.609252 38.255001)"
4040
}
4141
},
4242
{
43-
"pk": 6,
43+
"pk": "000000000000000000000006",
4444
"model": "geogapp.city",
4545
"fields": {
4646
"name": "Lawrence",
4747
"point": "POINT (-95.235060 38.971823)"
4848
}
4949
},
5050
{
51-
"pk": 7,
51+
"pk": "000000000000000000000007",
5252
"model": "geogapp.city",
5353
"fields": {
5454
"name": "Chicago",
5555
"point": "POINT (-87.650175 41.850385)"
5656
}
5757
},
5858
{
59-
"pk": 8,
59+
"pk": "000000000000000000000008",
6060
"model": "geogapp.city",
6161
"fields": {
6262
"name": "Victoria",
6363
"point": "POINT (-123.305196 48.462611)"
6464
}
6565
},
6666
{
67-
"pk": 1,
67+
"pk": "000000000000000000000001",
6868
"model": "geogapp.zipcode",
6969
"fields" : {
7070
"code" : "77002",

0 commit comments

Comments
 (0)