Exemplo n.º 1
0
 def get_symbols(self, id):
     map = self._get_map_from_user_by_id(c.user, id)
     if map is None:
         abort(404)
     mapfile = Mapfile()
     mapfile.from_file(os.path.join(config['mapfiles_dir'], map.filepath))
     # prevent JSON Array Cross-site Exploits (XSRF/CSRF)
     return {'symbols': mapfile.get_symbols()}
Exemplo n.º 2
0
 def get_symbols(self,id):
     map = self._get_map_from_user_by_id(c.user, id)
     if map is None:
         abort(404)
     mapfile = Mapfile()
     mapfile.from_file(os.path.join(config['mapfiles_dir'], map.filepath))
     # prevent JSON Array Cross-site Exploits (XSRF/CSRF)
     return {'symbols': mapfile.get_symbols()}
Exemplo n.º 3
0
 def show(self, id):
     """ GET /mapfiles/id: Get a specific mapfile owned by the current user. """
     map = self._get_map_from_user_by_id(c.user, id)
     if map is None:
         abort(404)
     mapfile = Mapfile()
     mapfile.from_file(os.path.join(config['mapfiles_dir'], map.filepath))
     return {
         'map': mapfile.to_dict(),
         'wmsproxyurl': h.url_for(controller='mapfiles', action='wms_proxy', id=id),
         'wmsurl': "%s?%s" %(config['mapserver_url'], urlencode({'map':os.path.join(config['mapfiles_dir'], map.filepath)}))
     }
Exemplo n.º 4
0
    def test_create(self):
        """POST /mapfiles: Create a new item."""
        # login as admin to be allowed to access /mapfiles/1
        log_in(self.app, 'enduser', 'password')

        mapfile = Mapfile()
        mapfile.from_file(os.path.join(config['mapserver_dir'], 'dummy_mapfile.map'))
        mapfile.set_name('Dummy mapfile name')
        mapfile = change_mapfile_paths(mapfile)
        dict = mapfile.to_dict()
        content = simplejson.dumps(dict)

        # post create request that must be tested
        response = self.app.post(url('mapfiles'), params=content, content_type='application/json')
        dict = simplejson.loads(response.normal_body)

        print os.path.join(config['mapfiles_dir'], dict['name'])
        map = model.meta.Session.query(model.Map).filter(model.Map.name=='Dummy mapfile name').one()
        assert map.id == dict['id']
        assert map.name == dict['name']
        assert os.path.exists(os.path.join(config['mapfiles_dir'], map.filepath))

        # test redirection to /signin when log out
        log_out(self.app)
        response = self.app.post(url('mapfiles'), params=content, content_type='application/json',
                status=302)
        urlparsed = urlparse(response.location)
        assert urlparsed.path == '/signin' # we are redirected to "signin"

        # Clean the mapfile created by POST request
        delete_mapfile(map)
Exemplo n.º 5
0
 def show(self, id):
     """ GET /mapfiles/id: Get a specific mapfile owned by the current user. """
     map = self._get_map_from_user_by_id(c.user, id)
     if map is None:
         abort(404)
     mapfile = Mapfile()
     mapfile.from_file(os.path.join(config['mapfiles_dir'], map.filepath))
     return {
         'map':
         mapfile.to_dict(),
         'wmsproxyurl':
         h.url_for(controller='mapfiles', action='wms_proxy', id=id),
         'wmsurl':
         "%s?%s" %
         (config['mapserver_url'],
          urlencode(
              {'map': os.path.join(config['mapfiles_dir'], map.filepath)}))
     }
Exemplo n.º 6
0
    def create(self):
        """POST /mapfiles: Create a new item."""
        # get json content from POST request
        content = request.environ['wsgi.input'].read(int(request.environ['CONTENT_LENGTH']))
        #content = content.decode('utf8')   mapfile interface don't like unicode strings... bad...

        # load mapfile
        mapfile = Mapfile()
        dict = simplejson.loads(content)
        mapfile.from_dict(dict)

        # create mapfile
        mapname = mapfile.get_name()
        map_pathname = h.gen_mapname()
        mapfile.to_file(os.path.join(config['mapfiles_dir'], map_pathname))

        # create map in db
        map = self._new_map_from_user(c.user, mapname, map_pathname)

        response.status = 201

        href = h.url_for(controller="mapfiles", action="show", id=map.id)
        wmsproxyurl = h.url_for(controller='mapfiles', action='wms_proxy', id=map.id)
        wmsurl = "%s?%s" %(config['mapserver_url'], urlencode({'map':os.path.join(config['mapfiles_dir'], map.filepath)}))
        return {'name': map.name, 'id': map.id, 'href': href, 'wmsurl': wmsurl, 'wmsproxyurl': wmsproxyurl}
