Exemple #1
0
 def check_and_pass_through_timestep(self, redirect_to):
     time_step = upload_step('time')
     srs_step = upload_step('srs')
     if srs_step in redirect_to:
         resp = self.client.make_request(redirect_to)
     else:
         self.assertTrue(time_step in redirect_to)
     resp = self.client.make_request(redirect_to)
     token = self.client.get_csrf_token(True)
     self.assertEqual(resp.status_code, 200)
     resp = self.client.make_request(
         redirect_to, {'csrfmiddlewaretoken': token}, ajax=True)
     return resp, resp.json()
Exemple #2
0
    def test_time(self):
        """Verify that uploading time based shapefile works properly"""
        cascading_delete(self.catalog, 'boxes_with_date')

        timedir = os.path.join(GOOD_DATA, 'time')
        layer_name = 'boxes_with_date'
        shp = os.path.join(timedir, '%s.shp' % layer_name)

        # get to time step
        resp, data = self.client.upload_file(shp)
        self.assertEquals(resp.code, 200)
        if not isinstance(data, basestring):
            self.wait_for_progress(data.get('progress'))
            self.assertTrue(data['success'])
            self.assertTrue(data['redirect_to'], upload_step('time'))
            redirect_to = data['redirect_to']
            resp, data = self.client.get_html(upload_step('time'))
            self.assertEquals(resp.code, 200)
            data = dict(
                csrfmiddlewaretoken=self.client.get_csrf_token(),
                time_attribute='date',
                presentation_strategy='LIST',
            )
            resp = self.client.make_request(redirect_to, data)
            self.assertEquals(resp.code, 200)
            resp_js = json.loads(resp.read())
            if resp_js['success']:
                url = resp_js['redirect_to']

                resp = self.client.make_request(url, data)

                url = json.loads(resp.read())['url']

                self.assertTrue(
                    url.endswith(layer_name),
                    'expected url to end with %s, but got %s' %
                    (layer_name, url))
                self.assertEquals(resp.code, 200)

                url = urllib.unquote(url)
                self.check_layer_complete(url, layer_name)
                wms = get_wms(type_name='geonode:%s' % layer_name,
                              username=GEOSERVER_USER,
                              password=GEOSERVER_PASSWD)
                layer_info = wms.items()[0][1]
                self.assertEquals(100, len(layer_info.timepositions))
            else:
                self.assertTrue('error_msg' in resp_js)
                self.assertTrue(
                    'Source SRS is not valid' in resp_js['error_msg'])
    def test_time(self):
        """Verify that uploading time based shapefile works properly"""
        cascading_delete(layer_name='boxes_with_date', catalog=self.catalog)

        timedir = os.path.join(GOOD_DATA, 'time')
        layer_name = 'boxes_with_date'
        shp = os.path.join(timedir, f'{layer_name}.shp')

        # get to time step
        resp, data = self.client.upload_file(shp)
        self.assertEqual(resp.status_code, 200)
        if not isinstance(data, str):
            # self.wait_for_progress(data.get('progress'))
            self.assertTrue(data['success'])
            self.assertTrue(data['redirect_to'], upload_step('time'))
            redirect_to = data['redirect_to']
            resp, data = self.client.get_html(upload_step('time'))
            self.assertEqual(resp.status_code, 200)
            data = dict(
                csrfmiddlewaretoken=self.client.get_csrf_token(),
                time_attribute='date',
                presentation_strategy='LIST',
            )
            resp = self.client.make_request(redirect_to, data)
            self.assertEqual(resp.status_code, 200)
            resp_js = resp.json()
            if resp_js['success']:
                url = resp_js['redirect_to']

                resp = self.client.make_request(url, data)

                url = resp.json()['url']

                self.assertTrue(
                    url.endswith(layer_name),
                    f'expected url to end with {layer_name}, but got {url}')
                self.assertEqual(resp.status_code, 200)

                url = unquote(url)
                self.check_layer_complete(url, layer_name)
                wms = get_wms(type_name=f'geonode:{layer_name}',
                              username=GEOSERVER_USER,
                              password=GEOSERVER_PASSWD)
                layer_info = list(wms.items())[0][1]
                self.assertEqual(100, len(layer_info.timepositions))
            else:
                self.assertTrue('error_msg' in resp_js)
