Test LayerMapping import of a simple point shapefile.
(self)
| 74 | LayerMapping(City, city_shp, city_mapping, encoding="foobar") |
| 75 | |
| 76 | def test_simple_layermap(self): |
| 77 | "Test LayerMapping import of a simple point shapefile." |
| 78 | # Setting up for the LayerMapping. |
| 79 | lm = LayerMapping(City, city_shp, city_mapping) |
| 80 | lm.save() |
| 81 | |
| 82 | # There should be three cities in the shape file. |
| 83 | self.assertEqual(3, City.objects.count()) |
| 84 | |
| 85 | # Opening up the shapefile, and verifying the values in each |
| 86 | # of the features made it to the model. |
| 87 | ds = DataSource(city_shp) |
| 88 | layer = ds[0] |
| 89 | for feat in layer: |
| 90 | city = City.objects.get(name=feat["Name"].value) |
| 91 | self.assertEqual(feat["Population"].value, city.population) |
| 92 | self.assertEqual(Decimal(str(feat["Density"])), city.density) |
| 93 | self.assertEqual(feat["Created"].value, city.dt) |
| 94 | |
| 95 | # Comparing the geometries. |
| 96 | pnt1, pnt2 = feat.geom, city.point |
| 97 | self.assertAlmostEqual(pnt1.x, pnt2.x, 5) |
| 98 | self.assertAlmostEqual(pnt1.y, pnt2.y, 5) |
| 99 | |
| 100 | def test_data_source_str(self): |
| 101 | lm = LayerMapping(City, str(city_shp), city_mapping) |
nothing calls this directly
no test coverage detected