From c072c87d46a0eb82f9b59fbe7fb8ede9dfd99a95 Mon Sep 17 00:00:00 2001 From: Mattia Date: Tue, 15 Oct 2024 15:19:37 +0200 Subject: [PATCH] [Fixes #12368] Fix build and broken tests --- geonode/assets/tests.py | 2 +- .../upload/handlers/common/tests_vector.py | 16 +++++++++-- geonode/upload/handlers/csv/tests.py | 8 +++++- geonode/upload/handlers/geojson/tests.py | 8 +++++- geonode/upload/handlers/shapefile/tests.py | 8 +++++- geonode/upload/tests/end2end/test_end2end.py | 28 +++++++++++++------ 6 files changed, 56 insertions(+), 14 deletions(-) diff --git a/geonode/assets/tests.py b/geonode/assets/tests.py index ccd5a0e6f61..6725db5cf80 100644 --- a/geonode/assets/tests.py +++ b/geonode/assets/tests.py @@ -238,7 +238,7 @@ def test_download_file(self): asset.save() self.assertIsInstance(asset, LocalAsset) - reloaded = Asset.objects.get(pk=asset.pk) + reloaded = LocalAsset.objects.get(pk=asset.pk) # put two more files in the asset dir asset_dir = os.path.dirname(reloaded.location[0]) diff --git a/geonode/upload/handlers/common/tests_vector.py b/geonode/upload/handlers/common/tests_vector.py index 9564935eecd..bf99e062f7c 100644 --- a/geonode/upload/handlers/common/tests_vector.py +++ b/geonode/upload/handlers/common/tests_vector.py @@ -21,6 +21,7 @@ import uuid from celery.canvas import Signature from celery import group +from django.conf import settings from django.test import TestCase from mock import MagicMock, patch from geonode.upload.handlers.common.vector import BaseVectorFileHandler, import_with_ogr2ogr @@ -238,11 +239,16 @@ def test_import_with_ogr2ogr_without_errors_should_call_the_right_command(self, self.assertEqual(alternate, "alternate") self.assertEqual(str(_uuid), execution_id) + _datastore = settings.DATABASES["datastore"] _open.assert_called_once() _open.assert_called_with( "/usr/bin/ogr2ogr --config PG_USE_COPY YES -f PostgreSQL PG:\" dbname='test_geonode_data' host=" + os.getenv("DATABASE_HOST", "localhost") - + " port=5432 user='geonode_data' password='geonode' \" \"" + + " port=5432 user='" + + _datastore["USER"] + + "' password='" + + _datastore["PASSWORD"] + + '\' " "' + self.valid_files.get("base_file") + '" -nln alternate "dataset"', stdout=-1, @@ -268,11 +274,17 @@ def test_import_with_ogr2ogr_with_errors_should_raise_exception(self, _open): alternate="alternate", ) + _datastore = settings.DATABASES["datastore"] + _open.assert_called_once() _open.assert_called_with( "/usr/bin/ogr2ogr --config PG_USE_COPY YES -f PostgreSQL PG:\" dbname='test_geonode_data' host=" + os.getenv("DATABASE_HOST", "localhost") - + " port=5432 user='geonode_data' password='geonode' \" \"" + + " port=5432 user='" + + _datastore["USER"] + + "' password='" + + _datastore["PASSWORD"] + + '\' " "' + self.valid_files.get("base_file") + '" -nln alternate "dataset"', stdout=-1, diff --git a/geonode/upload/handlers/csv/tests.py b/geonode/upload/handlers/csv/tests.py index 21ad69f6b41..dc75996bef4 100644 --- a/geonode/upload/handlers/csv/tests.py +++ b/geonode/upload/handlers/csv/tests.py @@ -19,6 +19,7 @@ import uuid from unittest.mock import MagicMock, patch import os +from django.conf import settings from django.contrib.auth import get_user_model from django.test import TestCase from geonode.base.populate_test_data import create_single_dataset @@ -163,11 +164,16 @@ def test_import_with_ogr2ogr_without_errors_should_call_the_right_command(self, self.assertEqual(alternate, "alternate") self.assertEqual(str(_uuid), execution_id) + _datastore = settings.DATABASES["datastore"] _open.assert_called_once() _open.assert_called_with( "/usr/bin/ogr2ogr --config PG_USE_COPY YES -f PostgreSQL PG:\" dbname='test_geonode_data' host=" + os.getenv("DATABASE_HOST", "localhost") - + " port=5432 user='geonode_data' password='geonode' \" \"" + + " port=5432 user='" + + _datastore["USER"] + + "' password='" + + _datastore["PASSWORD"] + + '\' " "' + self.valid_csv + '" -nln alternate "dataset" -oo KEEP_GEOM_COLUMNS=NO -lco GEOMETRY_NAME=geometry -oo "GEOM_POSSIBLE_NAMES=geom*,the_geom*,wkt_geom" -oo "X_POSSIBLE_NAMES=x,long*" -oo "Y_POSSIBLE_NAMES=y,lat*"', # noqa stdout=-1, diff --git a/geonode/upload/handlers/geojson/tests.py b/geonode/upload/handlers/geojson/tests.py index 4b56f0a98b3..acf5913e74e 100644 --- a/geonode/upload/handlers/geojson/tests.py +++ b/geonode/upload/handlers/geojson/tests.py @@ -18,6 +18,7 @@ ######################################################################### import uuid import os +from django.conf import settings from django.test import TestCase from mock import MagicMock, patch from geonode.upload.handlers.common.vector import import_with_ogr2ogr @@ -132,11 +133,16 @@ def test_import_with_ogr2ogr_without_errors_should_call_the_right_command(self, self.assertEqual(alternate, "alternate") self.assertEqual(str(_uuid), execution_id) + _datastore = settings.DATABASES["datastore"] _open.assert_called_once() _open.assert_called_with( "/usr/bin/ogr2ogr --config PG_USE_COPY YES -f PostgreSQL PG:\" dbname='test_geonode_data' host=" + os.getenv("DATABASE_HOST", "localhost") - + " port=5432 user='geonode_data' password='geonode' \" \"" + + " port=5432 user='" + + _datastore["USER"] + + "' password='" + + _datastore["PASSWORD"] + + '\' " "' + self.valid_files.get("base_file") + '" -nln alternate "dataset" -lco GEOMETRY_NAME=geometry', stdout=-1, diff --git a/geonode/upload/handlers/shapefile/tests.py b/geonode/upload/handlers/shapefile/tests.py index 560b42ed2bc..f643306bf7e 100644 --- a/geonode/upload/handlers/shapefile/tests.py +++ b/geonode/upload/handlers/shapefile/tests.py @@ -19,6 +19,7 @@ import os import uuid +from django.conf import settings import gisdata from django.contrib.auth import get_user_model from django.test import TestCase @@ -159,11 +160,16 @@ def test_import_with_ogr2ogr_without_errors_should_call_the_right_command(self, self.assertEqual(alternate, "alternate") self.assertEqual(str(_uuid), execution_id) + _datastore = settings.DATABASES["datastore"] _open.assert_called_once() _open.assert_called_with( "/usr/bin/ogr2ogr --config PG_USE_COPY YES -f PostgreSQL PG:\" dbname='test_geonode_data' host=" + os.getenv("DATABASE_HOST", "localhost") - + " port=5432 user='geonode_data' password='geonode' \" \"" + + " port=5432 user='" + + _datastore["USER"] + + "' password='" + + _datastore["PASSWORD"] + + '\' " "' + self.valid_shp.get("base_file") + '" -nln alternate "dataset" -lco precision=no -lco GEOMETRY_NAME=geometry ', stdout=-1, diff --git a/geonode/upload/tests/end2end/test_end2end.py b/geonode/upload/tests/end2end/test_end2end.py index a2ad76cfd9a..21e646a562a 100644 --- a/geonode/upload/tests/end2end/test_end2end.py +++ b/geonode/upload/tests/end2end/test_end2end.py @@ -187,13 +187,16 @@ def test_import_geopackage(self): @mock.patch.dict(os.environ, {"GEONODE_GEODATABASE": "test_geonode_data"}) @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_import_gpkg_overwrite(self): - prev_dataset = create_single_dataset(name="stazioni_metropolitana") self._cleanup_layers(name="stazioni_metropolitana") + initial_name = "stazioni_metropolitana" + payload = { + "base_file": open(self.valid_gkpg, "rb"), + } + prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) payload = { "base_file": open(self.valid_gkpg, "rb"), } - initial_name = "stazioni_metropolitana" payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk self._assertimport(payload, initial_name, overwrite=True, last_update=prev_dataset.last_updated) @@ -270,13 +273,15 @@ def test_import_geojson(self): @mock.patch.dict(os.environ, {"GEONODE_GEODATABASE": "test_geonode_data"}) @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_import_geojson_overwrite(self): - prev_dataset = create_single_dataset(name="valid") - self._cleanup_layers(name="valid") payload = { "base_file": open(self.valid_geojson, "rb"), } initial_name = "valid" + prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) + payload = { + "base_file": open(self.valid_geojson, "rb"), + } payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk self._assertimport(payload, initial_name, overwrite=True, last_update=prev_dataset.last_updated) @@ -300,9 +305,13 @@ def test_import_geojson(self): @mock.patch.dict(os.environ, {"GEONODE_GEODATABASE": "test_geonode_data"}) @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_import_csv_overwrite(self): - prev_dataset = create_single_dataset(name="valid") - self._cleanup_layers(name="valid") + payload = { + "base_file": open(self.valid_csv, "rb"), + } + initial_name = "valid" + prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) + payload = { "base_file": open(self.valid_csv, "rb"), } @@ -328,14 +337,17 @@ def test_import_kml(self): @mock.patch.dict(os.environ, {"GEONODE_GEODATABASE": "test_geonode_data"}) @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_import_kml_overwrite(self): - prev_dataset = create_single_dataset(name="sample_point_dataset") + initial_name = "sample_point_dataset" self._cleanup_layers(name="sample_point_dataset") + payload = { + "base_file": open(self.valid_kml, "rb"), + } + prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) payload = { "base_file": open(self.valid_kml, "rb"), } - initial_name = "sample_point_dataset" payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk self._assertimport(payload, initial_name, overwrite=True, last_update=prev_dataset.last_updated)