-
Notifications
You must be signed in to change notification settings - Fork 2
fix modulo mime_type for file #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
746b6f8
Add mime_type indexer and upgrade step for Modulo reindexing
6313cf5
Add link refresh logic for Modulo objects in upgrade script
0d66d9b
Fix portal blocks handling by using deepcopy to prevent mutation
96570bf
Add logging for re-aligning mime-types in to_7321 upgrade step
99f5580
Remove unused json import in to_730x upgrade script
f2058cc
black
63532db
Remove unnecessary deepcopy for blocks in to_7321 upgrade step
0ec0052
Remove update_catalog call from to_7321 upgrade step
59f630c
Refactor to_7321 upgrade step: streamline module link refresh logic a…
2e67bdd
changes.srt
TheSaintSimon a5bd66b
Add unit test for upgrade to_7321
TheSaintSimon 12843ae
Add unit tests for Modulo mime type handling and cache refresh
TheSaintSimon d954035
Refine modulo mime type upgrade and tests
TheSaintSimon 55c63da
Refine modulo mime type upgrade step
TheSaintSimon 99dd06a
Update changelog for Modulo mime type indexing and cache refresh impr…
TheSaintSimon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from design.plone.contenttypes.interfaces.modulo import IModulo | ||
| from plone.indexer.decorator import indexer | ||
|
|
||
|
|
||
| @indexer(IModulo) | ||
| def mime_type(context, **kw): | ||
| value = getattr(context, "file_principale", None) | ||
| return getattr(value, "contentType", None) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/design/plone/contenttypes/tests/test_modulo_mime_type.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from design.plone.contenttypes.testing import ( | ||
| DESIGN_PLONE_CONTENTTYPES_INTEGRATION_TESTING, | ||
| ) | ||
| from design.plone.contenttypes.upgrades.to_730x import to_7321 | ||
| from plone import api | ||
| from plone.app.testing import setRoles | ||
| from plone.app.testing import TEST_USER_ID | ||
| from plone.namedfile.file import NamedBlobFile | ||
|
|
||
| import os | ||
| import unittest | ||
|
|
||
|
|
||
| class TestModuloMimeType(unittest.TestCase): | ||
| layer = DESIGN_PLONE_CONTENTTYPES_INTEGRATION_TESTING | ||
|
|
||
| def setUp(self): | ||
| self.portal = self.layer["portal"] | ||
| setRoles(self.portal, TEST_USER_ID, ["Manager"]) | ||
|
|
||
| filename = os.path.join(os.path.dirname(__file__), "example.pdf") | ||
| with open(filename, "rb") as pdf_file: | ||
| pdf_data = pdf_file.read() | ||
|
|
||
| # Build a real Modulo with a PDF as main file. | ||
| self.documento = api.content.create( | ||
| container=self.portal, | ||
| type="Documento", | ||
| title="Documento", | ||
| ) | ||
| self.modulo = api.content.create( | ||
| container=self.documento, | ||
| type="Modulo", | ||
| title="Modulo", | ||
| file_principale=NamedBlobFile( | ||
| data=pdf_data, | ||
| filename="example.pdf", | ||
| contentType="application/pdf", | ||
| ), | ||
| ) | ||
| self.modulo_2 = api.content.create( | ||
| container=self.documento, | ||
| type="Modulo", | ||
| title="Modulo_2", | ||
| file_principale=NamedBlobFile( | ||
| data=pdf_data, | ||
| filename="example.pdf", | ||
| contentType="application/pdf", | ||
| ), | ||
| ) | ||
|
|
||
| def test_to_7321_refreshes_modulo_mime_type_cache(self): | ||
| enhancedlinks_tool = api.portal.get_tool("portal_enhancedlinks") | ||
| # Simulate the stale cache entry that the upgrade has to refresh. | ||
| enhancedlinks_tool._enhanced_links[self.modulo.UID()] = { | ||
| "getObjSize": "1 KB", | ||
| "mime_type": "text/plain", | ||
| } | ||
|
|
||
| # Start from the broken cached mime type. | ||
| self.assertEqual( | ||
| enhancedlinks_tool.get_enhanced_link(self.modulo.UID())["mime_type"], | ||
| "text/plain", | ||
| ) | ||
|
|
||
| # The upgrade reindexes Modulo mime_type and refreshes enhanced links. | ||
| to_7321(self.portal) | ||
|
|
||
| # After the refresh the cache must reflect the PDF mime type. | ||
| self.assertEqual( | ||
| enhancedlinks_tool.get_enhanced_link(self.modulo.UID())["mime_type"], | ||
| "application/pdf", | ||
| ) | ||
|
|
||
| def test_modulo_base_tool_mime_type(self): | ||
| # Without any stale cache, the tool should already have the correct | ||
| # mime type for the Modulo (taken from file_principale). | ||
| enhancedlinks_tool = api.portal.get_tool("portal_enhancedlinks") | ||
| result = enhancedlinks_tool.get_enhanced_link(self.modulo.UID()) | ||
| self.assertEqual(result["mime_type"], "application/pdf") | ||
|
|
||
| def test_modulo_mime_type_indexer(self): | ||
| # The indexer should return the correct mime type for the Modulo. | ||
|
|
||
| catalog = api.portal.get_tool("portal_catalog") | ||
| results = catalog(UID=self.modulo_2.UID()) | ||
| brain = results[0] | ||
|
|
||
| self.assertEqual(brain.mime_type, "application/pdf") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.