diff --git a/tugboat/tests/tests_unit/test_search_redirect.py b/tugboat/tests/tests_unit/test_search_redirect.py index c99dcc3..999409d 100644 --- a/tugboat/tests/tests_unit/test_search_redirect.py +++ b/tugboat/tests/tests_unit/test_search_redirect.py @@ -92,7 +92,7 @@ def test_authors(self): author_search = view.translate(req) self.assertEqual('q=' + urllib.quote('author:') + '(' + urllib.quote('"Huchra, John" AND "Macri, Lucas M."') + ')' + '&sort=' + urllib.quote('date desc, bibcode desc') + - '&warning_message=' + urllib.quote('author search terms combined with AND rather than OR') + '/', + '&warning_message=' + 'AUTHOR_ANDED_WARNING' + '/', author_search) # authors with or def test_object(self): @@ -235,7 +235,7 @@ def test_database(self): view = ClassicSearchRedirectView() search = view.translate(req) self.assertEqual('q=*:*&sort=' + urllib.quote('date desc, bibcode desc') + - '&error_message=' + urllib.quote('Invalid database from classic GEN') + '/', search) # general only + '&error_message=' + 'UNRECOGNIZABLE_VALUE' + '/', search) # general only def test_article_sel(self): """article_sel to property:article""" @@ -256,7 +256,7 @@ def test_article_sel(self): view = ClassicSearchRedirectView() search = view.translate(req) self.assertEqual('q=*:*' + '&sort=' + urllib.quote('date desc, bibcode desc') + - '&error_message=' + urllib.quote('Invalid value for article_sel: NO') + '/', search) + '&error_message=' + 'UNRECOGNIZABLE_VALUE' + '/', search) def test_data_link(self): """data_link to property:data""" @@ -433,7 +433,7 @@ def test_return_req(self): view = ClassicSearchRedirectView() search = view.translate(req) self.assertTrue('error_message' in search) # unsuppoprted value for return_req - self.assertTrue('form' in search) # unsuppoprted value for return_req + self.assertTrue('UNRECOGNIZABLE_VALUE' in search) # unsuppoprted value for return_req def test_jou_pick(self): """test jou_pick (refereed)""" @@ -478,7 +478,7 @@ def test_jou_pick(self): view = ClassicSearchRedirectView() search = view.translate(req) self.assertTrue('error_message' in search) # invalid value for jou_pick - self.assertTrue('foo' in search) # invalid value for jou_pick + self.assertTrue('UNRECOGNIZABLE_VALUE' in search) # invalid value for jou_pick def test_not_processed(self): """verify parameters that are not processed show up in message to user @@ -564,7 +564,7 @@ def test_data_and(self): view = ClassicSearchRedirectView() search = view.translate(req) self.assertTrue('error_message' in search) # invalid value for data_and - self.assertTrue('foo' in search) # invalid value for data_and + self.assertTrue('UNRECOGNIZABLE_VALUE' in search) # invalid value for data_and def test_article_link(self): """test article_link""" @@ -754,7 +754,7 @@ def test_error_link(self): view = ClassicSearchRedirectView() search = view.translate(req) self.assertEqual('q=*:*' + '&sort=' + urllib.quote('date desc, bibcode desc') + - '&error_message=' + urllib.quote('Invalid value for abstract: foo') + '/', search) + '&error_message=' + 'UNRECOGNIZABLE_VALUE' + '/', search) def test_group_and(self): """test group_and""" @@ -797,21 +797,21 @@ def test_group_and(self): view = ClassicSearchRedirectView() search = view.translate(req) self.assertEqual('q=*:*' + '&sort=' + urllib.quote('date desc, bibcode desc') + - '&error_message=' + urllib.quote('Invalid value for group_and: foo') + '/', search) + '&error_message=' + 'UNRECOGNIZABLE_VALUE' + '/', search) req.args = MultiDict([('group_and', 'YES'), ('group_sel', 'foo')]) req.args.update(self.append_defaults()) view = ClassicSearchRedirectView() search = view.translate(req) self.assertEqual('q=*:*' + '&sort=' + urllib.quote('date desc, bibcode desc') + - '&error_message=' + urllib.quote('Invalid value for group_sel: foo') + '/', search) + '&error_message=' + 'UNRECOGNIZABLE_VALUE' + '/', search) req.args = MultiDict([('group_and', 'YES'), ('group_sel', '')]) req.args.update(self.append_defaults()) view = ClassicSearchRedirectView() search = view.translate(req) self.assertEqual('q=*:*' + '&sort=' + urllib.quote('date desc, bibcode desc') + - '&error_message=' + urllib.quote('Invalid value for group_sel: ') + '/', search) + '&error_message=' + 'UNRECOGNIZABLE_VALUE' + '/', search) def test_sort(self): """test sort""" @@ -835,7 +835,7 @@ def test_sort(self): req.args.update(self.append_defaults()) view = ClassicSearchRedirectView() search = view.translate(req) - self.assertEqual('q=*:*' + '&error_message=' + urllib.quote('Invalid value for sort: foo') + '/', search) + self.assertEqual('q=*:*' + '&error_message=' + 'UNRECOGNIZABLE_VALUE' + '/', search) def test_arxiv_sel(self): """test arxiv_sel""" @@ -855,14 +855,14 @@ def test_arxiv_sel(self): view = ClassicSearchRedirectView() search = view.translate(req) self.assertEqual('q=*:*' + '&sort=' + urllib.quote('date desc, bibcode desc') + \ - '&error_message=' + urllib.quote('Invalid value for arxiv_sel: ') + '/', search) + '&error_message=' + 'UNRECOGNIZABLE_VALUE' + '/', search) req.args = MultiDict([('arxiv_sel', 'ADS')]) req.args.update(self.append_defaults()) view = ClassicSearchRedirectView() search = view.translate(req) self.assertEqual('q=*:*' + '&sort=' + urllib.quote('date desc, bibcode desc') + \ - '&error_message=' + urllib.quote('Invalid value for arxiv_sel: ADS') + '/', search) + '&error_message=' + 'UNRECOGNIZABLE_VALUE' + '/', search) req.args = MultiDict([('arxiv_sel', 'astro-ph'), ('arxiv_sel', 'cond-mat'), ('arxiv_sel', 'cs'), ('arxiv_sel', 'gr-qc'), ('arxiv_sel', 'hep-ex'), ('arxiv_sel', 'hep-lat'), ('arxiv_sel', 'hep-ph'), ('arxiv_sel', 'hep-th'), diff --git a/tugboat/views.py b/tugboat/views.py index d8be639..1ccd9f2 100644 --- a/tugboat/views.py +++ b/tugboat/views.py @@ -355,7 +355,7 @@ def translate_authors(self, args): self.translation.search.append('AND') self.translation.search.append(search) if len(authors) > 1 and logic == 'OR': - self.translation.warning_message.append(urllib.quote('author search terms combined with AND rather than OR')) + self.translation.warning_message.append(urllib.quote('AUTHOR_ANDED_WARNING')) def translate_simple(self, args, classic_param, bbb_param): """process easy to translate fields like title @@ -472,7 +472,7 @@ def translate_entry_date_start(self, args): date = sum(d > 0 for d in [start_year,start_month,start_day]) offset = sum(d < 0 for d in [start_year,start_month,start_day]) if date > 0 and offset > 0: - self.translation.error_message.append('can not combine a date and offset (negative value) for the Entry Date') + self.translation.error_message.append('ENTRY_DATE_OFFSET_ERROR') return None # if offset has been specified, get current date, subtract the offset, turn into string and return if offset > 0: @@ -487,7 +487,7 @@ def translate_entry_date_start(self, args): start_day = start_day if start_day != 0 else 1 return '{:04d}-{:02d}-{:02d}'.format(start_year, start_month, start_day) except: - self.translation.error_message.append('found a non numeric value in the Entry Date') + self.translation.error_message.append('ENTRY_DATE_NON_NUMERIC_ERROR') return None def translate_entry_date_end(self, args): @@ -514,7 +514,7 @@ def translate_entry_date_end(self, args): date = sum(d > 0 for d in [end_year,end_month,end_day]) offset = sum(d < 0 for d in [end_year,end_month,end_day]) if date > 0 and offset > 0: - self.translation.error_message.append('can not combine a date and offset (negative value) for the Entry Date') + self.translation.error_message.append('ENTRY_DATE_OFFSET_ERROR') return None # if offset has been specified, get current date, subtract the offset, turn into string and return if offset > 0: @@ -535,7 +535,7 @@ def translate_entry_date_end(self, args): (datetime.now().day if end_year == datetime.now().year else calendar.monthrange(end_year, end_month)[1]) return '{:04d}-{:02d}-{:02d}'.format(end_year, end_month, end_day) except: - self.translation.error_message.append('found a non numeric value in the Entry Date') + self.translation.error_message.append('ENTRY_DATE_NON_NUMERIC_ERROR') return None def translate_entry_date(self, args): @@ -607,7 +607,7 @@ def translate_database(self, args): '&fq_database=(' + urllib.quote(db_key) + ')') else: # unrecognizable value - self.translation.error_message.append(urllib.quote('Invalid database from classic {}'.format(value))) + self.translation.error_message.append('UNRECOGNIZABLE_VALUE') def translate_results_subset(self, args): """subset/pagination currently not supported by bumblebee @@ -649,7 +649,7 @@ def translate_jou_pick(self, args): self.translation.filter.append(urllib.quote('{') + '!' + urllib.quote('type=aqp v=$fq_property}') + \ '&fq_property=(' + urllib.quote('property:("not refereed")') + ')') else: - self.translation.error_message.append(urllib.quote('Invalid value for jou_pick: {}'.format(jou_pick))) + self.translation.error_message.append('UNRECOGNIZABLE_VALUE') def translate_data_entries(self, args): """ Convert all classic data entries search related parameters to ads/bumblebee """ @@ -691,7 +691,7 @@ def translate_data_entries(self, args): search.append(urllib.quote(BBB)) else: # unrecognizable value - self.translation.error_message.append(urllib.quote('Invalid value for {}: {}'.format(classic, value))) + self.translation.error_message.append('UNRECOGNIZABLE_VALUE') if len(search) == 1: self.translation.search.append(''.join(search)) elif len(search) > 1: @@ -716,7 +716,7 @@ def translate_data_and(self, args): operator = 'NOT' else: operator = None - self.translation.error_message.append(urllib.quote('Invalid value for data_and: {}'.format(data_and))) + self.translation.error_message.append('UNRECOGNIZABLE_VALUE') return operator def validate_group_sel(self, group_sel): @@ -759,7 +759,7 @@ def translate_group_sel(self, args): '&fq_bibgroup_facet=(' + urllib.quote_plus('bibgroup_facet:({})'.format(group_sel)) + ')') else: # unrecognizable value - self.translation.error_message.append(urllib.quote('Invalid value for group_sel: {}'.format(value))) + self.translation.error_message.append('UNRECOGNIZABLE_VALUE') def translate_group_and(self, args): """ set group entries operator """ @@ -777,7 +777,7 @@ def translate_group_and(self, args): operator = 'AND' else: operator = None - self.translation.error_message.append(urllib.quote('Invalid value for group_and: {}'.format(group_and))) + self.translation.error_message.append('UNRECOGNIZABLE_VALUE') return operator def translate_return_req(self, args): @@ -792,7 +792,7 @@ def translate_return_req(self, args): elif return_req == 'result': pass else: - self.translation.error_message.append(urllib.quote('Invalid value for return_req({}), should be "result"'.format(return_req))) + self.translation.error_message.append('UNRECOGNIZABLE_VALUE') def translate_article_sel(self, args): article_sel = args.pop('article_sel', None) @@ -812,7 +812,7 @@ def translate_article_sel(self, args): self.translation.filter.append(urllib.quote('{') + '!' + urllib.quote('type=aqp v=$fq_doctype}') + \ '&fq_doctype=(' + urllib.quote_plus('doctype_facet_hier:"0/Article"') + ')') else: - self.translation.error_message.append(urllib.quote('Invalid value for article_sel: {}'.format(article_sel))) + self.translation.error_message.append('UNRECOGNIZABLE_VALUE') def translate_qsearch(self, args): """translate qsearch parameter from single input form on classic_w_BBB_button.html @@ -866,7 +866,7 @@ def translate_sort(self, args): return # unrecognizable value - self.translation.error_message.append(urllib.quote('Invalid value for sort: {}'.format(value))) + self.translation.error_message.append('UNRECOGNIZABLE_VALUE') def translate_to_ignore(self, args): """ remove the fields that is being ignored in some cases an unprocessed message is issued """ @@ -1032,7 +1032,7 @@ def translate_arxiv_sel(self, args): self.translation.search.append('keyword:(' + urllib.quote(arxiv_sel) + ')') else: # unrecognizable value - self.translation.error_message.append(urllib.quote('Invalid value for arxiv_sel: {}'.format(value))) + self.translation.error_message.append('UNRECOGNIZABLE_VALUE') def translate_ref_stems(self, args): """