def test_iterable(self): iterable = (('geometry', self.geom), ) self.assertEqual(Feature(iterable=iterable), { 'geometry': self.geom, 'type': 'Feature', 'properties': {} })
def test_feature(self): feature = Feature(geometry=_geom) geojson = str(feature) geom = self.field.to_python(geojson) self.assertEqual(json.loads(geom.geojson), feature['geometry']) geom = self.field.to_python(feature) self.assertEqual(json.loads(geom.geojson), feature['geometry'])
def setUp(self): super(FeatureSerializerTestCase, self).setUp() attrs = {'id': 1, 'crs': 4326, 'geometry': {'type': 'Polygon', 'coordinates': self.coords}, 'properties': {'name': 'Argentina'}} self.expected = Feature(**attrs)
def test_dict(self): self.assertEqual( Feature(**{ 'geometry': self.geom, 'name': 'atlantic' }), { 'geometry': self.geom, 'type': 'Feature', 'properties': { 'name': 'atlantic' } })
def test_deserialize_projected(self): feat = Feature(**dict(self.expected, crs=4269)).copy() serializer = LocationFeatureSerializer(data=feat) self.assertTrue(serializer.is_valid()) object = serializer.save() self.assertEqual(object.geom.srid, 4269)
def test_render_feature(self): data = json.loads(self.r.render(self.data)) self.assertEqual(data, self.data) self.assertEqual(self.r.render({}), str(Feature()))
def setUp(self): self.data = Feature(id=1, properties={'name': 'San Francisco'}, geometry=_geom) self.collection = FeatureCollection(features=[self.data]) self.r = renderers.GeoJSONRenderer()
def test_feature_to_python(self): feature = Feature(geometry=_geom) self.fp.write(str(feature).encode('ascii')) self.fp.seek(0) v = self.field.to_python(self.fp) self.assertIsInstance(v, OGRGeometry)
def test_feature_srid(self): srid = 3857 feature = Feature(geometry=_geom, crs=NamedCRS(srid)) geom = self.field.to_python(str(feature)) self.assertEqual(geom.srid, srid)
def test_str(self): feat = Feature(properties={'event': datetime.date(1899, 1, 1)}) self.assertIn('"properties": {"event": "1899-01-01"}', str(feat))
def test_crs_epsg(self): self.assertEqual(Feature(crs=3310)['crs'], self.crs)
def test_crs(self): feat = Feature(crs=self.crs) self.assertEqual(feat['crs'], self.crs)
def test_copy(self): self.assertIsInstance(Feature().copy(), Feature)