Projet

Général

Profil

0001-workflows-check-on-import-if-mail_template-exists-41.patch

Lauréline Guérin, 03 juillet 2020 15:54

Télécharger (2,8 ko)

Voir les différences:

Subject: [PATCH] workflows: check on import if mail_template exists (#41832)

 tests/test_workflow_import.py | 28 ++++++++++++++++++++++++----
 wcs/workflows.py              | 11 +++++++++++
 2 files changed, 35 insertions(+), 4 deletions(-)
tests/test_workflow_import.py
1 1
# -*- coding: utf-8 -*-
2 2

  
3 3
import pytest
4
import sys
5
import shutil
6 4
import xml.etree.ElementTree as ET
7 5

  
8 6
from django.utils.six import BytesIO
9
from quixote import cleanup
10
from wcs import publisher
11 7

  
12 8
from wcs.formdef import FormDef
9
from wcs.mail_templates import MailTemplate
13 10
from wcs.workflows import (
14 11
    Workflow, CommentableWorkflowStatusItem, WorkflowCriticalityLevel,
15 12
    WorkflowBackofficeFieldsFormDef, SendmailWorkflowStatusItem,
......
807 804

  
808 805
    wf.store()
809 806
    assert_import_export_works(wf, include_id=True)
807

  
808

  
809
def test_worklow_with_mail_template(pub):
810
    mail_template = MailTemplate(name='test mail template')
811
    mail_template.subject = 'test subject'
812
    mail_template.body = 'test body'
813
    mail_template.store()
814

  
815
    wf = Workflow(name='test mail template')
816
    st1 = wf.add_status('Status1')
817
    item = SendmailWorkflowStatusItem()
818
    item.to = ['_receiver']
819
    item.mail_template = mail_template.slug
820
    st1.items.append(item)
821
    item.parent = st1
822
    wf.store()
823
    assert_import_export_works(wf, include_id=True)
824

  
825
    # import with non existing mail template
826
    MailTemplate.wipe()
827
    export = ET.tostring(wf.export_to_xml(include_id=True))
828
    with pytest.raises(WorkflowImportError, match='Unknown referenced mail template'):
829
        Workflow.import_from_xml_tree(ET.fromstring(export), include_id=True)
wcs/workflows.py
2099 2099
            del odict['parent']
2100 2100
        return odict
2101 2101

  
2102
    def mail_template_init_with_xml(self, elem, charset, include_id=False):
2103
        if elem is None:
2104
            self.mail_template = None
2105
            return
2106
        value = xml_node_text(elem)
2107
        mail_template = MailTemplate.get_by_slug(value)
2108
        if not mail_template:
2109
            raise WorkflowImportError(N_('Unknown referenced mail template (%s)'), (value,))
2110
        self.mail_template = value
2111
        return
2112

  
2102 2113
    def attachments_init_with_xml(self, elem, charset, include_id=False):
2103 2114
        if elem is None:
2104 2115
            self.attachments = None
2105
-