Skip to content

Commit

Permalink
[Fixes #227] Cleanup not-user code
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed May 3, 2024
1 parent bba1885 commit d082794
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 37 deletions.
1 change: 0 additions & 1 deletion importer/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def create(self, request, *args, **kwargs):
**{"files": files, "handler_module_path": str(handler)},
**extracted_params,
},
legacy_upload_name=_file.name,
action=action,
name=_file.name,
source=extracted_params.get('source'),
Expand Down
6 changes: 0 additions & 6 deletions importer/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from django_celery_results.models import TaskResult
from geonode.base.enumerations import STATE_INVALID, STATE_PROCESSED, STATE_RUNNING
from geonode.resource.models import ExecutionRequest
from geonode.upload.models import Upload
from geonode.storage.manager import storage_manager
from rest_framework import serializers

Expand Down Expand Up @@ -161,7 +160,6 @@ def set_as_failed(self, execution_id, reason=None, delete_file=True):
finished=timezone.now(),
last_updated=timezone.now(),
log=reason,
legacy_status=STATE_INVALID,
)
# delete
if delete_file:
Expand All @@ -185,7 +183,6 @@ def set_as_partially_failed(self, execution_id, reason=None):
finished=timezone.now(),
last_updated=timezone.now(),
log=f"The execution is completed, but the following layers are not imported: \n {', '.join(reason)}. Check the logs for additional infos",
legacy_status=STATE_INVALID,
)

def set_as_completed(self, execution_id):
Expand All @@ -197,7 +194,6 @@ def set_as_completed(self, execution_id):
status=ExecutionRequest.STATUS_FINISHED,
finished=timezone.now(),
last_updated=timezone.now(),
legacy_status=STATE_PROCESSED,
)

def evaluate_execution_progress(
Expand Down Expand Up @@ -292,7 +288,6 @@ def create_execution_request(
step: str,
input_params: dict = {},
resource=None,
legacy_upload_name="",
action=None,
name=None,
source=None,
Expand All @@ -316,7 +311,6 @@ def update_execution_request_status(
self,
execution_id,
status=None,
legacy_status=STATE_RUNNING,
celery_task_request=None,
**kwargs,
):
Expand Down
27 changes: 1 addition & 26 deletions importer/tests/unit/test_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from importer.handlers.base import BaseHandler
from importer.handlers.shapefile.serializer import ShapeFileSerializer
from importer.orchestrator import ImportOrchestrator
from geonode.upload.models import Upload
from django.utils import timezone
from django_celery_results.models import TaskResult

Expand Down Expand Up @@ -96,9 +95,7 @@ def test_create_execution_request(self):
exec_obj = ExecutionRequest.objects.filter(exec_id=exec_id).first()
self.assertEqual(count + 1, ExecutionRequest.objects.count())
self.assertDictEqual(input_files, exec_obj.input_params)
self.assertEqual(exec_obj.STATUS_READY, exec_obj.status)
# check that also the legacy is created
self.assertIsNotNone(Upload.objects.get(metadata__icontains=exec_id))
self.assertEqual(exec_obj.STATUS_READY, exec_obj.status))

@patch("importer.orchestrator.importer_app.tasks.get")
def test_perform_next_step(self, mock_celery):
Expand Down Expand Up @@ -177,7 +174,6 @@ def test_perform_with_error_set_invalid_status(self, mock_celery):
_excec = ExecutionRequest.objects.filter(exec_id=_id).first()
self.assertIsNotNone(_excec)
self.assertEqual(ExecutionRequest.STATUS_FAILED, _excec.status)
self.assertIsNotNone(Upload.objects.get(metadata__icontains=_id))

def test_set_as_failed(self):
# creating the temporary file that will be deleted
Expand All @@ -204,14 +200,8 @@ def test_set_as_failed(self):
self.assertTrue(req.status, ExecutionRequest.STATUS_FAILED)
self.assertTrue(req.log, "automatic test")
self.assertFalse(os.path.exists(fake_path))
# check legacy execution status
legacy = Upload.objects.filter(metadata__contains=_uuid)
self.assertTrue(legacy.exists())
self.assertEqual(legacy.first().state, enum.STATE_INVALID)

# cleanup
req.delete()
legacy.delete()

def test_set_as_completed(self):
# we need to create first the execution
Expand All @@ -231,14 +221,8 @@ def test_set_as_completed(self):
req = ExecutionRequest.objects.get(exec_id=_uuid)
self.assertTrue(req.status, ExecutionRequest.STATUS_FINISHED)

# check legacy execution status
legacy = Upload.objects.filter(metadata__contains=_uuid)
self.assertTrue(legacy.exists())
self.assertEqual(legacy.first().state, enum.STATE_PROCESSED)

# cleanup
req.delete()
legacy.delete()

def test_update_execution_request_status(self):
# we need to create first the execution
Expand All @@ -264,14 +248,8 @@ def test_update_execution_request_status(self):
self.assertTrue(req.func_name, "function_name")
self.assertTrue(req.step, "step_here")

# check legacy execution status
legacy = Upload.objects.filter(metadata__contains=_uuid)
self.assertTrue(legacy.exists())
self.assertEqual(legacy.first().state, enum.STATE_RUNNING)

# cleanup
req.delete()
legacy.delete()

def test_evaluate_execution_progress_should_continue_if_some_task_is_not_finished(
self,
Expand All @@ -283,7 +261,6 @@ def test_evaluate_execution_progress_should_continue_if_some_task_is_not_finishe
user=get_user_model().objects.first(),
func_name="test",
step="test",
legacy_upload_name="test",
)
)

Expand Down Expand Up @@ -319,7 +296,6 @@ def test_evaluate_execution_progress_should_fail_if_one_task_is_failed(self):
user=get_user_model().objects.first(),
func_name="test",
step="test",
legacy_upload_name="test",
)
)

Expand All @@ -344,7 +320,6 @@ def test_evaluate_execution_progress_should_set_as_completed(self):
user=get_user_model().objects.first(),
func_name="test",
step="test",
legacy_upload_name="test",
)
)

Expand Down
4 changes: 0 additions & 4 deletions importer/tests/unit/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def setUp(self):
user=get_user_model().objects.get(username=self.user),
func_name="dummy_func",
step="dummy_step",
legacy_upload_name="dummy",
input_params={
"files": {"base_file": "/filepath"},
# "overwrite_existing_layer": True,
Expand Down Expand Up @@ -81,7 +80,6 @@ def test_import_resource_should_rase_exp_if_is_invalid(
user=get_user_model().objects.get(username=user),
func_name="dummy_func",
step="dummy_step",
legacy_upload_name="dummy",
input_params={"files": "/filepath", "store_spatial_files": True},
)

Expand Down Expand Up @@ -115,7 +113,6 @@ def test_import_resource_should_work(
user=get_user_model().objects.get(username=user),
func_name="dummy_func",
step="dummy_step",
legacy_upload_name="dummy",
input_params={"files": "/filepath", "store_spatial_files": True},
)

Expand Down Expand Up @@ -513,7 +510,6 @@ def setUp(self):
user=get_user_model().objects.get(username=self.user),
func_name="dummy_func",
step="dummy_step",
legacy_upload_name="dummy",
input_params={
"files": {"base_file": "/filepath"},
# "overwrite_existing_layer": True,
Expand Down

0 comments on commit d082794

Please sign in to comment.