Ejemplo n.º 1
0
 def test_update(self):
     params = {
         'name': 'datastore3',
         'type': 'postgis',
         'ogrstring': 'pgsql://titi'
     }
     id1, id2 = self._insert_datastores()
     log_in(self.app, 'admin', 'password')
     response = self.app.put(url('DataStores', id=id2),
                             params=simplejson.dumps(params),
                             content_type='application/json')
     results = meta.Session.query(DataStore).all()
     assert len(results) == 2
     assert results[1].name == 'datastore3'
     assert results[1].type == 'postgis'
     assert results[1].ogrstring == 'pgsql://titi'
     log_out(self.app)
     # test forbidden user
     log_in(self.app, 'enduser', 'password')
     response = self.app.put(url('DataStores', id=id2),
                             status=403,
                             params=simplejson.dumps(params),
                             content_type='application/json')
     log_out(self.app)
     # test anonymous user
     response = self.app.put(url('DataStores', id=id2),
                             status=302,
                             params=simplejson.dumps(params),
                             content_type='application/json')
     assert response.location.find('signin') >= 0
Ejemplo n.º 2
0
 def test_update(self):
     params = {'name': 'datastore3',
               'type': 'postgis',
               'ogrstring': 'pgsql://titi'}
     id1, id2 = self._insert_datastores()        
     log_in(self.app, 'admin', 'password')
     response = self.app.put(url('DataStores', id=id2),
                             params = simplejson.dumps(params),
                             content_type='application/json')
     results = meta.Session.query(DataStore).all()
     assert len(results) == 2
     assert results[1].name == 'datastore3'
     assert results[1].type == 'postgis'
     assert results[1].ogrstring == 'pgsql://titi'        
     log_out(self.app)
     # test forbidden user
     log_in(self.app, 'enduser', 'password')
     response = self.app.put(url('DataStores', id=id2), status=403,
                             params = simplejson.dumps(params),
                             content_type='application/json')
     log_out(self.app)
     # test anonymous user
     response = self.app.put(url('DataStores', id=id2), status=302,
                             params = simplejson.dumps(params),
                             content_type='application/json')
     assert response.location.find('signin') >= 0
Ejemplo n.º 3
0
    def test_create(self):
        data_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                'data')
        single_file = [('datasources', os.path.join(data_dir, 'single_file'))]
        zip_file = [('datasources', os.path.join(data_dir, 'zip_archive.zip'))]
        tar_file = [('datasources', os.path.join(data_dir,
                                                 'tar_archive.tar.gz'))]

        log_in(self.app, 'admin', 'password')
        # create a new datastore for this test
        datastore_id = create_tmp_datastore(self.app)

        self.app.post(url(controller='datasources',
                          action='create',
                          datastore_id=datastore_id),
                      upload_files=single_file,
                      status=201)

        self.app.post(url(controller='datasources',
                          action='create',
                          datastore_id=datastore_id),
                      upload_files=zip_file,
                      status=201)

        self.app.post(url(controller='datasources',
                          action='create',
                          datastore_id=datastore_id),
                      upload_files=tar_file,
                      status=201)

        delete_tmp_datastore(self.app, datastore_id)
        log_out(self.app)
Ejemplo 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)
Ejemplo n.º 5
0
 def test_show_404(self):
     log_in(self.app, 'enduser', 'password')
     response = self.app.get(
         url(controller='datasources', action='show', datastore_id=99999, datasource_id=1),
         status=404
         )
     log_out(self.app)
Ejemplo n.º 6
0
 def test_index_404(self):
     self._insert_datastore()
     log_in(self.app, 'enduser', 'password')
     response = self.app.get(url(controller='datasources',
                                 action='index',
                                 datastore_id=99999),
                             status=404)
     log_out(self.app)
Ejemplo n.º 7
0
 def test_show_404(self):
     log_in(self.app, 'enduser', 'password')
     response = self.app.get(url(controller='datasources',
                                 action='show',
                                 datastore_id=99999,
                                 datasource_id=1),
                             status=404)
     log_out(self.app)
