MCPcopy
hub / github.com/django/django / test_simple_layermap

Method test_simple_layermap

tests/gis_tests/layermap/tests.py:76–98  ·  view source on GitHub ↗

Test LayerMapping import of a simple point shapefile.

(self)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected