Skip to content

Commit

Permalink
feat(tests): added new test;
Browse files Browse the repository at this point in the history
- Added new test for should remove unsupported resources from datastore.
  • Loading branch information
JVickery-TBS committed Jan 31, 2024
1 parent 27a7e3b commit 407db19
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions ckanext/xloader/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
from six import text_type as str
from ckan.tests import helpers, factories
from ckan.logic import _actions
from ckanext.xloader.plugin import _should_remove_unsupported_resource_from_datastore


@pytest.fixture
def mock_toolkit_config(request):
with mock.patch('ckan.plugins.toolkit.config.get') as mock_get:
mock_get.return_value = request.param
yield mock_get


@pytest.fixture
def mock_xloader_formats(request):
with mock.patch('ckanext.xloader.utils.XLoaderFormats.is_it_an_xloader_format') as mock_is_xloader_format:
mock_is_xloader_format.return_value = request.param
yield mock_is_xloader_format


@pytest.mark.usefixtures("clean_db", "with_plugins")
Expand Down Expand Up @@ -58,6 +73,51 @@ def test_submit_when_url_changes(self, monkeypatch):

assert func.called

@pytest.mark.parametrize("toolkit_config_value, xloader_formats_value, url_type, datastore_active, expected_result",
[(True, True, 'upload', True, True), # Test1
(True, False, 'upload', True, False), # Test2
(False, True, 'upload', True, False), # Test3
(False, False, 'upload', True, False), # Test4
(True, True, 'custom_type', True, False), # Test5
(True, True, 'upload', False, False), # Test6
(True, True, '', True, True), # Test7
(True, True, None, True, True), # Test8
])
def test_should_remove_unsupported_resource_from_datastore(
mock_toolkit_config, mock_xloader_formats, toolkit_config_value,
xloader_formats_value, url_type, datastore_active, expected_result):

# Test1: clean_datastore_tables=True, is_it_an_xloader_format=True, url_type='upload', datastore_active=True, expected_result=True
# Should pass as it is an Xloader format and supported url type and datastore active.
# Test2: clean_datastore_tables=True, is_it_an_xloader_format=False, url_type='upload', datastore_active=True, expected_result=False
# Should fail as it is not a supported Xloader format.
# Test3: clean_datastore_tables=False, is_it_an_xloader_format=True, url_type='upload', datastore_active=True, expected_result=False
# Should fail as the config option is turned off.
# Test4: clean_datastore_tables=False, is_it_an_xloader_format=False, url_type='upload', datastore_active=True, expected_result=False
# Should fail as the config option is turned off and the Xloader format is not supported.
# Test5: clean_datastore_tables=True, is_it_an_xloader_format=True, url_type='custom_type', datastore_active=True, expected_result=False
# Should fail as the url_type is not supported.
# Test6: clean_datastore_tables=True, is_it_an_xloader_format=True, url_type='upload', datastore_active=False, expected_result=False
# Should fail as datastore is inactive.
# Test7: clean_datastore_tables=True, is_it_an_xloader_format=True, url_type='', datastore_active=True, expected_result=True
# Should pass as it is an Xloader format and supported url type and datastore active.
# Test8: clean_datastore_tables=True, is_it_an_xloader_format=True, url_type=None, datastore_active=True, expected_result=True
# Should pass as it is an Xloader format and supported url type as falsy and datastore active.

# Setup mock data
res_dict = {
'format': 'some_format',
'url_type': url_type,
'datastore_active': True,
'extras': {'datastore_active': True}
}

# Call the function
result = _should_remove_unsupported_resource_from_datastore(res_dict)

# Assert the result based on the logic paths covered
assert result == expected_result

def _pending_task(self, resource_id):
return {
"entity_id": resource_id,
Expand Down

0 comments on commit 407db19

Please sign in to comment.