Exemple #4
0
    def finish_upload(
            self,
            current_step,
            layer_name,
            is_raster=False,
            skip_srs=False):
        if not is_raster and _ALLOW_TIME_STEP:
            resp, data = self.check_and_pass_through_timestep(current_step)
            self.assertEqual(resp.status_code, 200)
            if not isinstance(data, string_types):
                if data['success']:
                    self.assertTrue(
                        data['success'],
                        'expected success but got %s' %
                        data)
                    self.assertTrue('redirect_to' in data)
                    current_step = data['redirect_to']
                    self.wait_for_progress(data.get('progress'))

        if not is_raster and not skip_srs:
            self.assertTrue(upload_step('srs') in current_step)
            # if all is good, the srs step will redirect to the final page
            final_step = current_step.replace('srs', 'final')
            resp = self.client.make_request(final_step)
        else:
            self.assertTrue(
                urlsplit(upload_step('final')).path in current_step,
                f"current_step: {current_step} - upload_step('final'): {upload_step('final')}"
            )
            resp = self.client.get(current_step)

        self.assertEqual(resp.status_code, 200)
        try:
            c = resp.json()
            url = c['url']
            url = unquote(url)
            # and the final page should redirect to the layer page
            # @todo - make the check match completely (endswith at least)
            # currently working around potential 'orphaned' db tables
            self.assertTrue(
                layer_name in url, 'expected %s in URL, got %s' %
                (layer_name, url))
            return url
        except Exception:
            return current_step
Exemple #5
0
 def check_upload_complete(self, layer_name, resp, data):
     """ Makes sure that we got the correct response from an layer
     that can't be uploaded"""
     self.assertTrue(resp.status_code, 200)
     if not isinstance(data, string_types):
         self.assertTrue(data['success'])
         final_step = upload_step("final")
         if "final" in data['redirect_to']:
             self.assertTrue(final_step in data['redirect_to'])
Exemple #6
0
    def test_csv(self):
        """Override the baseclass test and verify a correct CSV upload"""

        csv_file = self.make_csv(['lat', 'lon', 'thing'],
                                 ['-100', '-40', 'foo'])
        layer_name, ext = os.path.splitext(os.path.basename(csv_file))
        resp, form_data = self.client.upload_file(csv_file)
        self.assertEquals(resp.code, 200)
        if not isinstance(form_data, basestring):
            self.check_save_step(resp, form_data)
            csv_step = form_data['redirect_to']
            self.assertTrue(upload_step('csv') in csv_step)
            form_data = dict(lat='lat',
                             lng='lon',
                             csrfmiddlewaretoken=self.client.get_csrf_token())
            resp = self.client.make_request(csv_step, form_data)
            content = json.loads(resp.read())
            self.assertEquals(resp.code, 200)
            self.assertTrue(upload_step('srs') in content['redirect_to'])
Exemple #7
0
    def finish_upload(self,
                      current_step,
                      layer_name,
                      is_raster=False,
                      skip_srs=False):
        if not is_raster and _ALLOW_TIME_STEP:
            resp, data = self.check_and_pass_through_timestep(current_step)
            self.assertEquals(resp.code, 200)
            if not isinstance(data, basestring):
                if data['success']:
                    self.assertTrue(data['success'],
                                    'expected success but got %s' % data)
                    self.assertTrue('redirect_to' in data)
                    current_step = data['redirect_to']
                    self.wait_for_progress(data.get('progress'))

        if not is_raster and not skip_srs:
            self.assertTrue(upload_step('srs') in current_step)
            # if all is good, the srs step will redirect to the final page
            resp = self.client.get(current_step)

            content = json.loads(resp.read())
            if not content.get('url') and content.get(
                    'redirect_to', current_step) == upload_step('final'):
                resp = self.client.get(content.get('redirect_to'))
        else:
            self.assertTrue(upload_step('final') in current_step)
            resp = self.client.get(current_step)

        self.assertEquals(resp.code, 200)
        resp_js = resp.read()
        try:
            c = json.loads(resp_js)
            url = c['url']
            url = urllib.unquote(url)
            # and the final page should redirect to the layer page
            # @todo - make the check match completely (endswith at least)
            # currently working around potential 'orphaned' db tables
            self.assertTrue(layer_name in url,
                            'expected %s in URL, got %s' % (layer_name, url))
            return url
        except BaseException:
            return current_step
Exemple #8
0
 def check_invalid_projection(self, layer_name, resp, data):
     """ Makes sure that we got the correct response from an layer
     that can't be uploaded"""
     self.assertTrue(resp.code, 200)
     if not isinstance(data, basestring):
         self.assertTrue(data['success'])
         self.assertTrue(upload_step("srs") in data['redirect_to'])
         resp, soup = self.client.get_html(data['redirect_to'])
         # grab an h2 and find the name there as part of a message saying it's
         # bad
         h2 = soup.find_all(['h2'])[0]
         self.assertTrue(str(h2).find(layer_name))
Exemple #9
0
    def test_csv(self):
        """Override the baseclass test and verify a correct CSV upload"""

        csv_file = self.make_csv(
            ['lat', 'lon', 'thing'], {'lat': -100, 'lon': -40, 'thing': 'foo'})
        layer_name, ext = os.path.splitext(os.path.basename(csv_file))
        resp, form_data = self.client.upload_file(csv_file)
        self.assertEqual(resp.status_code, 200)
        if not isinstance(form_data, string_types):
            self.check_save_step(resp, form_data)
            csv_step = form_data['redirect_to']
            self.assertTrue(upload_step('csv') in csv_step)
            form_data = dict(
                lat='lat',
                lng='lon',
                csrfmiddlewaretoken=self.client.get_csrf_token())
            resp = self.client.make_request(csv_step, form_data)
            content = resp.json()
            self.assertEqual(resp.status_code, 200)
            self.assertEqual(content['status'], 'incomplete')
