Skip to content

Commit

Permalink
Fixes #212 PG_USE_COPY should be optional add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed Nov 10, 2023
1 parent 0fd3c98 commit 25489c1
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions importer/handlers/common/tests_vector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import uuid
from celery.canvas import Signature
from celery import group
Expand Down Expand Up @@ -225,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=\'geonode_data\' host=localhost port=5434 user=\'geonode\' password=\'geonode\' " "{self.valid_files.get("base_file")}" -lco DIM=2 -nln alternate "dataset"',
f'/usr/bin/ogr2ogr --config PG_USE_COPY YES -f PostgreSQL PG:" dbname=\'geonode_data\' host=localhost port=5434 user=\'geonode\' password=\'geonode\' " "{self.valid_files.get("base_file")}" -nln alternate "dataset"',
stdout=-1,
stderr=-1,
shell=True, # noqa
Expand All @@ -251,7 +252,39 @@ 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=\'geonode_data\' host=localhost port=5434 user=\'geonode\' password=\'geonode\' " "{self.valid_files.get("base_file")}" -lco DIM=2 -nln alternate "dataset"',
f'/usr/bin/ogr2ogr --config PG_USE_COPY YES -f PostgreSQL PG:" dbname=\'geonode_data\' host=localhost port=5434 user=\'geonode\' password=\'geonode\' " "{self.valid_files.get("base_file")}" -nln alternate "dataset"',
stdout=-1,
stderr=-1,
shell=True, # noqa
)

@patch.dict(os.environ, {"DISABLE_PG_COPY_OGR2OGR": "True"}, clear=True)
@patch("importer.handlers.common.vector.Popen")
def test_import_with_ogr2ogr_without_errors_should_call_the_right_command_if_copy_is_disabled(
self, _open
):
_uuid = uuid.uuid4()

comm = MagicMock()
comm.communicate.return_value = b"", b""
_open.return_value = comm

_task, alternate, execution_id = import_with_ogr2ogr(
execution_id=str(_uuid),
files=self.valid_files,
original_name="dataset",
handler_module_path=str(self.handler),
ovverwrite_layer=False,
alternate="alternate",
)

self.assertEqual("ogr2ogr", _task)
self.assertEqual(alternate, "alternate")
self.assertEqual(str(_uuid), execution_id)

_open.assert_called_once()
_open.assert_called_with(
f'/usr/bin/ogr2ogr --config PG_USE_COPY NO -f PostgreSQL PG:" dbname=\'geonode_data\' host=localhost port=5434 user=\'geonode\' password=\'geonode\' " "{self.valid_files.get("base_file")}" -nln alternate "dataset"',
stdout=-1,
stderr=-1,
shell=True, # noqa
Expand Down

0 comments on commit 25489c1

Please sign in to comment.