Skip to content

Commit

Permalink
[Fixes #12368] Fix build and broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed Oct 15, 2024
1 parent d35699e commit c072c87
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
2 changes: 1 addition & 1 deletion geonode/assets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
16 changes: 14 additions & 2 deletions geonode/upload/handlers/common/tests_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion geonode/upload/handlers/csv/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion geonode/upload/handlers/geojson/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion geonode/upload/handlers/shapefile/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 20 additions & 8 deletions geonode/upload/tests/end2end/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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"),
}
Expand All @@ -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)
Expand Down

0 comments on commit c072c87

Please sign in to comment.