From 4ef6e99a886da17296e736c8a6c0b041238f917d Mon Sep 17 00:00:00 2001 From: Paul Grunewald Date: Fri, 8 Mar 2024 11:41:46 +0100 Subject: [PATCH] Run python2 compatible black --- CHANGES.rst | 3 +- DEVELOP.rst | 7 +- requirements_black.txt | 4 + src/collective/exportimport/config.py | 4 +- src/collective/exportimport/export_content.py | 52 +++++++---- src/collective/exportimport/export_other.py | 7 +- src/collective/exportimport/export_topic.py | 5 +- src/collective/exportimport/fix_html.py | 41 +++++++-- src/collective/exportimport/import_content.py | 71 +++++++++------ src/collective/exportimport/import_other.py | 25 ++++-- src/collective/exportimport/interfaces.py | 2 +- src/collective/exportimport/serializer.py | 68 ++++++++++---- .../tests/test_drop_and_include.py | 88 +++++++++---------- .../exportimport/tests/test_export.py | 4 +- .../exportimport/tests/test_fix_html.py | 54 ++++++++---- 15 files changed, 288 insertions(+), 147 deletions(-) create mode 100644 requirements_black.txt diff --git a/CHANGES.rst b/CHANGES.rst index 3f614a5d..d2481e20 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,8 @@ Changelog 1.13 (unreleased) ----------------- -- Nothing changed yet. +- Add and run a black version, that is compatible with Python 2. + [pgrunewald] 1.12 (2024-03-08) diff --git a/DEVELOP.rst b/DEVELOP.rst index df9f3232..a99138e8 100644 --- a/DEVELOP.rst +++ b/DEVELOP.rst @@ -7,7 +7,7 @@ Create a virtualenv in the package:: Install requirements with pip:: - $ ./bin/pip install -r requirements.txt + $ ./bin/pip install -r requirements.txt -r requirements_black.txt Run buildout:: @@ -38,3 +38,8 @@ run a specific tox env: $ tox -e plone52-py38 + +Format Python code +------------------ + + $ ./bin/black . \ No newline at end of file diff --git a/requirements_black.txt b/requirements_black.txt new file mode 100644 index 00000000..ecd175e6 --- /dev/null +++ b/requirements_black.txt @@ -0,0 +1,4 @@ +# black 21.12b0 is the last version supporting Python2 syntax +black==21.12b0 +# ensure compatibility with our black version +click==8.0.3 \ No newline at end of file diff --git a/src/collective/exportimport/config.py b/src/collective/exportimport/config.py index 17dc2b62..bd5452dd 100644 --- a/src/collective/exportimport/config.py +++ b/src/collective/exportimport/config.py @@ -12,7 +12,7 @@ os.path.expandvars(os.getenv("COLLECTIVE_EXPORTIMPORT_CENTRAL_DIRECTORY", "")) ) -SITE_ROOT = 'plone_site_root' +SITE_ROOT = "plone_site_root" # Discussion Item has its own export / import views, don't show it in the exportable content type list -SKIPPED_CONTENTTYPE_IDS = ['Discussion Item'] +SKIPPED_CONTENTTYPE_IDS = ["Discussion Item"] diff --git a/src/collective/exportimport/export_content.py b/src/collective/exportimport/export_content.py index 77e79c2a..f5501feb 100644 --- a/src/collective/exportimport/export_content.py +++ b/src/collective/exportimport/export_content.py @@ -112,7 +112,7 @@ def __call__( download_to_server=False, migration=True, include_revisions=False, - write_errors=False + write_errors=False, ): self.portal_type = portal_type or [] if isinstance(self.portal_type, str): @@ -150,7 +150,9 @@ def __call__( return self.template() if not self.portal_type: - api.portal.show_message(_(u"Select at least one type to export"), self.request) + api.portal.show_message( + _(u"Select at least one type to export"), self.request + ) return self.template() if self.include_blobs == 1: @@ -250,7 +252,11 @@ def __call__( json.dump(errors, f, indent=4) f.write("]") msg = _(u"Exported {} items ({}) as {} to {} with {} errors").format( - number, ", ".join(self.portal_type), filename, filepath, len(self.errors) + number, + ", ".join(self.portal_type), + filename, + filepath, + len(self.errors), ) logger.info(msg) api.portal.show_message(msg, self.request) @@ -274,12 +280,14 @@ def __call__( f.write(",") json.dump(datum, f, sort_keys=True, indent=4) if number: - if self.errors and self.write_errors: + if self.errors and self.write_errors: f.write(",") errors = {"unexported_paths": self.errors} json.dump(errors, f, indent=4) f.write("]") - msg = _(u"Exported {} {} with {} errors").format(number, self.portal_type, len(self.errors)) + msg = _(u"Exported {} {} with {} errors").format( + number, self.portal_type, len(self.errors) + ) logger.info(msg) api.portal.show_message(msg, self.request) response = self.request.response @@ -350,13 +358,13 @@ def export_content(self): obj = brain.getObject() except Exception: msg = u"Error getting brain {}".format(brain.getPath()) - self.errors.append({'path':None, 'message': msg}) + self.errors.append({"path": None, "message": msg}) logger.exception(msg, exc_info=True) continue if obj is None: msg = u"brain.getObject() is None {}".format(brain.getPath()) logger.error(msg) - self.errors.append({'path':None, 'message': msg}) + self.errors.append({"path": None, "message": msg}) continue obj = self.global_obj_hook(obj) if not obj: @@ -375,7 +383,7 @@ def export_content(self): yield item except Exception: msg = u"Error exporting {}".format(obj.absolute_url()) - self.errors.append({'path':obj.absolute_url(), 'message':msg}) + self.errors.append({"path": obj.absolute_url(), "message": msg}) logger.exception(msg, exc_info=True) def portal_types(self): @@ -395,7 +403,9 @@ def portal_types(self): "number": number, "value": fti.id, "title": translate( - safe_unicode(fti.title), domain="plone", context=self.request + safe_unicode(fti.title), + domain="plone", + context=self.request, ), } ) @@ -580,15 +590,27 @@ def export_revisions(self, item, obj): item_version = self.update_data_for_migration(item_version, obj) item["exportimport.versions"][version_id] = item_version # inject metadata (missing for Archetypes content): - comment = history_metadata.retrieve(version_id)["metadata"]["sys_metadata"]["comment"] - if comment and comment != item["exportimport.versions"][version_id].get("changeNote"): + comment = history_metadata.retrieve(version_id)["metadata"]["sys_metadata"][ + "comment" + ] + if comment and comment != item["exportimport.versions"][version_id].get( + "changeNote" + ): item["exportimport.versions"][version_id]["changeNote"] = comment - principal = history_metadata.retrieve(version_id)["metadata"]["sys_metadata"]["principal"] - if principal and principal != item["exportimport.versions"][version_id].get("changeActor"): + principal = history_metadata.retrieve(version_id)["metadata"][ + "sys_metadata" + ]["principal"] + if principal and principal != item["exportimport.versions"][version_id].get( + "changeActor" + ): item["exportimport.versions"][version_id]["changeActor"] = principal # current changenote - item["changeNote"] = history_metadata.retrieve(-1)["metadata"]["sys_metadata"]["comment"] - item["changeActor"] = history_metadata.retrieve(-1)["metadata"]["sys_metadata"]["principal"] + item["changeNote"] = history_metadata.retrieve(-1)["metadata"]["sys_metadata"][ + "comment" + ] + item["changeActor"] = history_metadata.retrieve(-1)["metadata"]["sys_metadata"][ + "principal" + ] return item diff --git a/src/collective/exportimport/export_other.py b/src/collective/exportimport/export_other.py index 1db617de..2263bf4f 100644 --- a/src/collective/exportimport/export_other.py +++ b/src/collective/exportimport/export_other.py @@ -644,7 +644,9 @@ def __call__(self, download_to_server=False): def all_portlets(self): self.results = [] portal = api.portal.get() - portal.ZopeFindAndApply(self.context, search_sub=True, apply_func=self.get_portlets) + portal.ZopeFindAndApply( + self.context, search_sub=True, apply_func=self.get_portlets + ) self.get_root_portlets() return self.results @@ -669,7 +671,7 @@ def _get_portlets(self, obj, uid): obj_results["uuid"] = uid self.results.append(obj_results) return - + def get_root_portlets(self): site = api.portal.get() self._get_portlets(site, PORTAL_PLACEHOLDER) @@ -681,6 +683,7 @@ def local_portlets_hook(self, portlets): def portlets_blacklist_hook(self, blacklist): return blacklist + def export_local_portlets(obj): """Serialize portlets for one content object Code mostly taken from https://github.com/plone/plone.restapi/pull/669 diff --git a/src/collective/exportimport/export_topic.py b/src/collective/exportimport/export_topic.py index f1648bb4..df90b42b 100644 --- a/src/collective/exportimport/export_topic.py +++ b/src/collective/exportimport/export_topic.py @@ -3,7 +3,8 @@ class ExportTopic(ExportContent): - """ Export ATTopic """ + """Export ATTopic""" + def build_query(self): - """ Build the query based on the topic criterias """ + """Build the query based on the topic criterias""" return self.context.buildQuery() diff --git a/src/collective/exportimport/fix_html.py b/src/collective/exportimport/fix_html.py index fc48f674..e5114ddc 100644 --- a/src/collective/exportimport/fix_html.py +++ b/src/collective/exportimport/fix_html.py @@ -235,7 +235,7 @@ def find_object(base, path): obj = api.portal.get() portal_path = obj.absolute_url_path() + "/" if path.startswith(portal_path): - path = path[len(portal_path):] + path = path[len(portal_path) :] else: obj = aq_parent(base) # relative urls start at the parent... @@ -324,14 +324,18 @@ def table_class_fixer(text, obj=None): query["path"] = "/".join(context.getPhysicalPath()) brains = catalog(**query) total = len(brains) - logger.info("There are %s content items in total, starting migration...", len(brains)) + logger.info( + "There are %s content items in total, starting migration...", len(brains) + ) fixed_fields = 0 fixed_items = 0 for index, brain in enumerate(brains, start=1): try: obj = brain.getObject() except Exception: - logger.warning("Could not get object for: %s", brain.getPath(), exc_info=True) + logger.warning( + "Could not get object for: %s", brain.getPath(), exc_info=True + ) continue if obj is None: logger.error(u"brain.getObject() is None %s", brain.getPath()) @@ -343,11 +347,19 @@ def table_class_fixer(text, obj=None): if text and IRichTextValue.providedBy(text) and text.raw: clean_text = text.raw for fixer in fixers: - logger.debug("Fixing html for %s with %s", obj.absolute_url(), fixer.__name__) + logger.debug( + "Fixing html for %s with %s", + obj.absolute_url(), + fixer.__name__, + ) try: clean_text = fixer(clean_text, obj) except Exception: - logger.info(u"Error while fixing html of %s for %s", fieldname, obj.absolute_url()) + logger.info( + u"Error while fixing html of %s for %s", + fieldname, + obj.absolute_url(), + ) raise if clean_text and clean_text != text.raw: @@ -359,7 +371,11 @@ def table_class_fixer(text, obj=None): ) setattr(obj, fieldname, textvalue) changed = True - logger.debug(u"Fixed html for field %s of %s", fieldname, obj.absolute_url()) + logger.debug( + u"Fixed html for field %s of %s", + fieldname, + obj.absolute_url(), + ) fixed_fields += 1 if changed: fixed_items += 1 @@ -371,11 +387,20 @@ def table_class_fixer(text, obj=None): # Commit every 1000 changed items. logger.info( u"Fix html for %s (%s) of %s items (changed %s fields in %s items)", - index, round(index / total * 100, 2), total, fixed_fields, fixed_items) + index, + round(index / total * 100, 2), + total, + fixed_fields, + fixed_items, + ) if commit: transaction.commit() - logger.info(u"Finished fixing html in content fields (changed %s fields in %s items)", fixed_fields, fixed_items) + logger.info( + u"Finished fixing html in content fields (changed %s fields in %s items)", + fixed_fields, + fixed_items, + ) if commit: # commit remaining items transaction.commit() diff --git a/src/collective/exportimport/import_content.py b/src/collective/exportimport/import_content.py index 895cef6e..2a2d3d90 100644 --- a/src/collective/exportimport/import_content.py +++ b/src/collective/exportimport/import_content.py @@ -80,7 +80,7 @@ def get_absolute_blob_path(obj, blob_path): def filesystem_walker(path=None): root = Path(path) - assert(root.is_dir()) + assert root.is_dir() # first import json-files directly in the path json_files = [i for i in root.glob("*.json") if i.stem.isdecimal()] @@ -325,7 +325,9 @@ def must_process(self, item_path): if not self.should_include(item_path): return False elif self.should_drop(item_path): - logger.info(u"Skipping %s, even though listed in INCLUDE_PATHS", item_path) + logger.info( + u"Skipping %s, even though listed in INCLUDE_PATHS", item_path + ) return False else: if self.should_drop(item_path): @@ -466,10 +468,12 @@ def import_new_content(self, data): # noqa: C901 if self.commit and not len(added) % self.commit: self.commit_hook(added, index) except Exception as e: - item_id = item['@id'].split('/')[-1] + item_id = item["@id"].split("/")[-1] container.manage_delObjects(item_id) logger.warning(e) - logger.warning("Didn't add %s %s", item["@type"], item["@id"], exc_info=True) + logger.warning( + "Didn't add %s %s", item["@type"], item["@id"], exc_info=True + ) continue return added @@ -484,13 +488,15 @@ def handle_new_object(self, item, index, new): try: new = deserializer(validate_all=False, data=item) except TypeError as error: - if 'unexpected keyword argument' in str(error): + if "unexpected keyword argument" in str(error): self.request["BODY"] = json.dumps(item) new = deserializer(validate_all=False) else: raise error except Exception: - logger.warning("Cannot deserialize %s %s", item["@type"], item["@id"], exc_info=True) + logger.warning( + "Cannot deserialize %s %s", item["@type"], item["@id"], exc_info=True + ) raise # Blobs can be exported as only a path in the blob storage. @@ -506,9 +512,7 @@ def handle_new_object(self, item, index, new): # Happens only when we import content that doesn't have a UID # for instance when importing from non Plone systems. logger.info( - "Created new UID for item %s with type %s.", - item["@id"], - item["@type"] + "Created new UID for item %s with type %s.", item["@id"], item["@type"] ) item["UID"] = uuid @@ -534,9 +538,7 @@ def handle_new_object(self, item, index, new): new.creation_date = creation_date new.aq_base.creation_date_migrated = creation_date logger.info( - "Created item #{}: {} {}".format( - index, item["@type"], new.absolute_url() - ) + "Created item #{}: {} {}".format(index, item["@type"], new.absolute_url()) ) return new @@ -598,7 +600,12 @@ def import_versions(self, container, item): try: new = deserializer(validate_all=False, data=version) except Exception: - logger.warning("Cannot deserialize %s %s", item["@type"], item["@id"], exc_info=True) + logger.warning( + "Cannot deserialize %s %s", + item["@type"], + item["@id"], + exc_info=True, + ) return self.save_revision(new, version, initial) @@ -609,7 +616,9 @@ def import_versions(self, container, item): try: new = deserializer(validate_all=False, data=item) except Exception: - logger.warning("Cannot deserialize %s %s", item["@type"], item["@id"], exc_info=True) + logger.warning( + "Cannot deserialize %s %s", item["@type"], item["@id"], exc_info=True + ) return self.import_blob_paths(new, item) @@ -778,15 +787,12 @@ def import_constrains(self, obj, item): return constrains.setConstrainTypesMode(ENABLED) - locally_allowed_types = item["exportimport.constrains"][ - "locally_allowed_types" - ] + locally_allowed_types = item["exportimport.constrains"]["locally_allowed_types"] try: constrains.setLocallyAllowedTypes(locally_allowed_types) except ValueError: logger.warning( - "Cannot setLocallyAllowedTypes on %s", item["@id"], - exc_info=True + "Cannot setLocallyAllowedTypes on %s", item["@id"], exc_info=True ) immediately_addable_types = item["exportimport.constrains"][ @@ -796,8 +802,7 @@ def import_constrains(self, obj, item): constrains.setImmediatelyAddableTypes(immediately_addable_types) except ValueError: logger.warning( - "Cannot setImmediatelyAddableTypes on %s", item["@id"], - exc_info=True + "Cannot setImmediatelyAddableTypes on %s", item["@id"], exc_info=True ) def import_review_state(self, obj, item): @@ -997,7 +1002,9 @@ def create_container(self, item): # Handle folderish Documents provided by plone.volto fti = getUtility(IDexterityFTI, name="Document") - parent_type = "Document" if fti.klass.endswith("FolderishDocument") else "Folder" + parent_type = ( + "Document" if fti.klass.endswith("FolderishDocument") else "Folder" + ) # create original structure for imported content for element in parent_path: if element not in folder: @@ -1007,7 +1014,11 @@ def create_container(self, item): id=element, title=element, ) - logger.info(u"Created container %s to hold %s", folder.absolute_url(), item["@id"]) + logger.info( + u"Created container %s to hold %s", + folder.absolute_url(), + item["@id"], + ) else: folder = folder[element] @@ -1043,8 +1054,10 @@ def fix_portal_type(portal_type): class ResetModifiedAndCreatedDate(BrowserView): def __call__(self): self.title = _(u"Reset creation and modification date") - self.help_text = _("

