Testing the `strict` keyword, and import of a LineString shapefile.
(self)
| 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 | """ |
nothing calls this directly
no test coverage detected