def test_shared(self): create_doc(self.factory.user) self.factory.xfer = DocumentShow() self.calljson('/lucterios.documents/documentShow', {"document": "5"}, False) self.assert_observer('core.custom', 'lucterios.documents', 'documentShow') self.assert_count_equal('', 9) self.assert_json_equal('LABELFORM', 'name', "doc1.png") self.assertEqual(len(self.json_actions), 3) self.factory.xfer = DocumentChangeShared() self.calljson('/lucterios.documents/documentChangeShared', {"document": "5"}, False) self.assert_observer('core.acknowledge', 'lucterios.documents', 'documentChangeShared') self.factory.xfer = DocumentShow() self.calljson('/lucterios.documents/documentShow', {"document": "5"}, False) self.assert_observer('core.custom', 'lucterios.documents', 'documentShow') self.assert_count_equal('', 10) self.assert_json_equal('LABELFORM', 'name', "doc1.png") self.assert_json_equal('EDIT', 'shared_link', "http://testserver/lucterios.documents/downloadFile?", True) self.assertEqual(len(self.json_actions), 3) shared_link = self.get_json_path('shared_link').split('?')[-1].split('&') self.assertEqual(len(shared_link), 2) self.assertEqual(shared_link[0][:7], 'shared=') shared_key = shared_link[0][7:] self.assertEqual(shared_link[1], 'filename=doc1.png') self.factory.xfer = DownloadFile() self.call_ex('/lucterios.documents/downloadFile', {"shared": shared_key, "filename": "doc1.png"}, False) file_content = self.response.getvalue() self.assertEqual(file_content[:4], b'\x89PNG') self.factory.xfer = DocumentChangeShared() self.calljson('/lucterios.documents/documentChangeShared', {"document": "5"}, False) self.assert_observer('core.acknowledge', 'lucterios.documents', 'documentChangeShared') self.factory.xfer = DocumentShow() self.calljson('/lucterios.documents/documentShow', {"document": "5"}, False) self.assert_observer('core.custom', 'lucterios.documents', 'documentShow') self.assert_count_equal('', 9) self.assert_json_equal('LABELFORM', 'name', "doc1.png") self.assertEqual(len(self.json_actions), 3) self.factory.xfer = DownloadFile() self.call_ex('/lucterios.documents/downloadFile', {"shared": shared_key, "filename": "doc1.png"}, False) file_content = self.response.getvalue().decode() self.assertEqual(file_content, 'Fichier non trouvé !')
def test_cannot_view(self): self.create_doc() self.factory.xfer = DocumentShow() self.call('/lucterios.documents/documentShow', {"document": "3"}, False) self.assert_observer('core.exception', 'lucterios.documents', 'documentShow') self.assert_xml_equal('EXCEPTION/MESSAGE', "Visualisation non autorisée !") self.factory.xfer = DocumentAddModify() self.call('/lucterios.documents/documentAddModify', {"document": "3"}, False) self.assert_observer('core.exception', 'lucterios.documents', 'documentAddModify') self.assert_xml_equal('EXCEPTION/MESSAGE', "Visualisation non autorisée !") self.factory.xfer = DocumentDel() self.call('/lucterios.documents/documentDel', {"document": "3"}, False) self.assert_observer('core.exception', 'lucterios.documents', 'documentDel') self.assert_xml_equal('EXCEPTION/MESSAGE', "Visualisation non autorisée !")
def test_readonly(self): current_date = create_doc(self.factory.user) self.factory.xfer = DocumentShow() self.calljson('/lucterios.documents/documentShow', {"document": "6"}, False) self.assert_observer('core.custom', 'lucterios.documents', 'documentShow') self.assertEqual(self.json_meta['title'], "Afficher le document") self.assert_count_equal('', 9) self.assert_comp_equal(('LABELFORM', 'name'), "doc2.png", (1, 0, 2, 1)) self.assert_comp_equal(('LABELFORM', 'parent'), ">truc1", (1, 1, 2, 1)) self.assert_comp_equal(('LABELFORM', 'description'), "doc 2", (1, 2, 2, 1)) self.assert_comp_equal(('LABELFORM', 'modifier'), None, (1, 3, 1, 1)) self.assert_comp_equal(('LABELFORM', 'date_modification'), current_date.isoformat(), (2, 3, 1, 1), (0, 22)) self.assert_comp_equal(('LABELFORM', 'creator'), "empty", (1, 4, 1, 1)) self.assert_comp_equal(('LABELFORM', 'date_creation'), current_date.isoformat(), (2, 4, 1, 1), (0, 22)) self.assertEqual(len(self.json_actions), 2) self.factory.xfer = DocumentAddModify() self.calljson('/lucterios.documents/documentAddModify', {"document": "6"}, False) self.assert_observer('core.exception', 'lucterios.documents', 'documentAddModify') self.assert_json_equal('', 'message', "Écriture non autorisée !") self.factory.xfer = ContainerDel() self.calljson('/lucterios.documents/containerDel', {"container": "6"}, False) self.assert_observer('core.exception', 'lucterios.documents', 'containerDel') self.assert_json_equal('', 'message', "Écriture non autorisée !")
def test_saveagain(self): current_date = create_doc(self.factory.user) self.factory.xfer = DocumentShow() self.calljson('/lucterios.documents/documentShow', {"document": "5"}, False) self.assert_observer('core.custom', 'lucterios.documents', 'documentShow') self.assertEqual(self.json_meta['title'], "Afficher le document") self.assert_count_equal('', 9) self.assert_comp_equal(('LABELFORM', 'name'), "doc1.png", (1, 0, 2, 1)) self.assert_comp_equal(('LABELFORM', 'parent'), ">truc2", (1, 1, 2, 1)) self.assert_comp_equal(('LABELFORM', 'description'), "doc 1", (1, 2, 2, 1)) self.assert_comp_equal(('LABELFORM', 'modifier'), None, (1, 3, 1, 1)) self.assert_comp_equal(('LABELFORM', 'date_modification'), current_date.isoformat(), (2, 3, 1, 1), (0, 22)) self.assert_comp_equal(('LABELFORM', 'creator'), "empty", (1, 4, 1, 1)) self.assert_comp_equal(('LABELFORM', 'date_creation'), current_date.isoformat(), (2, 4, 1, 1), (0, 22)) self.assertEqual(len(self.json_actions), 3) self.factory.xfer = DocumentAddModify() self.calljson('/lucterios.documents/documentAddModify', {'SAVE': 'YES', "document": "5", 'description': 'old doc', 'parent': 3}, False) self.assert_observer('core.acknowledge', 'lucterios.documents', 'documentAddModify') docs = DocumentContainer.objects.all().order_by('id') self.assertEqual(len(docs), 3) self.assertEqual(docs[0].id, 5) self.assertEqual(docs[0].parent.id, 3) self.assertEqual(docs[0].name, 'doc1.png') self.assertEqual(docs[0].description, "old doc") self.assertEqual(docs[0].creator.username, "empty") self.assertEqual(docs[0].modifier.username, "empty") self.assertNotEqual(docs[0].date_creation, docs[0].date_modification)
def show(self, xfer): xfer.move_components('body', 0, 2) obj_recipients = xfer.get_components('recipients') new_recipients = XferCompGrid('recipient_list') new_recipients.tab = obj_recipients.tab new_recipients.set_location(obj_recipients.col, obj_recipients.row, obj_recipients.colspan) new_recipients.add_header("model", _('model')) new_recipients.add_header("filter", _('filter')) compid = 0 for model_title, filter_desc in self.item.recipients_description: new_recipients.set_value(compid, "model", model_title) new_recipients.set_value(compid, "filter", filter_desc) compid += 1 if compid == 0: xfer.remove_component('contact_nb') if not will_mail_send() or (len(self.item.get_contacts(False)) == 0): xfer.remove_component('contact_noemail') xfer.remove_component('recipients') new_recipients.add_action_notified(xfer, 'recipient_list') xfer.tab = new_recipients.tab xfer.add_component(new_recipients) old_documents = xfer.get_components('documents') xfer.remove_component('documents') new_documents = XferCompGrid('document') new_documents.tab = old_documents.tab new_documents.set_location(old_documents.col, old_documents.row, old_documents.colspan) new_documents.set_model(self.item.documents.all(), ["name", "description", "date_modification"], xfer) new_documents.add_action(xfer.request, DocumentShow.get_action( TITLE_EDIT, "images/show.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_SINGLE) if self.item.status == 0: new_documents.add_action(xfer.request, MessageRemoveDoc.get_action( _("Remove"), "images/delete.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_MULTI) new_documents.add_action(xfer.request, MessageInsertDoc.get_action( _("Insert"), "images/add.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_NONE) xfer.tab = new_documents.tab xfer.add_component(new_documents) return LucteriosEditor.show(self, xfer)
def show(self, xfer): obj_body = xfer.get_components('body') obj_body.value = "{[div style='border:1px solid black;background-color:#EEE;padding:5px;']}%s{[div]}" % obj_body.value xfer.move_components('body', 0, 2) obj_recipients = xfer.get_components('recipients') new_recipients = XferCompGrid('recipient_list') new_recipients.tab = obj_recipients.tab new_recipients.set_location(obj_recipients.col, obj_recipients.row, obj_recipients.colspan) new_recipients.add_header("model", _('model')) new_recipients.add_header("filter", _('filter')) compid = 0 for model_title, filter_desc in self.item.recipients_description: new_recipients.set_value(compid, "model", model_title) new_recipients.set_value(compid, "filter", filter_desc) compid += 1 if compid == 0: xfer.remove_component('contact_nb') if not will_mail_send() or (len(self.item.get_contacts(False)) == 0): xfer.remove_component('contact_noemail') xfer.remove_component('recipients') new_recipients.add_action_notified(xfer, 'recipient_list') xfer.tab = new_recipients.tab xfer.add_component(new_recipients) old_documents = xfer.get_components('attachments') xfer.remove_component('attachments') if xfer.item.is_dynamic: xfer.remove_component('__tab_3') xfer.remove_component('doc_in_link') xfer.remove_component('empty') else: new_documents = XferCompGrid('attachments') new_documents.tab = old_documents.tab new_documents.set_location(old_documents.col, old_documents.row, old_documents.colspan) new_documents.set_model(self.item.attachments.all(), ["name", "description", "date_modification"], xfer) new_documents.add_action(xfer.request, DocumentShow.get_action(TITLE_EDIT, "images/show.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_SINGLE) if self.item.status == 0: new_documents.add_action(xfer.request, MessageRemoveDoc.get_action(_("Remove"), "images/delete.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_MULTI) new_documents.add_action(xfer.request, MessageInsertDoc.get_action(_("Insert"), "images/add.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_NONE) xfer.tab = new_documents.tab xfer.add_component(new_documents) contact_nb = xfer.get_components('contact_nb') if (contact_nb is not None) and (self.item.nb_total > 0): xfer.tab = contact_nb.tab xfer.fill_from_model(contact_nb.col, contact_nb.row + 1, True, [((_('statistic'), 'statistic'),)]) return LucteriosEditor.show(self, xfer)
def test_cannot_view(self): create_doc(self.factory.user) self.factory.xfer = DocumentShow() self.calljson('/lucterios.documents/documentShow', {"document": "7"}, False) self.assert_observer('core.exception', 'lucterios.documents', 'documentShow') self.assert_json_equal('', 'message', "Visualisation non autorisée !") self.factory.xfer = DocumentAddModify() self.calljson('/lucterios.documents/documentAddModify', {"document": "7"}, False) self.assert_observer('core.exception', 'lucterios.documents', 'documentAddModify') self.assert_json_equal('', 'message', "Visualisation non autorisée !") self.factory.xfer = ContainerDel() self.calljson('/lucterios.documents/containerDel', {"container": "7"}, False) self.assert_observer('core.exception', 'lucterios.documents', 'containerDel') self.assert_json_equal('', 'message', "Visualisation non autorisée !")
def test_saveagain(self): current_date = self.create_doc() self.factory.xfer = DocumentShow() self.call('/lucterios.documents/documentShow', {"document": "1"}, False) self.assert_observer('core.custom', 'lucterios.documents', 'documentShow') self.assert_xml_equal('TITLE', "Afficher le document") self.assert_count_equal('COMPONENTS/*', 9) self.assert_comp_equal('COMPONENTS/LABELFORM[@name="folder"]', ">truc2", (1, 0, 2, 1)) self.assert_comp_equal('COMPONENTS/LABELFORM[@name="name"]', "doc1.png", (1, 1, 2, 1)) self.assert_comp_equal('COMPONENTS/LABELFORM[@name="description"]', "doc 1", (1, 2, 2, 1)) self.assert_comp_equal('COMPONENTS/LABELFORM[@name="modifier"]', '---', (1, 3, 1, 1)) self.assert_comp_equal( 'COMPONENTS/LABELFORM[@name="date_modification"]', formats.date_format(current_date, "DATETIME_FORMAT"), (2, 3, 1, 1)) self.assert_comp_equal('COMPONENTS/LABELFORM[@name="creator"]', "empty", (1, 4, 1, 1)) self.assert_comp_equal( 'COMPONENTS/LABELFORM[@name="date_creation"]', formats.date_format(current_date, "DATETIME_FORMAT"), (2, 4, 1, 1)) self.assert_count_equal('ACTIONS/ACTION', 2) self.factory.xfer = DocumentAddModify() self.call('/lucterios.documents/documentAddModify', { 'SAVE': 'YES', "document": "1", 'description': 'old doc' }, False) docs = Document.objects.all().order_by('id') self.assertEqual(len(docs), 3) self.assertEqual(docs[0].folder.id, 2) self.assertEqual(docs[0].name, 'doc1.png') self.assertEqual(docs[0].description, "old doc") self.assertEqual(docs[0].creator.username, "empty") self.assertEqual(docs[0].modifier.username, "empty") self.assertNotEqual(docs[0].date_creation, docs[0].date_modification)
def test_readonly(self): current_date = self.create_doc() self.factory.xfer = DocumentShow() self.call('/lucterios.documents/documentShow', {"document": "2"}, False) self.assert_observer('core.custom', 'lucterios.documents', 'documentShow') self.assert_xml_equal('TITLE', "Afficher le document") self.assert_count_equal('COMPONENTS/*', 9) self.assert_comp_equal('COMPONENTS/LABELFORM[@name="folder"]', ">truc1", (1, 0, 2, 1)) self.assert_comp_equal('COMPONENTS/LABELFORM[@name="name"]', "doc2.png", (1, 1, 2, 1)) self.assert_comp_equal('COMPONENTS/LABELFORM[@name="description"]', "doc 2", (1, 2, 2, 1)) self.assert_comp_equal('COMPONENTS/LABELFORM[@name="modifier"]', '---', (1, 3, 1, 1)) self.assert_comp_equal( 'COMPONENTS/LABELFORM[@name="date_modification"]', formats.date_format(current_date, "DATETIME_FORMAT"), (2, 3, 1, 1)) self.assert_comp_equal('COMPONENTS/LABELFORM[@name="creator"]', "empty", (1, 4, 1, 1)) self.assert_comp_equal( 'COMPONENTS/LABELFORM[@name="date_creation"]', formats.date_format(current_date, "DATETIME_FORMAT"), (2, 4, 1, 1)) self.assert_count_equal('ACTIONS/ACTION', 1) self.factory.xfer = DocumentAddModify() self.call('/lucterios.documents/documentAddModify', {"document": "2"}, False) self.assert_observer('core.exception', 'lucterios.documents', 'documentAddModify') self.assert_xml_equal('EXCEPTION/MESSAGE', "Écriture non autorisée !") self.factory.xfer = DocumentDel() self.call('/lucterios.documents/documentDel', {"document": "2"}, False) self.assert_observer('core.exception', 'lucterios.documents', 'documentDel') self.assert_xml_equal('EXCEPTION/MESSAGE', "Écriture non autorisée !")
def show(self, xfer): xfer.move_components('body', 0, 2) obj_recipients = xfer.get_components('recipients') new_recipients = XferCompGrid('recipient_list') new_recipients.tab = obj_recipients.tab new_recipients.set_location(obj_recipients.col, obj_recipients.row, obj_recipients.colspan) new_recipients.add_header("model", _('model')) new_recipients.add_header("filter", _('filter')) compid = 0 for model_title, filter_desc in self.item.recipients_description: new_recipients.set_value(compid, "model", model_title) new_recipients.set_value(compid, "filter", filter_desc) compid += 1 if compid == 0: xfer.remove_component('contact_nb') if not will_mail_send() or (len(self.item.get_contacts(False)) == 0): xfer.remove_component('contact_noemail') xfer.remove_component('recipients') new_recipients.add_action_notified(xfer, 'recipient_list') xfer.tab = new_recipients.tab xfer.add_component(new_recipients) old_documents = xfer.get_components('documents') xfer.remove_component('documents') new_documents = XferCompGrid('document') new_documents.tab = old_documents.tab new_documents.set_location(old_documents.col, old_documents.row, old_documents.colspan) new_documents.set_model(self.item.documents.all(), ["name", "description", "date_modification"], xfer) new_documents.add_action(xfer.request, DocumentShow.get_action(TITLE_EDIT, "images/show.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_SINGLE) if self.item.status == 0: new_documents.add_action(xfer.request, MessageRemoveDoc.get_action(_("Remove"), "images/delete.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_MULTI) new_documents.add_action(xfer.request, MessageInsertDoc.get_action(_("Insert"), "images/add.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_NONE) xfer.tab = new_documents.tab xfer.add_component(new_documents) return LucteriosEditor.show(self, xfer)