Skip to content

Commit

Permalink
Fix importer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed Feb 2, 2024
1 parent 020cd50 commit a507800
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions docker-compose-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
- geoserver-data-dir:/geoserver_data/data
- data:/data
- tmp:/tmp
- .:/usr/src/importer


# Geoserver backend
Expand Down
4 changes: 2 additions & 2 deletions importer/handlers/common/tests_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_import_with_ogr2ogr_without_errors_should_call_the_right_command(

_open.assert_called_once()
_open.assert_called_with(
f'/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_data\' " "{self.valid_files.get("base_file")}" -nln alternate "dataset"',
f'/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_data\' " ' + self.valid_files.get("base_file") + ' -nln alternate "dataset"',
stdout=-1,
stderr=-1,
shell=True, # noqa
Expand All @@ -252,7 +252,7 @@ def test_import_with_ogr2ogr_with_errors_should_raise_exception(self, _open):

_open.assert_called_once()
_open.assert_called_with(
f'/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_data\' " "{self.valid_files.get("base_file")}" -nln alternate "dataset"',
f'/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_data\' " ' + self.valid_shp.get("base_file") + ' -nln alternate "dataset"',
stdout=-1,
stderr=-1,
shell=True, # noqa
Expand Down
2 changes: 1 addition & 1 deletion importer/handlers/csv/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_import_with_ogr2ogr_without_errors_should_call_the_right_command(

_open.assert_called_once()
_open.assert_called_with(
f'/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_data\' " "{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*"',
f'/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_data\' "' + {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*"',
stdout=-1,
stderr=-1,
shell=True, # noqa
Expand Down
2 changes: 1 addition & 1 deletion importer/handlers/geojson/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_import_with_ogr2ogr_without_errors_should_call_the_right_command(

_open.assert_called_once()
_open.assert_called_with(
f'/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_data\' " "{self.valid_files.get("base_file")}" -nln alternate "dataset" -lco GEOMETRY_NAME=geometry',
f'/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_data\' "' + self.valid_files.get("base_file") + '" -nln alternate "dataset" -lco GEOMETRY_NAME=geometry',
stdout=-1,
stderr=-1,
shell=True, # noqa
Expand Down
2 changes: 1 addition & 1 deletion importer/handlers/gpkg/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_is_valid_should_raise_exception_if_the_gpkg_is_invalid(self):
self.assertIsNotNone(_exc)
print(_exc.exception.detail)
self.assertTrue(
"Layer names must start with a letter, and valid characters are lowercase a-z, numbers or underscores."
"Layer names must start with a letter, and valid characters are lowercase a-z, numbers or underscores"
in str(_exc.exception.detail)
)

Expand Down
2 changes: 1 addition & 1 deletion importer/handlers/shapefile/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_import_with_ogr2ogr_without_errors_should_call_the_right_command(

_open.assert_called_once()
_open.assert_called_with(
f'/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_data\' " "{self.valid_shp.get("base_file")}" -nln alternate "dataset" -lco precision=no -lco GEOMETRY_NAME=geometry ',
f'/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_data\' "' + self.valid_shp.get("base_file") + '" -nln alternate "dataset" -lco precision=no -lco GEOMETRY_NAME=geometry ',
stdout=-1,
stderr=-1,
shell=True, # noqa
Expand Down
7 changes: 5 additions & 2 deletions importer/tests/unit/test_models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import os
from dynamic_models.models import ModelSchema, FieldSchema
import mock
from geonode.base.populate_test_data import create_single_dataset
from importer.models import ResourceHandlerInfo
from importer.tests.utils import TransactionImporterBaseTestSupport

import uuid

class TestModelSchemaSignal(TransactionImporterBaseTestSupport):
databases = ("default", "datastore")

def setUp(self):
self.resource = create_single_dataset(name="test_dataset")
self.resource = create_single_dataset(name=f"test_dataset_{uuid.uuid4()}")
ResourceHandlerInfo.objects.create(
resource=self.resource,
handler_module_path="importer.handlers.shapefile.handler.ShapeFileHandler",
Expand All @@ -22,6 +24,7 @@ def setUp(self):
model_schema=self.dynamic_model,
)

@mock.patch.dict(os.environ, {"IMPORTER_ENABLE_DYN_MODELS": "True"})
def test_delete_dynamic_model(self):
"""
Ensure that the dynamic model is deleted
Expand Down
7 changes: 7 additions & 0 deletions importer/tests/unit/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from importer import project_dir
from importer.publisher import DataPublisher
from unittest.mock import MagicMock
from geonode.geoserver.helpers import create_geoserver_db_featurestore


class TestDataPublisher(TestCase):
Expand Down Expand Up @@ -66,6 +67,12 @@ def test_extract_resource_name_and_crs_return_empty_if_the_file_does_not_exists(

@patch("importer.publisher.create_geoserver_db_featurestore")
def test_get_or_create_store_creation_should_not_be_called(self, datastore):
try:
create_geoserver_db_featurestore(
store_name="geonode_data", workspace=self.workspace.name
)
except:
pass
self.publisher.get_or_create_store()
datastore.assert_not_called()

Expand Down

0 comments on commit a507800

Please sign in to comment.