Ejemplo n.º 8
0
 def test_index_404(self):
     self._insert_datastore()
     log_in(self.app, 'enduser', 'password')
     response = self.app.get(
         url(controller='datasources', action='index', datastore_id=99999),
         status=404
         )
     log_out(self.app)
Ejemplo n.º 9
0
 def test_show(self):
     datastore_id = self._insert_datastore()
     log_in(self.app, 'enduser', 'password')
     # datasource "TM_WORLD_BORDERS_SIMPL-0.3"
     datasource_id = "3dfa880a8e37bcc97ff8bbeb9aff7852"
     response = self.app.get(
         url(controller='datasources', action='show', datastore_id=datastore_id, datasource_id=datasource_id),
         )
     assert response.response.content_type == 'application/json'
     log_out(self.app)
Ejemplo n.º 10
0
    def test_index(self):
        log_in(self.app, 'enduser', 'password')
        response = self.app.get(url(controller='main', action='index'), status=200)
        assert response.body.find('<script type="text/javascript" src="/layout.js"></script>') >= 0
        log_out(self.app)

        # test without being logged in
        response = self.app.get(url(controller='main', action='index'), status=302)
        urlparsed = urlparse(response.location)
        assert urlparsed.path == '/signin' # we are redirected to "signin"
Ejemplo n.º 11
0
 def test_show(self):
     datastore_id = self._insert_datastore()
     log_in(self.app, 'enduser', 'password')
     # datasource "TM_WORLD_BORDERS_SIMPL-0.3"
     datasource_id = "3dfa880a8e37bcc97ff8bbeb9aff7852"
     response = self.app.get(
         url(controller='datasources',
             action='show',
             datastore_id=datastore_id,
             datasource_id=datasource_id), )
     assert response.response.content_type == 'application/json'
     log_out(self.app)
Ejemplo n.º 12
0
 def test_show(self):
     id1, id2 = self._insert_datastores()
     log_in(self.app, 'admin', 'password')
     response = self.app.get(url('DataStores', id=id1, test="true"))
     assert response.response.content_type == 'application/json'
     r = simplejson.loads(response.response._body)
     assert r['id'] == id1
     assert r['type'] == 'postgis'
     assert r['name'] == 'datastore1'
     log_out(self.app)
     # test anonymous user
     response = self.app.get(url('DataStores', id=id1), status=302)
     assert response.location.find('signin') >= 0
Ejemplo n.º 13
0
 def test_show_mapfile(self):
     datastore_id = self._insert_datastore()
     log_in(self.app, 'enduser', 'password')
     # datasource "TM_WORLD_BORDERS_SIMPL-0.3"
     datasource_id = "3dfa880a8e37bcc97ff8bbeb9aff7852"
     response = self.app.get(
         url(controller='datasources', action='showmapfile', datastore_id=datastore_id, datasource_id=datasource_id),
         )
     assert response.response.content_type == 'application/json'
     response = simplejson.loads(response.response._body)
     assert isinstance(response, dict)
     assert response['type']=='polygon'
     log_out(self.app)
Ejemplo n.º 14
0
 def test_show(self):
     id1, id2 = self._insert_datastores()
     log_in(self.app, 'admin', 'password')
     response = self.app.get(url('DataStores', id=id1, test="true"))
     assert response.response.content_type == 'application/json'
     r = simplejson.loads(response.response._body)
     assert r['id'] == id1
     assert r['type'] == 'postgis'
     assert r['name'] == 'datastore1'
     log_out(self.app)
     # test anonymous user
     response = self.app.get(url('DataStores', id=id1), status=302)
     assert response.location.find('signin') >= 0
