Repository navigation
PARAF-550: Formalised the sent filename generation in ISignable.get_filename #49
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from imio.esign.adapters import DefaultContextUidProvider | ||
| from imio.esign.adapters import ISignable | ||
| from imio.esign.adapters import SignableAdapter | ||
| from imio.esign.interfaces import IContextUidProvider | ||
| from imio.esign.interfaces import IItemOrderProvider | ||
| from imio.esign.tests.base import BaseEsignTest | ||
|
|
@@ -35,3 +37,25 @@ def test_get_item_order(self): | |
| empty = api.content.create(container=self.portal, type="Folder", id="empty-folder") | ||
| provider = getAdapter(empty, IItemOrderProvider) | ||
| self.assertEqual(provider.get_item_order(), {}) | ||
|
|
||
|
|
||
| class TestSignableAdapter(BaseEsignTest): | ||
|
|
||
| def test_get_filename(self): | ||
| annex = self.portal["folder0"]["annex0"] | ||
| adapter = getAdapter(annex.aq_parent, ISignable) | ||
| self.assertIsInstance(adapter, SignableAdapter) | ||
| self.assertEqual(adapter.get_filename(annex), u"annex0.pdf") | ||
| # a name already used in the session gets a numbered suffix | ||
| self.assertEqual(adapter.get_filename(annex, existing_files=["annex0"]), u"annex0-1.pdf") | ||
| self.assertEqual(adapter.get_filename(annex, existing_files=["annex0", "annex0-1"]), u"annex0-2.pdf") | ||
| # a __<uid> suffix is kept: imio.zamqp parses it back | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ce fonctionnement est propre à dmsmail mais çà pourrait devenir le fonctionnement de base (pas inutile d'avoir l'uid dans le nom du fichier en cas de debug ou autre) mais le problème actuellement c'est que çà apparaît sans doute dans l'interface de Cosi (à vérifier), si il y a la notion de "friendly pdf name" dans Cosi avec possibilité d'afficher un titre qui n'est pas l'id du fichier pdf, çà pourrait rentrer dans le comportement par défaut...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| annex.file.filename = u"Rapport__{}.pdf".format(annex.UID()) | ||
| self.assertEqual(adapter.get_filename(annex), u"Rapport__{}.pdf".format(annex.UID())) | ||
| # and it survives deduplication, the suffix landing after the uid | ||
| self.assertEqual( | ||
| adapter.get_filename(annex, existing_files=["Rapport__{}".format(annex.UID())]), | ||
| u"Rapport__{}-1.pdf".format(annex.UID()), | ||
| ) | ||
| annex.file.filename = None | ||
| self.assertEqual(adapter.get_filename(annex), u"no_filename.pdf") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """events tests for this package.""" | ||
| from imio.esign.tests.base import BaseEsignTest | ||
| from imio.esign.utils import add_files_to_session | ||
| from zope.event import notify | ||
| from zope.lifecycleevent import ObjectModifiedEvent | ||
|
|
||
|
|
||
| class TestEvents(BaseEsignTest): | ||
| def test_on_categorized_annex_updated(self): | ||
| """Renaming an annex keeps its session filename unique, without conflicting with itself.""" | ||
| signers = [("user1", "user1@sign.com", "User 1", "Position 1")] | ||
| annex0 = self.portal["folder0"]["annex0"] | ||
| annex2 = self.portal["folder0"]["annex2"] | ||
| sid, session = add_files_to_session(signers, (annex0.UID(), annex2.UID()))[-1] | ||
| self.assertEqual([f["filename"] for f in session["files"]], [u"annex0.pdf", u"annex2.pdf"]) | ||
| # renamed to a name already used in the session: deduplicated | ||
| annex2.file.filename = u"annex0.pdf" | ||
| notify(ObjectModifiedEvent(annex2)) | ||
| self.assertEqual([f["filename"] for f in session["files"]], [u"annex0.pdf", u"annex0-1.pdf"]) | ||
| # updated again: the generated name is the one it already has, it must not drift to annex0-2.pdf | ||
| annex2.setTitle("New Annex 2") | ||
| notify(ObjectModifiedEvent(annex2)) | ||
| self.assertEqual([f["filename"] for f in session["files"]], [u"annex0.pdf", u"annex0-1.pdf"]) | ||
| self.assertEqual(session["files"][1]["title"], "New Annex 2") |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ici le
if f["uid"] != annex_uidpeut être utile si le nom précédent correspond au nouveau nom généré par get_correct_id, donc bien vu, mais on pourrait même ajouter un test :-)