Exemple #10
0
    def test_configure_time(self):
        layer_name = 'boxes_with_end_date'
        # make sure it's not there (and configured)
        cascading_delete(layer_name=layer_name, catalog=gs_catalog)

        def get_wms_timepositions():
            alternate_name = 'geonode:%s' % layer_name
            if alternate_name in get_wms().contents:
                metadata = get_wms().contents[alternate_name]
                self.assertTrue(metadata is not None)
                return metadata.timepositions
            else:
                return None

        thefile = os.path.join(
            GOOD_DATA, 'time', '%s.shp' % layer_name
        )
        resp, data = self.client.upload_file(thefile)

        # initial state is no positions or info
        self.assertTrue(get_wms_timepositions() is None)
        self.assertEqual(resp.status_code, 200)

        # enable using interval and single attribute
        if not isinstance(data, string_types):
            self.wait_for_progress(data.get('progress'))
            self.assertTrue(data['success'])
            self.assertTrue(data['redirect_to'], upload_step('time'))
            redirect_to = data['redirect_to']
            resp, data = self.client.get_html(upload_step('time'))
            self.assertEqual(resp.status_code, 200)
            data = dict(csrfmiddlewaretoken=self.client.get_csrf_token(),
                        time_attribute='date',
                        time_end_attribute='enddate',
                        presentation_strategy='LIST',
                        )
            resp = self.client.make_request(redirect_to, data)
            self.assertEqual(resp.status_code, 200)
            resp_js = resp.json()
            if resp_js['success']:
                url = resp_js['redirect_to']

                resp = self.client.make_request(url, data)

                url = resp.json()['url']

                self.assertTrue(
                    url.endswith(layer_name),
                    'expected url to end with %s, but got %s' %
                    (layer_name,
                     url))
                self.assertEqual(resp.status_code, 200)

                url = unquote(url)
                self.check_layer_complete(url, layer_name)
                wms = get_wms(
                    type_name='geonode:%s' % layer_name, username=GEOSERVER_USER, password=GEOSERVER_PASSWD)
                layer_info = list(wms.items())[0][1]
                self.assertEqual(100, len(layer_info.timepositions))
            else:
                self.assertTrue('error_msg' in resp_js)
Exemple #11
0
    def test_configure_time(self):
        dataset_name = 'boxes_with_end_date'
        # make sure it's not there (and configured)
        cascading_delete(dataset_name=dataset_name, catalog=gs_catalog)

        def get_wms_timepositions():
            alternate_name = f'geonode:{dataset_name}'
            if alternate_name in get_wms().contents:
                metadata = get_wms().contents[alternate_name]
                self.assertTrue(metadata is not None)
                return metadata.timepositions
            else:
                return None

        thefile = os.path.join(
            GOOD_DATA, 'time', f'{dataset_name}.shp'
        )
        # Test upload with custom permissions
        resp, data = self.client.upload_file(
            thefile, perms='{"users": {"AnonymousUser": []}, "groups":{}}'
        )
        _dataset = Dataset.objects.get(name=dataset_name)
        _user = get_user_model().objects.get(username='******')
        self.assertEqual(_dataset.get_user_perms(_user).count(), 0)

        # initial state is no positions or info
        self.assertTrue(get_wms_timepositions() is None)
        self.assertEqual(resp.status_code, 200)

        # enable using interval and single attribute
        if not isinstance(data, str):
            # self.wait_for_progress(data.get('progress'))
            self.assertTrue(data['success'])
            self.assertTrue(data['redirect_to'], upload_step('time'))
            redirect_to = data['redirect_to']
            resp, data = self.client.get_html(upload_step('time'))
            self.assertEqual(resp.status_code, 200)
            data = dict(csrfmiddlewaretoken=self.client.get_csrf_token(),
                        time_attribute='date',
                        time_end_attribute='enddate',
                        presentation_strategy='LIST',
                        )
            resp = self.client.make_request(redirect_to, data)
            self.assertEqual(resp.status_code, 200)
            resp_js = resp.json()
            if resp_js['success']:
                url = resp_js['redirect_to']
                resp = self.client.make_request(url, data)
                url = resp.json()['url']
                self.assertTrue(
                    url.endswith(dataset_name),
                    f'expected url to end with {dataset_name}, but got {url}')
                self.assertEqual(resp.status_code, 200)
                url = unquote(url)
                self.check_dataset_complete(url, dataset_name)
                wms = get_wms(
                    type_name=f'geonode:{dataset_name}', username=GEOSERVER_USER, password=GEOSERVER_PASSWD)
                dataset_info = list(wms.items())[0][1]
                self.assertEqual(100, len(dataset_info.timepositions))
            else:
                self.assertTrue('error_msg' in resp_js)