Skip to content

Commit

Permalink
[Fixes #257] Fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed Jul 23, 2024
1 parent 2ea6bb5 commit a2665e7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
13 changes: 13 additions & 0 deletions importer/handlers/common/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from importer.api.exception import ImportException
from importer.handlers.common.remote import BaseRemoteResourceHandler
from django.contrib.auth import get_user_model
from importer.handlers.common.serializer import RemoteResourceSerializer
from importer.orchestrator import orchestrator
from geonode.base.populate_test_data import create_single_dataset
from geonode.resource.models import ExecutionRequest
Expand Down Expand Up @@ -32,6 +33,18 @@ def setUpClass(cls):
name="stazioni_metropolitana", owner=cls.owner
)

def test_can_handle_should_return_true_for_remote(self):
actual = self.handler.can_handle(self.valid_files)
self.assertTrue(actual)

def test_can_handle_should_return_false_for_other_files(self):
actual = self.handler.can_handle({"base_file": "random.file"})
self.assertFalse(actual)

def test_should_get_the_specific_serializer(self):
actual = self.handler.has_serializer(self.valid_files)
self.assertEqual(type(actual), type(RemoteResourceSerializer))

def test_create_error_log(self):
"""
Should return the formatted way for the log of the handler
Expand Down
55 changes: 55 additions & 0 deletions importer/tests/unit/test_dastore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
from django.test import TestCase
from mock import patch
from importer import project_dir
from importer.orchestrator import orchestrator
from importer.datastore import DataStoreManager
from importer.publisher import DataPublisher
from unittest.mock import MagicMock
from django.contrib.auth import get_user_model

class TestDataStoreManager(TestCase):
"""
"""

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.files = {"base_file": f"{project_dir}/tests/fixture/valid.gpkg"}

def setUp(self):
self.user = get_user_model().objects.first()
execution_id = orchestrator.create_execution_request(
user=self.user,
func_name="create",
step="create",
action="import",
input_params={
**{"handler_module_path": "importer.handlers.gpkg.handler.GPKGFileHandler"},
},
source="importer_copy",
)
self.datastore = DataStoreManager(
self.files, "importer.handlers.gpkg.handler.GPKGFileHandler", self.user, execution_id
)

execution_id_url = orchestrator.create_execution_request(
user=self.user,
func_name="create",
step="create",
action="import",
input_params={
"url": "https://geosolutionsgroup.com"
},
source="importer_copy",
)
self.datastore_url = DataStoreManager(
self.files, "importer.handlers.common.remote.BaseRemoteResourceHandler", self.user, execution_id_url
)
self.gpkg_path = f"{project_dir}/tests/fixture/valid.gpkg"

def test_input_is_valid_with_files(self):
self.assertTrue(self.datastore.input_is_valid())

def test_input_is_valid_with_urls(self):
self.assertTrue(self.datastore_url.input_is_valid())

0 comments on commit a2665e7

Please sign in to comment.