Ejemplo n.º 15
0
    def test_get_default_mapfile(self):
        """ GET /mapfiles/default: Get a default mapfile. """
        # login as admin to be allowed to access /mapfiles/1
        log_in(self.app, 'enduser', 'password')

        response = self.app.get(url(controller='mapfiles', action='get_default_mapfile'))
        assert response.response.content_type == 'application/json'
        assert '"map": {' in response

        # test redirection to /signin when log out
        log_out(self.app)
        response = self.app.get(url(controller='mapfiles', action='get_default_mapfile'), status=302)
        urlparsed = urlparse(response.location)
        assert urlparsed.path == '/signin' # we are redirected to "signin"
Ejemplo n.º 16
0
 def test_index(self):
     self._insert_datastores()
     log_in(self.app, 'admin', 'password')
     response = self.app.get(url('datastores'))
     assert response.response.content_type == 'application/json'
     response = simplejson.loads(response.response._body)
     assert isinstance(response, dict)
     r = response['datastores']
     assert isinstance(r, list)
     assert len(r) == 2
     log_out(self.app)
     # test anonymous user
     response = self.app.get(url('datastores'), status=302)
     assert response.location.find('signin') >= 0
Ejemplo n.º 17
0
 def test_index(self):
     self._insert_datastores()
     log_in(self.app, 'admin', 'password')
     response = self.app.get(url('datastores'))
     assert response.response.content_type == 'application/json'
     response = simplejson.loads(response.response._body)
     assert isinstance(response, dict)
     r = response['datastores']
     assert isinstance(r, list)
     assert len(r) == 2
     log_out(self.app)
     # test anonymous user
     response = self.app.get(url('datastores'), status=302)
     assert response.location.find('signin') >= 0
Ejemplo n.º 18
0
 def test_index(self):
     id = self._insert_datastore()
     log_in(self.app, 'enduser', 'password')
     response = self.app.get(
         url(controller='datasources', action='index', datastore_id=id), )
     assert response.response.content_type == 'application/json'
     response = simplejson.loads(response.response._body)
     assert isinstance(response, dict)
     r = response['datasources']
     assert isinstance(r, list)
     assert 'text' in r[0]
     assert 'id' in r[0]
     assert 'leaf' in r[0]
     assert 'type' in r[0]
     log_out(self.app)
Ejemplo n.º 19
0
 def test_show_mapfile(self):
     datastore_id = self._insert_datastore()
     log_in(self.app, 'enduser', 'password')
     # datasource "TM_WORLD_BORDERS_SIMPL-0.3"
     datasource_id = "3dfa880a8e37bcc97ff8bbeb9aff7852"
     response = self.app.get(
         url(controller='datasources',
             action='showmapfile',
             datastore_id=datastore_id,
             datasource_id=datasource_id), )
     assert response.response.content_type == 'application/json'
     response = simplejson.loads(response.response._body)
     assert isinstance(response, dict)
     assert response['type'] == 'polygon'
     log_out(self.app)
Ejemplo n.º 20
0
    def test_signout(self):
        log_in(self.app, 'enduser', 'password')
        # then test signout
        response = self.app.get(url(controller='main', action='signout'), status=302)
        urlparsed = urlparse(response.location)
        assert urlparsed.path == '/logout' # we are redirected to "logout"

        follow_response = response.follow()
        assert follow_response.status.startswith('302 ')
        urlparsed = urlparse(follow_response.location)
        assert urlparsed.path == '/signin' # we are redirected to "signin"

        # test you cannot signout twice
        response = self.app.get(url(controller='main', action='signout'), status=302)
        urlparsed = urlparse(response.location)
        assert urlparsed.path == '/signin' # we are redirected to "signin"
Ejemplo n.º 21
0
 def test_index(self):
     id = self._insert_datastore()
     log_in(self.app, 'enduser', 'password')
     response = self.app.get(
         url(controller='datasources', action='index', datastore_id=id),
         )
     assert response.response.content_type == 'application/json'
     response = simplejson.loads(response.response._body)
     assert isinstance(response, dict)
     r = response['datasources']
     assert isinstance(r, list)
     assert 'text' in r[0]
     assert 'id' in r[0]
     assert 'leaf' in r[0]
     assert 'type' in r[0]
     log_out(self.app)