Creation- and modification-dates are changed during import." \ - "This resets them to the original dates of the imported content.

") + self.help_text = _( + "

Creation- and modification-dates are changed during import." + "This resets them to the original dates of the imported content.

" + ) if not self.request.form.get("form.submitted", False): return self.index() @@ -1074,11 +1087,15 @@ def reset_dates(obj, path): class FixCollectionQueries(BrowserView): def __call__(self): self.title = _(u"Fix collection queries") - self.help_text = _(u"""

This fixes invalid collection-criteria that were imported from Plone 4 or 5.

""") + self.help_text = _( + u"""

This fixes invalid collection-criteria that were imported from Plone 4 or 5.

""" + ) if not HAS_COLLECTION_FIX: api.portal.show_message( - _(u"plone.app.querystring.upgrades.fix_select_all_existing_collections is not available"), + _( + u"plone.app.querystring.upgrades.fix_select_all_existing_collections is not available" + ), self.request, ) return self.index() diff --git a/src/collective/exportimport/import_other.py b/src/collective/exportimport/import_other.py index b24672ac..bfdea317 100644 --- a/src/collective/exportimport/import_other.py +++ b/src/collective/exportimport/import_other.py @@ -170,6 +170,7 @@ def link_translations(obj, translation, language): logger.info(u"Item is not translatable: {}".format(e)) else: + class ImportTranslations(BrowserView): def __call__(self, jsonfile=None, return_json=False): return "This view only works when using plone.app.multilingual >= 2.0.0" @@ -260,9 +261,7 @@ def import_members(self, data): try: pr.addMember(username, password, roles, [], item) except ValueError: - logger.info( - u"ValueError {} : {}".format(username, item) - ) + logger.info(u"ValueError {} : {}".format(username, item)) continue for group in groups: if group not in groupsDict.keys(): @@ -286,7 +285,9 @@ def __call__(self, jsonfile=None, return_json=False): if not HAS_RELAPI and not HAS_PLONE6: api.portal.show_message( - _("You need either Plone 6 or collective.relationhelpers to import relations"), + _( + "You need either Plone 6 or collective.relationhelpers to import relations" + ), self.request, ) return self.index() @@ -407,7 +408,11 @@ def import_localroles(self, data): if item["uuid"] == PORTAL_PLACEHOLDER: obj = api.portal.get() else: - logger.info("Could not find object to set localroles on. UUID: {}".format(item["uuid"])) + logger.info( + "Could not find object to set localroles on. UUID: {}".format( + item["uuid"] + ) + ) continue if item.get("localroles"): localroles = item["localroles"] @@ -465,7 +470,9 @@ def __call__(self, jsonfile=None, return_json=False): orders = self.import_ordering(data) end = datetime.now() delta = end - start - msg = _(u"Imported {} orders in {} seconds").format(orders, delta.seconds) + msg = _(u"Imported {} orders in {} seconds").format( + orders, delta.seconds + ) logger.info(msg) api.portal.show_message(msg, self.request) if return_json: @@ -703,7 +710,11 @@ def import_portlets(self, data): if item["uuid"] == PORTAL_PLACEHOLDER: obj = api.portal.get() else: - logger.info("Could not find object to set portlet on UUID: {}".format(item["uuid"])) + logger.info( + "Could not find object to set portlet on UUID: {}".format( + item["uuid"] + ) + ) continue registered_portlets = register_portlets(obj, item) results += registered_portlets diff --git a/src/collective/exportimport/interfaces.py b/src/collective/exportimport/interfaces.py index c2ef14dc..9dc5523e 100644 --- a/src/collective/exportimport/interfaces.py +++ b/src/collective/exportimport/interfaces.py @@ -20,4 +20,4 @@ class IMigrationMarker(Interface): class ITalesField(Interface): - """a marker interface to export TalesField """ + """a marker interface to export TalesField""" diff --git a/src/collective/exportimport/serializer.py b/src/collective/exportimport/serializer.py index acb5a67b..eff23154 100644 --- a/src/collective/exportimport/serializer.py +++ b/src/collective/exportimport/serializer.py @@ -163,7 +163,13 @@ def __call__(self): except LookupError: # TODO: handle defaultFactory? if v not in [self.field.default, self.field.missing_value]: - logger.info("Term lookup error: %r not in vocabulary %r for field %r of %r", v, value_type.vocabularyName, self.field.__name__, self.context) + logger.info( + "Term lookup error: %r not in vocabulary %r for field %r of %r", + v, + value_type.vocabularyName, + self.field.__name__, + self.context, + ) return json_compatible(value) @@ -186,7 +192,13 @@ def __call__(self): except LookupError: # TODO: handle defaultFactory? if value not in [self.field.default, self.field.missing_value]: - logger.info("Term lookup error: %r not in vocabulary %r for field %r of %r", value, self.field.vocabularyName, self.field.__name__, self.context) + logger.info( + "Term lookup error: %r not in vocabulary %r for field %r of %r", + value, + self.field.vocabularyName, + self.field.__name__, + self.context, + ) return json_compatible(value) @@ -418,28 +430,43 @@ def __call__(self, version=None, include_items=False): registry = reader.parseRegistry() # Inject new selection-operators that were added in Plone 5 - selection = registry["plone"]["app"]["querystring"]["operation"]["selection"] + selection = registry["plone"]["app"]["querystring"]["operation"][ + "selection" + ] new_operators = ["all", "any", "none"] - for operator in new_operators: + for operator in new_operators: if operator not in selection: # just a dummy method to pass validation selection[operator] = {"operation": "collective.exportimport"} # Inject any operator for some fields any_operator = "plone.app.querystring.operation.selection.any" - fields_with_any_operator = ['Creator', 'Subject', 'portal_type', 'review_state'] + fields_with_any_operator = [ + "Creator", + "Subject", + "portal_type", + "review_state", + ] for field in fields_with_any_operator: - operations = registry["plone"]["app"]["querystring"]["field"][field]["operations"] + operations = registry["plone"]["app"]["querystring"]["field"][field][ + "operations" + ] if any_operator not in operations: - registry["plone"]["app"]["querystring"]["field"][field]["operations"].append(any_operator) + registry["plone"]["app"]["querystring"]["field"][field][ + "operations" + ].append(any_operator) # Inject all operator for Subject - all_operator= "plone.app.querystring.operation.selection.all" + all_operator = "plone.app.querystring.operation.selection.all" fields_with_any_operator = ["Subject"] for field in fields_with_any_operator: - operations = registry["plone"]["app"]["querystring"]["field"][field]["operations"] + operations = registry["plone"]["app"]["querystring"]["field"][field][ + "operations" + ] if all_operator not in operations: - registry["plone"]["app"]["querystring"]["field"][field]["operations"].append(all_operator) + registry["plone"]["app"]["querystring"]["field"][field][ + "operations" + ].append(all_operator) # 3. Migrate criteria using the converters from p.a.contenttypes criteria = self.context.listCriteria() @@ -460,7 +487,11 @@ def __call__(self, version=None, include_items=False): try: converter(query, criterion, registry) except Exception: - logger.info(u"Error converting criterion %s", criterion.__dict__, exc_info=True) + logger.info( + u"Error converting criterion %s", + criterion.__dict__, + exc_info=True, + ) pass # Try to manually convert when no criterion was added @@ -470,7 +501,10 @@ def __call__(self, version=None, include_items=False): if fixed: query.append(fixed) else: - logger.info(u"Check maybe broken collection %s", self.context.absolute_url()) + logger.info( + u"Check maybe broken collection %s", + self.context.absolute_url(), + ) # 4. So some manual fixes in the migrated query indexes_to_fix = [ @@ -481,10 +515,8 @@ def __call__(self, version=None, include_items=False): ] operator_mapping = { # old -> new - u"plone.app.querystring.operation.selection.is": - u"plone.app.querystring.operation.selection.any", - u"plone.app.querystring.operation.string.is": - u"plone.app.querystring.operation.selection.any", + u"plone.app.querystring.operation.selection.is": u"plone.app.querystring.operation.selection.any", + u"plone.app.querystring.operation.string.is": u"plone.app.querystring.operation.selection.any", } fixed_query = [] for crit in query: @@ -553,10 +585,10 @@ def get_dx_blob_path(obj): @adapter(INamedFileField, IDexterityContent, IPathBlobsMarker) @implementer(IFieldSerializer) class FileFieldSerializerZODBData(FileFieldSerializerWithBlobs): - """ Although the marker is IPathBlobsMarker, this being a plain NamedFile + """Although the marker is IPathBlobsMarker, this being a plain NamedFile object, its data is in the ZODB, thus this still needs to be base64 encoded into the JSON file - So we just subclass from the above FileFieldSerializerWithBlobs """ + So we just subclass from the above FileFieldSerializerWithBlobs""" @adapter(INamedBlobFileField, IDexterityContent, IPathBlobsMarker) diff --git a/src/collective/exportimport/tests/test_drop_and_include.py b/src/collective/exportimport/tests/test_drop_and_include.py index 26a91e32..f16d6aa7 100644 --- a/src/collective/exportimport/tests/test_drop_and_include.py +++ b/src/collective/exportimport/tests/test_drop_and_include.py @@ -8,70 +8,70 @@ class NoIncludeAndNoDrop(ImportContent): class IncludeAndNoDrop(ImportContent): - INCLUDE_PATHS = ['/Plone/include'] + INCLUDE_PATHS = ["/Plone/include"] class NoIncludeAndDrop(ImportContent): - DROP_PATHS = ['/Plone/drop'] + DROP_PATHS = ["/Plone/drop"] class IncludeAndDrop(ImportContent): - INCLUDE_PATHS = ['/Plone/include'] - DROP_PATHS = ['/Plone/include/drop', '/Plone/drop'] + INCLUDE_PATHS = ["/Plone/include"] + DROP_PATHS = ["/Plone/include/drop", "/Plone/drop"] class TestDropAndInclude(unittest.TestCase): def test_no_include_and_no_drop(self): view = NoIncludeAndNoDrop(None, None) - self.assertFalse(view.should_drop('/Plone/testdocument')) - self.assertTrue(view.must_process('/Plone/testdocument')) + self.assertFalse(view.should_drop("/Plone/testdocument")) + self.assertTrue(view.must_process("/Plone/testdocument")) def test_include_and_no_drop(self): view = IncludeAndNoDrop(None, None) - self.assertFalse(view.should_drop('/Plone/testdocument')) - self.assertFalse(view.should_include('/Plone/testdocument')) - self.assertTrue(view.should_include('/Plone/include')) - self.assertTrue(view.should_include('/Plone/include/testdocument')) - self.assertFalse(view.must_process('/Plone/testdocument')) - self.assertTrue(view.must_process('/Plone/include')) - self.assertTrue(view.must_process('/Plone/include/testdocument')) + self.assertFalse(view.should_drop("/Plone/testdocument")) + self.assertFalse(view.should_include("/Plone/testdocument")) + self.assertTrue(view.should_include("/Plone/include")) + self.assertTrue(view.should_include("/Plone/include/testdocument")) + self.assertFalse(view.must_process("/Plone/testdocument")) + self.assertTrue(view.must_process("/Plone/include")) + self.assertTrue(view.must_process("/Plone/include/testdocument")) def test_no_include_and_drop(self): view = NoIncludeAndDrop(None, None) - self.assertFalse(view.should_drop('/Plone/testdocument')) - self.assertTrue(view.should_drop('/Plone/drop')) - self.assertTrue(view.should_drop('/Plone/drop/testdocument')) + self.assertFalse(view.should_drop("/Plone/testdocument")) + self.assertTrue(view.should_drop("/Plone/drop")) + self.assertTrue(view.should_drop("/Plone/drop/testdocument")) - self.assertFalse(view.should_include('/Plone/drop/testdocument')) - self.assertFalse(view.should_include('/Plone/testdocument')) + self.assertFalse(view.should_include("/Plone/drop/testdocument")) + self.assertFalse(view.should_include("/Plone/testdocument")) - self.assertFalse(view.must_process('/Plone/drop')) - self.assertTrue(view.must_process('/Plone/testdocument')) - self.assertFalse(view.must_process('/Plone/drop/testdocument')) + self.assertFalse(view.must_process("/Plone/drop")) + self.assertTrue(view.must_process("/Plone/testdocument")) + self.assertFalse(view.must_process("/Plone/drop/testdocument")) def test_include_and_drop(self): view = IncludeAndDrop(None, None) - self.assertTrue(view.should_drop('/Plone/drop')) - self.assertFalse(view.should_drop('/Plone/testdocument')) - self.assertTrue(view.should_drop('/Plone/drop/testdocument')) - self.assertFalse(view.should_drop('/Plone/include/testdocument')) - self.assertTrue(view.should_drop('/Plone/include/drop/testdocument')) - self.assertFalse(view.should_drop('/Plone/include')) - self.assertTrue(view.should_drop('/Plone/include/drop')) - - self.assertFalse(view.should_include('/Plone/drop')) - self.assertFalse(view.should_include('/Plone/testdocument')) - self.assertFalse(view.should_include('/Plone/drop/testdocument')) - self.assertTrue(view.should_include('/Plone/include/testdocument')) - self.assertTrue(view.should_include('/Plone/include/drop/testdocument')) - self.assertTrue(view.should_include('/Plone/include')) - self.assertTrue(view.should_include('/Plone/include/drop')) - - self.assertFalse(view.must_process('/Plone/drop')) - self.assertFalse(view.must_process('/Plone/testdocument')) - self.assertFalse(view.must_process('/Plone/drop/testdocument')) - self.assertTrue(view.must_process('/Plone/include/testdocument')) - self.assertFalse(view.must_process('/Plone/include/drop/testdocument')) - self.assertTrue(view.must_process('/Plone/include')) - self.assertFalse(view.must_process('/Plone/include/drop')) + self.assertTrue(view.should_drop("/Plone/drop")) + self.assertFalse(view.should_drop("/Plone/testdocument")) + self.assertTrue(view.should_drop("/Plone/drop/testdocument")) + self.assertFalse(view.should_drop("/Plone/include/testdocument")) + self.assertTrue(view.should_drop("/Plone/include/drop/testdocument")) + self.assertFalse(view.should_drop("/Plone/include")) + self.assertTrue(view.should_drop("/Plone/include/drop")) + + self.assertFalse(view.should_include("/Plone/drop")) + self.assertFalse(view.should_include("/Plone/testdocument")) + self.assertFalse(view.should_include("/Plone/drop/testdocument")) + self.assertTrue(view.should_include("/Plone/include/testdocument")) + self.assertTrue(view.should_include("/Plone/include/drop/testdocument")) + self.assertTrue(view.should_include("/Plone/include")) + self.assertTrue(view.should_include("/Plone/include/drop")) + + self.assertFalse(view.must_process("/Plone/drop")) + self.assertFalse(view.must_process("/Plone/testdocument")) + self.assertFalse(view.must_process("/Plone/drop/testdocument")) + self.assertTrue(view.must_process("/Plone/include/testdocument")) + self.assertFalse(view.must_process("/Plone/include/drop/testdocument")) + self.assertTrue(view.must_process("/Plone/include")) + self.assertFalse(view.must_process("/Plone/include/drop")) diff --git a/src/collective/exportimport/tests/test_export.py b/src/collective/exportimport/tests/test_export.py index 831f3e7d..b4daceb7 100644 --- a/src/collective/exportimport/tests/test_export.py +++ b/src/collective/exportimport/tests/test_export.py @@ -812,5 +812,7 @@ def test_export_blob_as_download_urls(self): self.assertEqual(info["title"], file1.Title()) self.assertEqual(info["file"]["content-type"], "application/pdf") self.assertEqual(info["file"]["filename"], "file.pdf") - self.assertEqual(info["file"]["download"], "http://nohost/plone/file1/@@download/file") + self.assertEqual( + info["file"]["download"], "http://nohost/plone/file1/@@download/file" + ) self.assertEqual(info["file"]["size"], 8561) diff --git a/src/collective/exportimport/tests/test_fix_html.py b/src/collective/exportimport/tests/test_fix_html.py index 1621f4cf..1cdce295 100644 --- a/src/collective/exportimport/tests/test_fix_html.py +++ b/src/collective/exportimport/tests/test_fix_html.py @@ -121,19 +121,25 @@ def test_html_fixer(self): # image with srcset old_text = '' - fixed_html = ''.format(self.image.UID()) + fixed_html = ''.format( + self.image.UID() + ) output = html_fixer(old_text, self.team) self.assertEqual(output, fixed_html) # relative embed of content old_text = '

' - fixed_html = '

'.format(self.team.UID()) + fixed_html = '

'.format( + self.team.UID() + ) output = html_fixer(old_text, self.team) self.assertEqual(output, fixed_html) # relative video/audio embed old_text = '

' - fixed_html = '

'.format(self.team.UID()) + fixed_html = '

'.format( + self.team.UID() + ) output = html_fixer(old_text, self.team) self.assertEqual(output, fixed_html) @@ -171,12 +177,16 @@ def test_fix_html_form(self): form = self.portal.restrictedTraverse("@@fix_html") html = form() self.assertIn("Fix links to content and images in richtext", html) - self.request.form.update({ - "form.submitted": True, - "form.commit": False, - }) + self.request.form.update( + { + "form.submitted": True, + "form.commit": False, + } + ) html = form() - self.assertIn("Fixed HTML for 1 fields in content items. Fixed HTML for 0 portlets.", html) + self.assertIn( + "Fixed HTML for 1 fields in content items. Fixed HTML for 0 portlets.", html + ) fixed_html = """

