diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index b4365123dacb299afda520206df777495aa9723a..b2ade0381a5e9c6de61e6261727de560d888c0c7 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -396,6 +396,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm except ValueError: return search_params + empty_range = start_date and end_date and start_date > end_date + if not start_date and not end_date: return search_params @@ -416,7 +418,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm start_date=start_date, end_date=end_date) enclosing_query = '' - if do_enclosing_query: + if do_enclosing_query and not empty_range: enclosing_query_start = 'extras_temporal_start:[* TO {start_date}]'.format( start_date=start_date) diff --git a/ckanext/odsh/tests/test_search.py b/ckanext/odsh/tests/test_search.py index 99a3a07c344b833896303455727f25d40d2ebb1c..14d61acd23156320211c86bdcf7ca32852716a44 100644 --- a/ckanext/odsh/tests/test_search.py +++ b/ckanext/odsh/tests/test_search.py @@ -52,6 +52,17 @@ class TestSearch(helpers.FunctionalTestBase): # assert assert dataset['name'] in response + @odsh_test() + def test_query_with_end_before_start_finds_no_dataset(self): + # arrange + datasetA = self._create_dataset('dataseta', '1960-01-01', '1960-12-31') + + # act + response = self._perform_date_search('1960-12-30', '1960-02-01') + + # assert + self._assert_no_results(response) + @odsh_test() def test_query_with_wrong_dates_shows_error(self): # arrange