Ejemplo n.º 22
0
 def test_show_columns(self):
     datastore_id = self._insert_datastore()
     log_in(self.app, 'enduser', 'password')
     # datasource "TM_WORLD_BORDERS_SIMPL-0.3"
     datasource_id = "3dfa880a8e37bcc97ff8bbeb9aff7852"
     response = self.app.get(
         url(controller='datasources', action='showcolumns', datastore_id=datastore_id, datasource_id=datasource_id),
         )
     assert response.response.content_type == 'application/json'
     response = simplejson.loads(response.response._body)
     assert 'columns' in response
     found_pop_column = False
     for column in response['columns']:
             if column['name'] == 'POP2005':
                 found_pop_column = True
     assert found_pop_column == True
     log_out(self.app)
Ejemplo n.º 23
0
 def test_delete(self):
     id1, id2 = self._insert_datastores()
     log_in(self.app, 'admin', 'password')
     response = self.app.delete(url('DataStores', id=id1), status=204)
     results = meta.Session.query(DataStore).all()
     assert len(results) == 1
     assert results[0].id == id2
     assert results[0].name == 'datastore2'
     assert results[0].type == 'path'
     assert results[0].ogrstring == 'file://my/path'
     log_out(self.app)
     # test forbidden user
     log_in(self.app, 'enduser', 'password')
     response = self.app.delete(url('DataStores', id=id1), status=403)
     log_out(self.app)
     # test anonymous user
     response = self.app.delete(url('DataStores', id=id1), status=302)
     assert response.location.find('signin') >= 0
Ejemplo n.º 24
0
 def test_delete(self):
     id1, id2 = self._insert_datastores()
     log_in(self.app, 'admin', 'password')
     response = self.app.delete(url('DataStores', id=id1), status=204)
     results = meta.Session.query(DataStore).all()
     assert len(results) == 1
     assert results[0].id == id2
     assert results[0].name == 'datastore2'
     assert results[0].type == 'path'
     assert results[0].ogrstring == 'file://my/path'
     log_out(self.app)
     # test forbidden user
     log_in(self.app, 'enduser', 'password')
     response = self.app.delete(url('DataStores', id=id1), status=403)
     log_out(self.app)
     # test anonymous user
     response = self.app.delete(url('DataStores', id=id1), status=302)
     assert response.location.find('signin') >= 0
Ejemplo n.º 25
0
 def test_show_columns(self):
     datastore_id = self._insert_datastore()
     log_in(self.app, 'enduser', 'password')
     # datasource "TM_WORLD_BORDERS_SIMPL-0.3"
     datasource_id = "3dfa880a8e37bcc97ff8bbeb9aff7852"
     response = self.app.get(
         url(controller='datasources',
             action='showcolumns',
             datastore_id=datastore_id,
             datasource_id=datasource_id), )
     assert response.response.content_type == 'application/json'
     response = simplejson.loads(response.response._body)
     assert 'columns' in response
     found_pop_column = False
     for column in response['columns']:
         if column['name'] == 'POP2005':
             found_pop_column = True
     assert found_pop_column == True
     log_out(self.app)
Ejemplo n.º 26
0
    def test_layout(self):
        # test log in as enduser
        log_in(self.app, 'enduser', 'password')
        response = self.app.get(url(controller='main', action='layout'), status=200)
        assert response.body.find('xtype: "studio.mm.chooser"') >= 0
        assert response.body.find('xtype: "studio.dm.chooser"') < 0
        log_out(self.app)

        # test log in as admin
        log_in(self.app, 'admin', 'password')
        response = self.app.get(url(controller='main', action='layout'), status=200)
        assert response.body.find('xtype: "studio.mm.chooser"') >= 0
        assert response.body.find('xtype: "studio.dm.chooser"') >= 0
        log_out(self.app)

        # test without being logged in
        response = self.app.get(url(controller='main', action='layout'), status=302)
        urlparsed = urlparse(response.location)
        assert urlparsed.path == '/signin' # we are redirected to "signin"