Links to uuid

Link to view/form

@@ -200,7 +210,9 @@ def test_fix_html_form(self):

-""".format(self.contact.UID(), self.team.UID(), self.image.UID()) +""".format( + self.contact.UID(), self.team.UID(), self.image.UID() + ) self.assertEqual(fixed_html, doc.text.raw) @@ -218,10 +230,12 @@ def test_fix_html_status_message(self): form = self.portal.restrictedTraverse("@@fix_html") html = form() self.assertIn("Fix links to content and images in richtext", html) - self.request.form.update({ - "form.submitted": True, - "form.commit": False, - }) + self.request.form.update( + { + "form.submitted": True, + "form.commit": False, + } + ) html = form() self.assertIn( "Fixed HTML for 1 fields in content items. Fixed HTML for 0 portlets.", @@ -240,14 +254,18 @@ def test_fix_html_does_not_change_normal_links(self): ) form = self.portal.restrictedTraverse("@@fix_html") html = form() - self.request.form.update({ - "form.submitted": True, - "form.commit": False, - }) + self.request.form.update( + { + "form.submitted": True, + "form.commit": False, + } + ) html = form() fixed_html = 'Result for the fight between Rudd-O and Andufo' self.assertEqual(fixed_html, doc.text.raw) - self.assertIn("Fixed HTML for 0 fields in content items. Fixed HTML for 0 portlets.", html) + self.assertIn( + "Fixed HTML for 0 fields in content items. Fixed HTML for 0 portlets.", html + ) def test_html_fixer_commas_in_href(self): self.create_demo_content()