Exemplo n.º 7
0
def create_mapfile(mapfile_name, pathname, user_id=2):
    # copy test mapfile dummy_mapfile.map and change fontset and symbolset paths
    # so that it matches user environnement
    mapfile = Mapfile()
    mapfile.from_file(os.path.join(config['mapserver_dir'], 'dummy_mapfile.map'))
    mapfile.set_name(mapfile_name)
    mapfile = change_mapfile_paths(mapfile)
    mapfile.to_file(os.path.join(config['mapfiles_dir'], pathname))
    assert os.path.exists(os.path.join(config['mapfiles_dir'], pathname))
    # db insertion of new mapfile
    map = Map(mapfile_name, pathname, user_id)
    meta.Session.add(map)
    meta.Session.commit()
    return map
Exemplo n.º 8
0
    def update(self, id):
        """PUT /mapfiles/id: Update an existing item."""
        map = self._get_map_from_user_by_id(c.user, id)
        if map is None:
            abort(404)

        # get json content from PUT request
        content = request.environ['wsgi.input'].read(
            int(request.environ['CONTENT_LENGTH']))
        #content = content.decode('utf8')

        # update mapfile
        mapfile = Mapfile()
        dict = simplejson.loads(content)
        mapfile.from_dict(dict)
        mapfile.to_file(os.path.join(config['mapfiles_dir'], map.filepath))
        if mapfile.get_name() != map.name:
            self._update_map(map, name=mapfile.get_name())

        response.status = 201
        return
Exemplo n.º 9
0
    def update(self, id):
        """PUT /mapfiles/id: Update an existing item."""
        map = self._get_map_from_user_by_id(c.user, id)
        if map is None:
            abort(404)

        # get json content from PUT request
        content = request.environ['wsgi.input'].read(int(request.environ['CONTENT_LENGTH']))
        #content = content.decode('utf8')

        # update mapfile
        mapfile = Mapfile()
        dict = simplejson.loads(content)
        mapfile.from_dict(dict)
        mapfile.to_file(os.path.join(config['mapfiles_dir'], map.filepath))
        if mapfile.get_name() != map.name:
            self._update_map(map, name=mapfile.get_name())

        response.status = 201
        return
Exemplo n.º 10
0
    def create(self):
        """POST /mapfiles: Create a new item."""
        # get json content from POST request
        content = request.environ['wsgi.input'].read(
            int(request.environ['CONTENT_LENGTH']))
        #content = content.decode('utf8')   mapfile interface don't like unicode strings... bad...

        # load mapfile
        mapfile = Mapfile()
        dict = simplejson.loads(content)
        mapfile.from_dict(dict)

        # create mapfile
        mapname = mapfile.get_name()
        map_pathname = h.gen_mapname()
        mapfile.to_file(os.path.join(config['mapfiles_dir'], map_pathname))

        # create map in db
        map = self._new_map_from_user(c.user, mapname, map_pathname)

        response.status = 201

        href = h.url_for(controller="mapfiles", action="show", id=map.id)
        wmsproxyurl = h.url_for(controller='mapfiles',
                                action='wms_proxy',
                                id=map.id)
        wmsurl = "%s?%s" % (
            config['mapserver_url'],
            urlencode(
                {'map': os.path.join(config['mapfiles_dir'], map.filepath)}))
        return {
            'name': map.name,
            'id': map.id,
            'href': href,
            'wmsurl': wmsurl,
            'wmsproxyurl': wmsproxyurl
        }
Exemplo n.º 11
0
    def test_update(self):
        """PUT /mapfiles/id: Update an existing item."""
        # Create new mapfile for this test
        filename = h.gen_mapname()
        map = create_mapfile('Dummy mapfile name', filename)
        # login as admin to be allowed to access /mapfiles/1
        log_in(self.app, 'enduser', 'password')

        mapfile = Mapfile()
        mapfile.from_file(os.path.join(config['mapserver_dir'], 'dummy_mapfile.map'))
        mapfile.set_name('New dummy name')
        mapfile = change_mapfile_paths(mapfile)
        dict = mapfile.to_dict()
        content = simplejson.dumps(dict)

        # PUT update request that must be tested
        map_id = map.id
        response = self.app.put(url('MapFiles', id=map_id), params=content,
                content_type='application/json')
        updated_map = model.meta.Session.query(model.Map).get(map_id)
        assert updated_map.name == 'New dummy name'
        map_path = os.path.join(config['mapfiles_dir'],updated_map.filepath)
        assert os.path.exists(map_path)
        mapobj = Mapfile()
        mapobj.from_file(map_path)
        assert mapobj.get_name() == 'New dummy name'

        # test redirection to /signin when log out
        log_out(self.app)
        response = self.app.get(url('MapFiles', id=map_id), params=content,
                status=302)
        urlparsed = urlparse(response.location)
        assert urlparsed.path == '/signin' # we are redirected to "signin"

        # Clean the test mapfile
        delete_mapfile(updated_map)