示例#1
0
    def test_render_validate(self):
        params = {'Spot--the_geom': 'Point(0 1)'}

        spot_fieldset = FieldSet(Spot, data = params)

        spot_fieldset.validate()
        form = spot_fieldset.render()
        ok_("Point(0 1)'" in form, 'submitted value was not re-displayed in case of validation error')
示例#2
0
    def test_deserialize(self):
        params = {'Spot--the_geom': 'Point(0 1)', 'Spot--name': 'dummy'}
        session = FakeSession()

        spot_fieldset = FieldSet(Spot, data = params, session=session)
        spot_fieldset.the_geom.set(options=[('map_srid', 4326)])

        spot_fieldset.validate()
        spot_fieldset.sync()
        ok_(isinstance(spot_fieldset.model.the_geom, WKTSpatialElement), 'Geometry was not assigned to model')
        eq_(str(spot_fieldset.model.the_geom), 'Point(0 1)', 'wkt is wrong')

        params = {'Spot--the_geom': ' ', 'Spot--name': ''}
        spot_fieldset = FieldSet(Spot, data = params, session=session)
        spot_fieldset.validate()
        spot_fieldset.sync()
        ok_(spot_fieldset.model.the_geom is None, 'Geometry is not set to None for empty strings')
 def test_deserialize_reproject(self):
     params = {'Spot--the_geom': 'Point(0 1)', 'Spot--name': 'dummy'}
     session = FakeSession()
     
     spot_fieldset = FieldSet(Spot, data = params, session=session)
     spot_fieldset.the_geom.set(options=[('map_srid', 900913)])
     
     spot_fieldset.validate()
     spot_fieldset.sync()
     ok_(isinstance(spot_fieldset.model.the_geom, WKTSpatialElement), 'Geometry was not assigned to model')
     eq_(spot_fieldset.model.the_geom.desc, 'geometry', 'The geometry was not reprojected for the insertion into the db')
     
     spot_fieldset.render()
     ok_(isinstance(session.scalar_args[0], functions.wkt), 'The geometry was not queried as WKT')
     ok_(isinstance(session.scalar_args[0].arguments[0], functions.transform), 'The geometry was not reprojected')
     
     params = {'Spot--the_geom': ' ', 'Spot--name': ''}
     spot_fieldset = FieldSet(Spot, data = params, session=session)
     spot_fieldset.validate()
     spot_fieldset.sync()
     ok_(spot_fieldset.model.the_geom is None, 'Geometry is not set to None for empty strings')