From f952b881f427872546eb181d1ae40464212e881d Mon Sep 17 00:00:00 2001 From: anonymous <anonymous> Date: Tue, 5 Feb 2019 16:12:04 +0100 Subject: [PATCH] fix empy serach range query --- ckanext/odsh/plugin.py | 4 +++- ckanext/odsh/tests/test_search.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index b4365123..b2ade038 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 99a3a07c..14d61acd 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 -- GitLab