Esempio n. 1
0
 def setUp(self):
     self.files = os.path.join(gisdata.GOOD_DATA, "vector/san_andres_y_providencia_water.shp")
     self.files_as_dict, self.tmpdir = get_files(self.files)
     self.cat = gs_catalog
     self.user = get_user_model().objects.get(username="******")
     self.sut = create_single_layer("san_andres_y_providencia_water.shp")
     self.sut.name = 'san_andres_y_providencia_water'
     self.sut.save()
     self.geoserver_url = settings.GEOSERVER_LOCATION
     self.geoserver_manager = GeoServerResourceManager()
Esempio n. 2
0
class TestGeoServerResourceManager(GeoNodeBaseTestSupport):

    def setUp(self):
        self.files = os.path.join(gisdata.GOOD_DATA, "vector/san_andres_y_providencia_water.shp")
        self.files_as_dict, self.tmpdir = get_files(self.files)
        self.cat = gs_catalog
        self.user = get_user_model().objects.get(username="******")
        self.sut = create_single_layer("san_andres_y_providencia_water.shp")
        self.sut.name = 'san_andres_y_providencia_water'
        self.sut.save()
        self.geoserver_url = settings.GEOSERVER_LOCATION
        self.geoserver_manager = GeoServerResourceManager()

    def tearDown(self) -> None:
        if self.tmpdir:
            shutil.rmtree(self.tmpdir, ignore_errors=True)
        return super().tearDown()

    @on_ogc_backend(geoserver.BACKEND_PACKAGE)
    def test_revise_resource_value_in_append_should_add_expected_rows_in_the_catalog(self):
        layer = Layer.objects.get(name=self.sut.name)
        _gs_import_session_info = self.geoserver_manager._revise_resource_value(layer, list(self.files_as_dict.values()), self.user, action_type="append")
        result = requests.get(f'{self.geoserver_url}/rest/imports/{_gs_import_session_info.import_session.id}')
        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.json().get('import').get('state'), enumerations.STATE_COMPLETE)

    @on_ogc_backend(geoserver.BACKEND_PACKAGE)
    def test_revise_resource_value_in_replace_should_add_expected_rows_in_the_catalog(self):
        layer = Layer.objects.get(name=self.sut.name)
        _gs_import_session_info = self.geoserver_manager._revise_resource_value(layer, list(self.files_as_dict.values()), self.user, action_type="replace")
        result = requests.get(f'{self.geoserver_url}/rest/imports/{_gs_import_session_info.import_session.id}')
        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.json().get('import').get('state'), enumerations.STATE_COMPLETE)

    @on_ogc_backend(geoserver.BACKEND_PACKAGE)
    def test_revise_resource_value_in_replace_should_return_none_for_not_existing_layer(self):
        layer = create_single_layer('fake_layer')
        _gs_import_session_info = self.geoserver_manager._revise_resource_value(layer, list(self.files_as_dict.values()), self.user, action_type="replace")
        self.assertEqual(_gs_import_session_info.import_session.state, enumerations.STATE_PENDING)