Ejemplo n.º 27
0
    def test_get_symbols(self):
        # 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')

        response = self.app.get(url(controller='mapfiles', action='get_symbols', id=map.id))
        assert response.response.content_type == 'application/json'
        assert '"symbols": [' in response

        # test redirection to /signin when log out
        log_out(self.app)
        response = self.app.get(url(controller='mapfiles', action='get_symbols', id=map.id),
                status=302)
        urlparsed = urlparse(response.location)
        assert urlparsed.path == '/signin' # we are redirected to "signin"

        # Clean the test mapfile
        delete_mapfile(map)
Ejemplo n.º 28
0
    def test_show(self):
        """ GET /mapfiles/id: Get a specific mapfile owned by the current user. """
        # 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')

        response = self.app.get(url('MapFiles', id=map.id))
        assert response.response.content_type == 'application/json'
        assert '"map": {' in response
        assert 'Dummy mapfile name' in response

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

        # Clean the test mapfile
        delete_mapfile(map)
Ejemplo n.º 29
0
    def test_create(self):
        data_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'data')
        single_file = [('datasources', os.path.join(data_dir, 'single_file'))]
        zip_file = [('datasources', os.path.join(data_dir, 'zip_archive.zip'))]
        tar_file = [('datasources', os.path.join(data_dir, 'tar_archive.tar.gz'))]

        log_in(self.app, 'admin', 'password')
        # create a new datastore for this test
        datastore_id = create_tmp_datastore(self.app)
        
        self.app.post(url(controller='datasources', action='create', datastore_id=datastore_id),
                      upload_files=single_file, status=201)

        self.app.post(url(controller='datasources', action='create', datastore_id=datastore_id),
                      upload_files=zip_file, status=201)

        self.app.post(url(controller='datasources', action='create', datastore_id=datastore_id),
                      upload_files=tar_file, status=201)

        delete_tmp_datastore(self.app, datastore_id)
        log_out(self.app)       
Ejemplo n.º 30
0
    def test_download(self):
        """ GET /mapfiles/id/download: Download the mapfile as an attachment. """
        # 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')

        response = self.app.get(url(controller='mapfiles', action='download_mapfile', id=map.id))
        assert response.content_type == 'text/plain'
        assert response.body.startswith('MAP')
        assert response.headers['content-disposition'] == 'attachment; filename=%s' \
                %os.path.join(config['mapfiles_dir'], filename)

        # test redirection to /signin when log out
        log_out(self.app)
        response = self.app.get(url(controller='mapfiles', action='download_mapfile', id=map.id),
                status=302)
        urlparsed = urlparse(response.location)
        assert urlparsed.path == '/signin' # we are redirected to "signin"

        # Clean the test mapfile
        delete_mapfile(map)
Ejemplo n.º 31
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)
Ejemplo n.º 32
0
    def test_delete(self):
        """DELETE /mapfiles/id: Delete an existing mapfile owned by the current
        user. Deletion of the map entry in db and remove mapfile from filesystem. """
        # 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')

        # delete request that must be tested
        response = self.app.delete(url('MapFiles', id=map.id))

        assert not(os.path.exists(os.path.join(config['mapfiles_dir'], map.filepath)))
        deleted_map = model.meta.Session.query(model.Map).get(map.id)
        assert deleted_map is None

        # assert mapfile doesn't still exist
        response = self.app.delete(url('MapFiles', id=2), status=404)

        # test redirection to /signin when log out
        log_out(self.app)
        response = self.app.delete(url('MapFiles', id=map.id), status=302)
        urlparsed = urlparse(response.location)
        assert urlparsed.path == '/signin' # we are redirected to "signin"
Ejemplo n.º 33
0
 def setUp(self):
     meta.Session.query(LayerTemplate).delete()
     log_in(self.app, 'enduser', 'password')
Ejemplo n.º 34
0
 def setUp(self):
     meta.Session.query(LayerTemplate).delete()
     log_in(self.app, 'enduser', 'password')