MCPcopy
hub / github.com/django/django / test_layermap_strict

Method test_layermap_strict

tests/gis_tests/layermap/tests.py:105–139  ·  view source on GitHub ↗

Testing the `strict` keyword, and import of a LineString shapefile.

(self)

Source from the content-addressed store, hash-verified

103 self.assertEqual(City.objects.count(), 3)
104
105 def test_layermap_strict(self):
106 "Testing the `strict` keyword, and import of a LineString shapefile."
107 # When the `strict` keyword is set an error encountered will force
108 # the importation to stop.
109 with self.assertRaises(InvalidDecimal):
110 lm = LayerMapping(Interstate, inter_shp, inter_mapping)
111 lm.save(silent=True, strict=True)
112 Interstate.objects.all().delete()
113
114 # This LayerMapping should work b/c `strict` is not set.
115 lm = LayerMapping(Interstate, inter_shp, inter_mapping)
116 lm.save(silent=True)
117
118 # Two interstate should have imported correctly.
119 self.assertEqual(2, Interstate.objects.count())
120
121 # Verifying the values in the layer w/the model.
122 ds = DataSource(inter_shp)
123
124 # Only the first two features of this shapefile are valid.
125 valid_feats = ds[0][:2]
126 for feat in valid_feats:
127 istate = Interstate.objects.get(name=feat["Name"].value)
128
129 if feat.fid == 0:
130 self.assertEqual(Decimal(str(feat["Length"])), istate.length)
131 elif feat.fid == 1:
132 # Everything but the first two decimal digits were truncated,
133 # because the Interstate model's `length` field has
134 # decimal_places=2.
135 self.assertAlmostEqual(feat.get("Length"), float(istate.length), 2)
136
137 for p1, p2 in zip(feat.geom, istate.path):
138 self.assertAlmostEqual(p1[0], p2[0], 6)
139 self.assertAlmostEqual(p1[1], p2[1], 6)
140
141 def county_helper(self, county_feat=True):
142 """

Callers

nothing calls this directly

Calls 7

saveMethod · 0.95
LayerMappingClass · 0.90
DataSourceClass · 0.90
deleteMethod · 0.45
allMethod · 0.45
countMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected