From 02f38dc4fe0e785fbd65bb2107b02a9ea8ce7bb0 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Wed, 8 Nov 2023 17:04:19 +0100 Subject: [PATCH] Revert "blacked" This reverts commit 6e049d57a8f1f1275f9a246db23ae2fa0c951dd6. --- src/rer/solrpush/adapters/file.py | 3 +- src/rer/solrpush/adapters/rss_feed.py | 1 + src/rer/solrpush/behaviors/solr_fields.py | 10 +- src/rer/solrpush/browser/controlpanel.py | 16 +-- src/rer/solrpush/browser/elevate_settings.py | 6 +- src/rer/solrpush/browser/maintenance.py | 17 ++- src/rer/solrpush/browser/querybuilder.py | 2 +- src/rer/solrpush/indexer.py | 6 +- src/rer/solrpush/interfaces/elevate.py | 14 +- src/rer/solrpush/interfaces/settings.py | 134 +++++++++--------- .../restapi/services/solr_search/batch.py | 6 +- src/rer/solrpush/testing.py | 6 +- src/rer/solrpush/tests/test_behaviors.py | 2 +- src/rer/solrpush/tests/test_elevate.py | 16 +-- src/rer/solrpush/tests/test_events.py | 4 +- src/rer/solrpush/tests/test_image_tags.py | 10 +- src/rer/solrpush/tests/test_maintenance.py | 10 +- src/rer/solrpush/tests/test_querybuilder.py | 8 +- src/rer/solrpush/tests/test_restapi_search.py | 17 ++- src/rer/solrpush/tests/test_search.py | 14 +- src/rer/solrpush/tests/test_setup.py | 1 + src/rer/solrpush/tests/test_solr_interface.py | 4 +- src/rer/solrpush/tests/test_tika.py | 10 +- src/rer/solrpush/utils/solr_indexer.py | 2 +- src/rer/solrpush/utils/solr_search.py | 9 +- 25 files changed, 170 insertions(+), 158 deletions(-) diff --git a/src/rer/solrpush/adapters/file.py b/src/rer/solrpush/adapters/file.py index 7185f29..6482241 100644 --- a/src/rer/solrpush/adapters/file.py +++ b/src/rer/solrpush/adapters/file.py @@ -34,7 +34,8 @@ def maxfilesize(self): return max_size * 1024 * 1024 def get_file_to_index(self): - """ """ + """ + """ file_obj = getattr(self.context, "file", None) if not file_obj: return None diff --git a/src/rer/solrpush/adapters/rss_feed.py b/src/rer/solrpush/adapters/rss_feed.py index bdac8b9..9b503ec 100644 --- a/src/rer/solrpush/adapters/rss_feed.py +++ b/src/rer/solrpush/adapters/rss_feed.py @@ -10,6 +10,7 @@ @implementer(IFeedItem) @adapter(ISolrBrain, IFeed) class SOLRFeedItem(BaseItem): + @property def link(self): return self.context.getURL() diff --git a/src/rer/solrpush/behaviors/solr_fields.py b/src/rer/solrpush/behaviors/solr_fields.py index 7436cc0..6638b57 100644 --- a/src/rer/solrpush/behaviors/solr_fields.py +++ b/src/rer/solrpush/behaviors/solr_fields.py @@ -19,7 +19,7 @@ class ISolrFields(model.Schema): required=False, default=True, missing_value=True, - title=_("label_showinsearch", default="Show in search"), + title=_("label_showinsearch", default=u"Show in search"), description=_("help_showinsearch", default=""), ) @@ -27,13 +27,13 @@ class ISolrFields(model.Schema): required=False, default=[], missing_value=[], - title=_("label_searchwords", default="Search words"), + title=_("label_searchwords", default=u"Search words"), value_type=schema.TextLine(), description=_( "help_searchwords", - "Specify words for which this item will show up " - "as the first search result. Multiple words can be " - "specified on new lines.", + u"Specify words for which this item will show up " + u"as the first search result. Multiple words can be " + u"specified on new lines.", ), ) diff --git a/src/rer/solrpush/browser/controlpanel.py b/src/rer/solrpush/browser/controlpanel.py index 5ca7ca5..1753c68 100644 --- a/src/rer/solrpush/browser/controlpanel.py +++ b/src/rer/solrpush/browser/controlpanel.py @@ -19,15 +19,15 @@ class FormDefault(group.Group): - label = _("settings_default_label", default="Settings") + label = _("settings_default_label", default=u"Settings") fields = field.Fields(IRerSolrpushConf) class FormSearch(group.Group): - label = _("settings_search_label", default="Search") + label = _("settings_search_label", default=u"Search") description = _( "settings_search_help", - default="Use these settings to tweak search results.", + default=u"Use these settings to tweak search results.", ) fields = field.Fields(IRerSolrpushSearchConf) @@ -39,11 +39,11 @@ class RerSolrpushEditForm(RegistryEditForm): schema = IRerSolrpushSettings groups = (FormDefault, FormSearch) - label = _("Solr Push Configuration") + label = _(u"Solr Push Configuration") formErrorsMessage = _( "settings_form_error", - default="Sono presenti degli errori, si prega di ricontrollare i dati inseriti", + default=u"Sono presenti degli errori, si prega di ricontrollare i dati inseriti", ) def updateFields(self): @@ -59,7 +59,7 @@ def handleSave(self, action): self.status = self.formErrorsMessage return self.applyChanges(data) - api.portal.show_message(_("Changes saved."), request=self.request) + api.portal.show_message(_(u"Changes saved."), request=self.request) init_error = init_solr_push() if init_error: api.portal.show_message( @@ -67,7 +67,7 @@ def handleSave(self, action): ) else: api.portal.show_message( - _("Loaded schema.xml from SOLR"), request=self.request + _(u"Loaded schema.xml from SOLR"), request=self.request ) self.request.response.redirect(self.request.getURL()) @@ -86,7 +86,7 @@ def handleReload(self, action): ) else: api.portal.show_message( - _("Reloaded schema.xml from SOLR"), request=self.request + _(u"Reloaded schema.xml from SOLR"), request=self.request ) self.request.response.redirect(self.request.getURL()) diff --git a/src/rer/solrpush/browser/elevate_settings.py b/src/rer/solrpush/browser/elevate_settings.py index b2ca8f8..4ff31ec 100644 --- a/src/rer/solrpush/browser/elevate_settings.py +++ b/src/rer/solrpush/browser/elevate_settings.py @@ -10,17 +10,19 @@ class ElevateSettingsEditForm(RegistryEditForm): + schema = IElevateSettings label = _( "solr_elevate_configuration_label", - default="Solr Push Elevate Configuration", + default=u"Solr Push Elevate Configuration", ) fields = field.Fields(IElevateSettings) fields["elevate_schema"].widgetFactory = JSONFieldWidget def updateWidgets(self): - """ """ + """ + """ super(ElevateSettingsEditForm, self).updateWidgets() self.widgets["elevate_schema"].schema = IElevateRowSchema diff --git a/src/rer/solrpush/browser/maintenance.py b/src/rer/solrpush/browser/maintenance.py index 97aec40..1dd1843 100644 --- a/src/rer/solrpush/browser/maintenance.py +++ b/src/rer/solrpush/browser/maintenance.py @@ -45,7 +45,7 @@ def timer(func=time): - """set up a generator returning the elapsed time since the last call""" + """ set up a generator returning the elapsed time since the last call """ def gen(last=func()): while True: @@ -57,11 +57,12 @@ def gen(last=func()): class SolrMaintenanceBaseForm(form.Form): + # template = ViewPageTemplateFile('templates/reindex_solr.pt') ignoreContext = True - @button.buttonAndHandler(_("start_label", default="Start")) + @button.buttonAndHandler(_("start_label", default=u"Start")) def handleApply(self, action): data, errors = self.extractData() if errors: @@ -69,7 +70,7 @@ def handleApply(self, action): return self.do_action() - @button.buttonAndHandler(_("cancel_label", default="Cancel")) + @button.buttonAndHandler(_("cancel_label", default=u"Cancel")) def handleCancel(self, action): msg_label = _("maintenance_cancel_action", default="Action cancelled") api.portal.show_message(message=msg_label, request=self.request) @@ -107,8 +108,8 @@ def solr_error_message(self): return translate( _( "solr_error_connection", - default="There have been problems connecting to SOLR. " - "Contact site administrator.", + default=u"There have been problems connecting to SOLR. " + u"Contact site administrator.", ), context=self.request, ) @@ -364,7 +365,7 @@ def sync_contents( class DoReindexView(ReindexBaseView): def __call__(self): authenticator = getMultiAdapter( - (self.context, self.request), name="authenticator" + (self.context, self.request), name=u"authenticator" ) if not authenticator.verify(): raise Unauthorized @@ -386,7 +387,7 @@ class DoSyncView(ReindexBaseView): def __call__(self, cron_view=False): if not cron_view: authenticator = getMultiAdapter( - (self.context, self.request), name="authenticator" + (self.context, self.request), name=u"authenticator" ) if not authenticator.verify(): raise Unauthorized @@ -456,6 +457,7 @@ def is_active(self): class ReindexSolrView(ReactView): + label = _("maintenance_reindex_label", default="Reindex SOLR") description = _( "maintenance_reindex_help", @@ -465,6 +467,7 @@ class ReindexSolrView(ReactView): class SyncSolrView(ReactView): + label = _("maintenance_sync_label", default="Sync SOLR") description = _( "maintenance_sync_help", diff --git a/src/rer/solrpush/browser/querybuilder.py b/src/rer/solrpush/browser/querybuilder.py index ce62794..06a1188 100644 --- a/src/rer/solrpush/browser/querybuilder.py +++ b/src/rer/solrpush/browser/querybuilder.py @@ -137,7 +137,7 @@ def clean_query_for_solr(self, query): portal_state = api.content.get_view( context=self.context, request=self.request, - name="plone_portal_state", + name=u"plone_portal_state", ) root_path = portal_state.navigation_root_path() path = self.extract_value(v) diff --git a/src/rer/solrpush/indexer.py b/src/rer/solrpush/indexer.py index 02cfb47..bce614b 100644 --- a/src/rer/solrpush/indexer.py +++ b/src/rer/solrpush/indexer.py @@ -94,9 +94,9 @@ def commit(self, wait=None): logger.exception("error indexing %s %s", iop, uid) message = _( "content_indexed_error", - default="There was a problem indexing or unindexing " - "this content. Please take note of this address and " - "contact site administrator.", + default=u"There was a problem indexing or unindexing " + u"this content. Please take note of this address and " + u"contact site administrator.", ) api.portal.show_message( message=message, request=getRequest(), type="warning" diff --git a/src/rer/solrpush/interfaces/elevate.py b/src/rer/solrpush/interfaces/elevate.py index d9b3da0..e096eef 100644 --- a/src/rer/solrpush/interfaces/elevate.py +++ b/src/rer/solrpush/interfaces/elevate.py @@ -26,19 +26,19 @@ def __contains__(self, value): class IElevateRowSchema(model.Schema): text = schema.List( - title=_("elevate_row_schema_text_label", default="Text"), + title=_("elevate_row_schema_text_label", default=u"Text"), description=_( "elevate_row_schema_text_help", - default="The word that should match in the search.", + default=u"The word that should match in the search.", ), required=True, value_type=schema.TextLine(), ) uid = RelationList( - title=_("elevate_row_schema_uid_label", "Elements"), + title=_("elevate_row_schema_uid_label", u"Elements"), description=_( "elevate_row_schema_uid_help", - "Select a list of elements to elevate for that search word.", + u"Select a list of elements to elevate for that search word.", ), value_type=RelationChoice(vocabulary="plone.app.vocabularies.Catalog"), required=True, @@ -54,10 +54,10 @@ class IElevateSettings(model.Schema): """ """ elevate_schema = schema.SourceText( - title=_("elevate_schema_label", default="Elevate configuration"), + title=_(u"elevate_schema_label", default=u"Elevate configuration"), description=_( - "elevate_schema_help", - default="Insert a list of values for elevate.", + u"elevate_schema_help", + default=u"Insert a list of values for elevate.", ), required=False, ) diff --git a/src/rer/solrpush/interfaces/settings.py b/src/rer/solrpush/interfaces/settings.py index 0e1c8aa..cee02f6 100644 --- a/src/rer/solrpush/interfaces/settings.py +++ b/src/rer/solrpush/interfaces/settings.py @@ -19,18 +19,18 @@ def __contains__(self, value): class IElevateRowSchema(model.Schema): text = schema.TextLine( - title=_("elevate_row_schema_text_label", default="Text"), + title=_("elevate_row_schema_text_label", default=u"Text"), description=_( "elevate_row_schema_text_help", - default="The word that should match in the search.", + default=u"The word that should match in the search.", ), required=True, ) uid = schema.List( - title=_("elevate_row_schema_uid_label", "Elements"), + title=_("elevate_row_schema_uid_label", u"Elements"), description=_( "elevate_row_schema_uid_help", - "Select a list of elements to elevate for that search word.", + u"Select a list of elements to elevate for that search word.", ), value_type=schema.Choice(source=CatalogSource()), required=True, @@ -42,52 +42,52 @@ class IRerSolrpushConf(model.Schema): """""" active = schema.Bool( - title=_("Active"), - description=_("Enable SOLR indexing on this site."), + title=_(u"Active"), + description=_(u"Enable SOLR indexing on this site."), required=False, default=False, ) search_enabled = schema.Bool( - title=_("Search enabled"), + title=_(u"Search enabled"), description=_( - "Site search will use SOLR as engine instead portal_catalog." + u"Site search will use SOLR as engine instead portal_catalog." ), required=False, default=True, ) force_commit = schema.Bool( - title=_("Force commit"), + title=_(u"Force commit"), description=_( - "Force commits on CRUD operations. If enabled, each indexing " - "operation to SOLR will be immediately committed and persisted. " - "This means that updates are immediately available on SOLR queries." # noqa - "If you are using SolrCloud with ZooKeeper, immediate commits " - "will slow down response performances when indexing, so it's " - "better to turn it off. In this case updates will be available " - "when SOLR periodically commit changes." + u"Force commits on CRUD operations. If enabled, each indexing " + u"operation to SOLR will be immediately committed and persisted. " + u"This means that updates are immediately available on SOLR queries." # noqa + u"If you are using SolrCloud with ZooKeeper, immediate commits " + u"will slow down response performances when indexing, so it's " + u"better to turn it off. In this case updates will be available " + u"when SOLR periodically commit changes." ), required=False, default=True, ) solr_url = schema.TextLine( - title=_("SOLR url"), - description=_("The SOLR core to connect to."), + title=_(u"SOLR url"), + description=_(u"The SOLR core to connect to."), required=True, ) frontend_url = schema.TextLine( - title=_("Frontend url"), - description=_("If the website has different URL for frontend users."), + title=_(u"Frontend url"), + description=_(u"If the website has different URL for frontend users."), required=False, ) enabled_types = schema.List( - title=_("enabled_types_label", default="Enabled portal types"), + title=_(u"enabled_types_label", default=u"Enabled portal types"), description=_( - "enabled_types_help", - default="Select a list of portal types to index in solr. " - "Empty list means that all portal types will be indexed.", + u"enabled_types_help", + default=u"Select a list of portal types to index in solr. " + u"Empty list means that all portal types will be indexed.", ), required=False, default=[], @@ -100,21 +100,21 @@ class IRerSolrpushConf(model.Schema): index_fields = schema.SourceText( title=_( "index_fields_label", - default="List of fields loaded from SOLR that we use for " - "indexing.", + default=u"List of fields loaded from SOLR that we use for " + u"indexing.", ), description=_( - "index_fields_help", - default="We store this list for performance" - " reasons. If the configuration changes, you need to click on" - " Reload button", + u"index_fields_help", + default=u"We store this list for performance" + u" reasons. If the configuration changes, you need to click on" + u" Reload button", ), required=False, ) # NASCOSTO DAL PANNELLO DI CONTROLLO (vedi: browser/controlpanel.py) ready = schema.Bool( - title=_("Ready"), - description=_("SOLR push is ready to be used."), + title=_(u"Ready"), + description=_(u"SOLR push is ready to be used."), required=False, default=False, ) @@ -122,69 +122,69 @@ class IRerSolrpushConf(model.Schema): class IRerSolrpushSearchConf(model.Schema): query_debug = schema.Bool( - title=_("Query debug"), + title=_(u"Query debug"), description=_( - "If enabled, when a search to SOLR is performed (for " - "example in Collection), the query will be showed in the page for " - "debug. Only visible to Managers." + u"If enabled, when a search to SOLR is performed (for " + u"example in Collection), the query will be showed in the page for " + u"debug. Only visible to Managers." ), required=False, default=False, ) remote_elevate_schema = schema.TextLine( - title=_("remote_elevate_label", default="Remote elevate"), + title=_(u"remote_elevate_label", default=u"Remote elevate"), description=_( - "remote_elevate_help", - default='If this field is set and no "site_name" is ' - "passed in query, elevate schema is taken from an external " - "source. This is useful if you index several sites and handle " - "elevate configuration in one single site. This should be an url " - 'that points to "@elevate-schema" view.' - "For example: http://my-site/@elevate-schema.", + u"remote_elevate_help", + default=u'If this field is set and no "site_name" is ' + u"passed in query, elevate schema is taken from an external " + u"source. This is useful if you index several sites and handle " + u"elevate configuration in one single site. This should be an url " + u'that points to "@elevate-schema" view.' + u"For example: http://my-site/@elevate-schema.", ), - default="", + default=u"", required=False, ) qf = schema.TextLine( - title=_("qf_label", default="qf (query fields)"), + title=_("qf_label", default=u"qf (query fields)"), description=_( "qf_help", - default="Set a list of fields, each of which is assigned a boost " - "factor to increase or decrease that particular field’s " - "importance in the query. " - "For example: fieldOne^1000.0 fieldTwo fieldThree^10.0", + default=u"Set a list of fields, each of which is assigned a boost " + u"factor to increase or decrease that particular field’s " + u"importance in the query. " + u"For example: fieldOne^1000.0 fieldTwo fieldThree^10.0", ), required=False, - default="", + default=u"", ) bq = schema.TextLine( - title=_("bq_label", default="bq (boost query)"), + title=_("bq_label", default=u"bq (boost query)"), description=_( "bq_help", - default="Set a list query clauses that will be added to the main " - "query to influence the score. For example if we want to boost " - 'results that have a specific "searchwords" term: ' - "searchwords:something^1000", + default=u"Set a list query clauses that will be added to the main " + u"query to influence the score. For example if we want to boost " + u'results that have a specific "searchwords" term: ' + u"searchwords:something^1000", ), required=False, - default="", + default=u"", ) bf = schema.TextLine( - title=_("bf_label", default="bf (boost functions)"), + title=_("bf_label", default=u"bf (boost functions)"), description=_( "bf_help", - default="Set a list of functions (with optional boosts) that " - "will be used to construct FunctionQueries which will be added " - "to the main query as optional clauses that will influence the " - "score. Any function supported natively by Solr can be used, " - "along with a boost value. " - "For example if we want to give less relevance to " - "items deeper in the tree we can set something like this: " - "recip(path_depth,10,100,1)", + default=u"Set a list of functions (with optional boosts) that " + u"will be used to construct FunctionQueries which will be added " + u"to the main query as optional clauses that will influence the " + u"score. Any function supported natively by Solr can be used, " + u"along with a boost value. " + u"For example if we want to give less relevance to " + u"items deeper in the tree we can set something like this: " + u"recip(path_depth,10,100,1)", ), required=False, - default="", + default=u"", ) diff --git a/src/rer/solrpush/restapi/services/solr_search/batch.py b/src/rer/solrpush/restapi/services/solr_search/batch.py index a2acb63..f18b902 100644 --- a/src/rer/solrpush/restapi/services/solr_search/batch.py +++ b/src/rer/solrpush/restapi/services/solr_search/batch.py @@ -57,7 +57,8 @@ def current_batch_url(self): @property def links(self): - """Get a dictionary with batching links.""" + """Get a dictionary with batching links. + """ # Don't provide batching links if resultset isn't batched if self.hits <= self.b_size: return None @@ -81,7 +82,8 @@ def links(self): return links def _url_for_batch(self, pagenumber): - """Return a new Batch object for the given pagenumber.""" + """Return a new Batch object for the given pagenumber. + """ new_start = pagenumber * self.b_size return self._url_with_params(params={"b_start": new_start}) diff --git a/src/rer/solrpush/testing.py b/src/rer/solrpush/testing.py index 7947753..6748b24 100644 --- a/src/rer/solrpush/testing.py +++ b/src/rer/solrpush/testing.py @@ -46,7 +46,7 @@ def __init__( self.solr_host = solr_host self.solr_port = solr_port self.solr_base = solr_base - self.solr_url = "http://{0}:{1}{2}".format( + self.solr_url = u"http://{0}:{1}{2}".format( solr_host, solr_port, solr_base ) @@ -96,9 +96,9 @@ def __init__( bases=None, name="SolrPush Layer", module=None, - solr_host="localhost", + solr_host=u"localhost", solr_port=8983, - solr_base="/solr/solrpush_test", + solr_base=u"/solr/solrpush_test", ): super(PloneSandboxLayer, self).__init__(bases, name, module) self.solr_host = solr_host diff --git a/src/rer/solrpush/tests/test_behaviors.py b/src/rer/solrpush/tests/test_behaviors.py index d0fee6f..b1f9bd4 100644 --- a/src/rer/solrpush/tests/test_behaviors.py +++ b/src/rer/solrpush/tests/test_behaviors.py @@ -31,7 +31,7 @@ def setUp(self): setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record( "enabled_types", - ["Document", "News Item"], + [u"Document", u"News Item"], interface=IRerSolrpushSettings, ) init_solr_push() diff --git a/src/rer/solrpush/tests/test_elevate.py b/src/rer/solrpush/tests/test_elevate.py index 356dc70..8fb8e66 100644 --- a/src/rer/solrpush/tests/test_elevate.py +++ b/src/rer/solrpush/tests/test_elevate.py @@ -18,18 +18,20 @@ class TestSolrSearch(unittest.TestCase): - """ """ + """ + """ layer = RER_SOLRPUSH_API_FUNCTIONAL_TESTING def setUp(self): - """ """ + """ + """ self.portal = self.layer["portal"] self.request = self.layer["request"] setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record( "enabled_types", - ["Document", "News Item"], + [u"Document", u"News Item"], interface=IRerSolrpushSettings, ) @@ -76,7 +78,7 @@ def setUp(self): def tearDown(self): set_registry_record("active", True, interface=IRerSolrpushSettings) #  reset elevate - set_registry_record("elevate_schema", "", interface=IElevateSettings) + set_registry_record("elevate_schema", u"", interface=IElevateSettings) reset_solr() commit() @@ -102,13 +104,11 @@ def test_search_with_elevate(self): ) # now let's set an elevate for third document - value = json.dumps([{"text": ["page"], "uid": [{"UID": doc3.UID()}]}]) + value = json.dumps([{"text": [u"page"], "uid": [{"UID": doc3.UID()}]}]) if six.PY2: value = value.decode("utf-8") set_registry_record( - "elevate_schema", - value, - interface=IElevateSettings, + "elevate_schema", value, interface=IElevateSettings, ) solr_results = search( query={"SearchableText": "page"}, fl=["UID", "Title", "[elevated]"] diff --git a/src/rer/solrpush/tests/test_events.py b/src/rer/solrpush/tests/test_events.py index 4af7486..824841b 100644 --- a/src/rer/solrpush/tests/test_events.py +++ b/src/rer/solrpush/tests/test_events.py @@ -36,7 +36,7 @@ def setUp(self): setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record( "enabled_types", - ["Document", "File"], + [u"Document", u"File"], interface=IRerSolrpushSettings, ) @@ -81,7 +81,7 @@ def setUp(self): setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record( "enabled_types", - ["Document", "File"], + [u"Document", u"File"], interface=IRerSolrpushSettings, ) init_solr_push() diff --git a/src/rer/solrpush/tests/test_image_tags.py b/src/rer/solrpush/tests/test_image_tags.py index 9838639..f78dee9 100644 --- a/src/rer/solrpush/tests/test_image_tags.py +++ b/src/rer/solrpush/tests/test_image_tags.py @@ -27,7 +27,7 @@ def setUp(self): self.request = self.layer["request"] setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record( - "enabled_types", ["File"], interface=IRerSolrpushSettings + "enabled_types", [u"File"], interface=IRerSolrpushSettings ) init_solr_push() commit() @@ -51,7 +51,7 @@ def create_file_item(self, filename): return file_item def test_index_and_extract_pdf(self): - file_item = self.create_file_item("example.pdf") + file_item = self.create_file_item(u"example.pdf") solr_results = search(query={"*": "*"}, fl="UID") self.assertEqual(solr_results.hits, 1) @@ -60,7 +60,7 @@ def test_index_and_extract_pdf(self): self.assertEqual(file_item.UID(), st_results.docs[0]["UID"]) def test_index_and_extract_docx(self): - file_item = self.create_file_item("example.docx") + file_item = self.create_file_item(u"example.docx") solr_results = search(query={"*": "*"}, fl="UID SearchableText") self.assertEqual(solr_results.hits, 1) @@ -69,7 +69,7 @@ def test_index_and_extract_docx(self): self.assertEqual(file_item.UID(), st_results.docs[0]["UID"]) def test_index_and_extract_ods(self): - file_item = self.create_file_item("example.ods") + file_item = self.create_file_item(u"example.ods") solr_results = search(query={"*": "*"}, fl="UID SearchableText") self.assertEqual(solr_results.hits, 1) @@ -78,7 +78,7 @@ def test_index_and_extract_ods(self): self.assertEqual(file_item.UID(), st_results.docs[0]["UID"]) def test_indexed_file_has_right_mimetype(self): - self.create_file_item("example.pdf") + self.create_file_item(u"example.pdf") solr_results = search(query={"*": "*"}, fl="UID mime_type") self.assertEqual(solr_results.hits, 1) diff --git a/src/rer/solrpush/tests/test_maintenance.py b/src/rer/solrpush/tests/test_maintenance.py index d81731e..cf80ffc 100644 --- a/src/rer/solrpush/tests/test_maintenance.py +++ b/src/rer/solrpush/tests/test_maintenance.py @@ -39,7 +39,7 @@ def setUp(self): setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record("active", False, interface=IRerSolrpushSettings) set_registry_record( - "enabled_types", ["Document"], interface=IRerSolrpushSettings + "enabled_types", [u"Document"], interface=IRerSolrpushSettings ) get_registry_record("enabled_types", interface=IRerSolrpushSettings) self.published_doc = api.content.create( @@ -125,7 +125,7 @@ def test_maintenance_reindex_with_unwanted_types(self): set_registry_record( "enabled_types", - ["Document", "News Item"], + [u"Document", u"News Item"], interface=IRerSolrpushSettings, ) api.content.transition(obj=self.news, transition="publish") @@ -137,7 +137,7 @@ def test_maintenance_reindex_with_unwanted_types(self): self.assertEqual(solr_results.hits, 3) set_registry_record( - "enabled_types", ["Document"], interface=IRerSolrpushSettings + "enabled_types", [u"Document"], interface=IRerSolrpushSettings ) self.reindex_view() solr_results = search(query={"*": "*", "b_size": 100000}, fl="UID") @@ -150,7 +150,7 @@ def test_maintenance_sync(self): api.content.transition(obj=self.unpublished_doc, transition="publish") set_registry_record( "enabled_types", - ["Document", "News Item"], + [u"Document", u"News Item"], interface=IRerSolrpushSettings, ) self.reindex_view() @@ -158,7 +158,7 @@ def test_maintenance_sync(self): self.assertEqual(solr_results.hits, 3) set_registry_record( - "enabled_types", ["Document"], interface=IRerSolrpushSettings + "enabled_types", [u"Document"], interface=IRerSolrpushSettings ) self.sync_view() solr_results = search(query={"*": "*", "b_size": 100000}, fl="UID") diff --git a/src/rer/solrpush/tests/test_querybuilder.py b/src/rer/solrpush/tests/test_querybuilder.py index 0514c9b..db5cfe6 100644 --- a/src/rer/solrpush/tests/test_querybuilder.py +++ b/src/rer/solrpush/tests/test_querybuilder.py @@ -31,7 +31,7 @@ def setUp(self): setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record( "enabled_types", - ["Document", "News Item"], + [u"Document", u"News Item"], interface=IRerSolrpushSettings, ) init_solr_push() @@ -80,9 +80,9 @@ def setUp(self): def tearDown(self): solr = get_solr_connection() solr.delete(q="*:*", commit=True) - set_registry_record("qf", "", interface=IRerSolrpushSettings) - set_registry_record("bq", "", interface=IRerSolrpushSettings) - set_registry_record("bf", "", interface=IRerSolrpushSettings) + set_registry_record("qf", u"", interface=IRerSolrpushSettings) + set_registry_record("bq", u"", interface=IRerSolrpushSettings) + set_registry_record("bf", u"", interface=IRerSolrpushSettings) commit() def get_results( diff --git a/src/rer/solrpush/tests/test_restapi_search.py b/src/rer/solrpush/tests/test_restapi_search.py index fb8e0ed..af369ec 100644 --- a/src/rer/solrpush/tests/test_restapi_search.py +++ b/src/rer/solrpush/tests/test_restapi_search.py @@ -17,6 +17,7 @@ class SearchBandiTest(unittest.TestCase): + layer = RER_SOLRPUSH_API_FUNCTIONAL_TESTING def setUp(self): @@ -36,7 +37,7 @@ def setUp(self): set_registry_record( "enabled_types", - ["Document", "News Item"], + [u"Document", u"News Item"], interface=IRerSolrpushSettings, ) @@ -94,20 +95,22 @@ def tearDown(self): commit() def test_search_works(self): + solr_response = self.api_session.get("/@solr-search") plone_response = self.api_session.get("/@search") solr_results = solr_response.json() plone_results = plone_response.json() - self.assertEqual(plone_results["items_total"], 6) - self.assertEqual(solr_results["items_total"], 3) + self.assertEqual(plone_results[u"items_total"], 6) + self.assertEqual(solr_results[u"items_total"], 3) def test_disable_search_will_perform_classic_search(self): + solr_response = self.api_session.get("/@solr-search") plone_response = self.api_session.get("/@search") solr_results = solr_response.json() plone_results = plone_response.json() - self.assertEqual(plone_results["items_total"], 6) - self.assertEqual(solr_results["items_total"], 3) + self.assertEqual(plone_results[u"items_total"], 6) + self.assertEqual(solr_results[u"items_total"], 3) set_registry_record( "search_enabled", @@ -120,5 +123,5 @@ def test_disable_search_will_perform_classic_search(self): plone_response = self.api_session.get("/@search") solr_results = solr_response.json() plone_results = plone_response.json() - self.assertEqual(plone_results["items_total"], 6) - self.assertEqual(solr_results["items_total"], 6) + self.assertEqual(plone_results[u"items_total"], 6) + self.assertEqual(solr_results[u"items_total"], 6) diff --git a/src/rer/solrpush/tests/test_search.py b/src/rer/solrpush/tests/test_search.py index 5809f6f..7397637 100644 --- a/src/rer/solrpush/tests/test_search.py +++ b/src/rer/solrpush/tests/test_search.py @@ -32,7 +32,7 @@ def setUp(self): setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record( "enabled_types", - ["Document", "News Item"], + [u"Document", u"News Item"], interface=IRerSolrpushSettings, ) init_solr_push() @@ -62,9 +62,9 @@ def setUp(self): def tearDown(self): reset_solr() - set_registry_record("qf", "", interface=IRerSolrpushSettings) - set_registry_record("bq", "", interface=IRerSolrpushSettings) - set_registry_record("bf", "", interface=IRerSolrpushSettings) + set_registry_record("qf", u"", interface=IRerSolrpushSettings) + set_registry_record("bq", u"", interface=IRerSolrpushSettings) + set_registry_record("bf", u"", interface=IRerSolrpushSettings) commit() def test_all_items(self): @@ -82,7 +82,7 @@ def test_search_qf(self): set_registry_record( "qf", - "id^1000.0 SearchableText^1.0", + u"id^1000.0 SearchableText^1.0", interface=IRerSolrpushSettings, ) commit() @@ -97,7 +97,7 @@ def test_search_qf_for_searchwords(self): set_registry_record( "qf", - "searchwords^1000.0 SearchableText^1.0", + u"searchwords^1000.0 SearchableText^1.0", interface=IRerSolrpushSettings, ) commit() @@ -111,7 +111,7 @@ def test_search_bq(self): self.assertEqual(solr_results.hits, len(self.docs) / 2) self.assertNotEqual(solr_results.docs[0]["id"], "odd") - set_registry_record("bq", "id:odd", interface=IRerSolrpushSettings) + set_registry_record("bq", u"id:odd", interface=IRerSolrpushSettings) commit() solr_results = search(query={"": "odd"}, fl=["UID", "id", "Title"]) diff --git a/src/rer/solrpush/tests/test_setup.py b/src/rer/solrpush/tests/test_setup.py index ca05af2..0163c14 100644 --- a/src/rer/solrpush/tests/test_setup.py +++ b/src/rer/solrpush/tests/test_setup.py @@ -41,6 +41,7 @@ def test_browserlayer(self): class TestUninstall(unittest.TestCase): + layer = RER_SOLRPUSH_API_INTEGRATION_TESTING def setUp(self): diff --git a/src/rer/solrpush/tests/test_solr_interface.py b/src/rer/solrpush/tests/test_solr_interface.py index eaa883a..f722ee9 100644 --- a/src/rer/solrpush/tests/test_solr_interface.py +++ b/src/rer/solrpush/tests/test_solr_interface.py @@ -28,7 +28,7 @@ def setUp(self): self.request = self.layer["request"] setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record( - "enabled_types", ["Document"], interface=IRerSolrpushSettings + "enabled_types", [u"Document"], interface=IRerSolrpushSettings ) self.published_doc = api.content.create( container=self.portal, type="Document", title="Published Document" @@ -153,7 +153,7 @@ def setUp(self): setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record( "enabled_types", - ["Document", "News Item"], + [u"Document", u"News Item"], interface=IRerSolrpushSettings, ) #  initialize solr push, so solr will be populated automatically diff --git a/src/rer/solrpush/tests/test_tika.py b/src/rer/solrpush/tests/test_tika.py index 9838639..f78dee9 100644 --- a/src/rer/solrpush/tests/test_tika.py +++ b/src/rer/solrpush/tests/test_tika.py @@ -27,7 +27,7 @@ def setUp(self): self.request = self.layer["request"] setRoles(self.portal, TEST_USER_ID, ["Manager"]) set_registry_record( - "enabled_types", ["File"], interface=IRerSolrpushSettings + "enabled_types", [u"File"], interface=IRerSolrpushSettings ) init_solr_push() commit() @@ -51,7 +51,7 @@ def create_file_item(self, filename): return file_item def test_index_and_extract_pdf(self): - file_item = self.create_file_item("example.pdf") + file_item = self.create_file_item(u"example.pdf") solr_results = search(query={"*": "*"}, fl="UID") self.assertEqual(solr_results.hits, 1) @@ -60,7 +60,7 @@ def test_index_and_extract_pdf(self): self.assertEqual(file_item.UID(), st_results.docs[0]["UID"]) def test_index_and_extract_docx(self): - file_item = self.create_file_item("example.docx") + file_item = self.create_file_item(u"example.docx") solr_results = search(query={"*": "*"}, fl="UID SearchableText") self.assertEqual(solr_results.hits, 1) @@ -69,7 +69,7 @@ def test_index_and_extract_docx(self): self.assertEqual(file_item.UID(), st_results.docs[0]["UID"]) def test_index_and_extract_ods(self): - file_item = self.create_file_item("example.ods") + file_item = self.create_file_item(u"example.ods") solr_results = search(query={"*": "*"}, fl="UID SearchableText") self.assertEqual(solr_results.hits, 1) @@ -78,7 +78,7 @@ def test_index_and_extract_ods(self): self.assertEqual(file_item.UID(), st_results.docs[0]["UID"]) def test_indexed_file_has_right_mimetype(self): - self.create_file_item("example.pdf") + self.create_file_item(u"example.pdf") solr_results = search(query={"*": "*"}, fl="UID mime_type") self.assertEqual(solr_results.hits, 1) diff --git a/src/rer/solrpush/utils/solr_indexer.py b/src/rer/solrpush/utils/solr_indexer.py index c2483fe..1c3b34b 100644 --- a/src/rer/solrpush/utils/solr_indexer.py +++ b/src/rer/solrpush/utils/solr_indexer.py @@ -275,7 +275,7 @@ def remove_from_solr(uid): logger.error(err) message = _( "content_remove_error", - default="There was a problem removing this content from SOLR. " + default=u"There was a problem removing this content from SOLR. " " Please contact site administrator.", ) api.portal.show_message( diff --git a/src/rer/solrpush/utils/solr_search.py b/src/rer/solrpush/utils/solr_search.py index 5eec74e..e386564 100644 --- a/src/rer/solrpush/utils/solr_search.py +++ b/src/rer/solrpush/utils/solr_search.py @@ -276,7 +276,6 @@ def add_query_tweaks(): # END HELPER METHODS - # LIBRARY METHODS def search( query, @@ -299,7 +298,7 @@ def search( """ solr = get_solr_connection() if not solr: - msg = "Unable to search using solr. Configuration is incomplete." + msg = u"Unable to search using solr. Configuration is incomplete." logger.error(msg) return { "error": True, @@ -325,9 +324,9 @@ def search( "message": translate( _( "search_error_label", - default="Unable to perform a search with SOLR." - " Please contact the site administrator or wait some" - " minutes.", + default=u"Unable to perform a search with SOLR." + u" Please contact the site administrator or wait some" + u" minutes.", ), context=api.portal.get().REQUEST, ),