tests: add tests on sendmail workflow item
This commit is contained in:
parent
21f72e3cd7
commit
aaa359c97f
|
@ -7,7 +7,7 @@ from quixote.http_request import HTTPRequest
|
|||
from wcs.formdef import FormDef
|
||||
from wcs.qommon import sessions
|
||||
from wcs.roles import Role
|
||||
from wcs.workflows import WorkflowStatusItem
|
||||
from wcs.workflows import WorkflowStatusItem, SendmailWorkflowStatusItem
|
||||
from wcs.wf.anonymise import AnonymiseWorkflowStatusItem
|
||||
from wcs.wf.dispatch import DispatchWorkflowStatusItem
|
||||
from wcs.wf.jump import JumpWorkflowStatusItem
|
||||
|
@ -15,7 +15,7 @@ from wcs.wf.register_comment import RegisterCommenterWorkflowStatusItem
|
|||
from wcs.wf.remove import RemoveWorkflowStatusItem
|
||||
from wcs.wf.roles import AddRoleWorkflowStatusItem, RemoveRoleWorkflowStatusItem
|
||||
|
||||
from utilities import create_temporary_pub, MockSubstitutionVariables
|
||||
from utilities import create_temporary_pub, MockSubstitutionVariables, emails
|
||||
|
||||
def setup_module(module):
|
||||
cleanup()
|
||||
|
@ -242,3 +242,86 @@ def test_register_comment():
|
|||
item.comment = '<div>[foo]</div>'
|
||||
item.perform(formdata)
|
||||
assert formdata.evolution[-1].display_parts()[-1] == '<div>1 < 3</div>'
|
||||
|
||||
def test_email():
|
||||
pub.substitutions.feed(MockSubstitutionVariables())
|
||||
|
||||
formdef = FormDef()
|
||||
formdef.name = 'baz'
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.just_created()
|
||||
formdata.store()
|
||||
|
||||
user = pub.user_class(name='foo')
|
||||
user.email = 'zorg@localhost'
|
||||
user.store()
|
||||
|
||||
Role.wipe()
|
||||
role1 = Role(name='foo')
|
||||
role1.emails = ['foo@localhost']
|
||||
role1.store()
|
||||
|
||||
role2 = Role(name='bar')
|
||||
role2.emails = ['bar@localhost', 'baz@localhost']
|
||||
role2.store()
|
||||
|
||||
emails.empty()
|
||||
# send using an uncompleted element
|
||||
item = SendmailWorkflowStatusItem()
|
||||
item.perform(formdata) # nothing
|
||||
assert emails.count() == 0
|
||||
|
||||
item.to = [role1.id]
|
||||
item.perform(formdata) # no subject nor body
|
||||
assert emails.count() == 0
|
||||
|
||||
item.subject = 'foobar'
|
||||
item.perform(formdata) # no body
|
||||
assert emails.count() == 0
|
||||
|
||||
# send for real
|
||||
item.body = 'baz'
|
||||
item.perform(formdata)
|
||||
assert emails.count() == 1
|
||||
assert emails.get('foobar')
|
||||
assert emails.get('foobar')['kwargs']['email_rcpt'] == ['foo@localhost']
|
||||
|
||||
# two recipients
|
||||
emails.empty()
|
||||
item.to = [role1.id, role2.id]
|
||||
item.perform(formdata)
|
||||
assert emails.count() == 1
|
||||
assert emails.get('foobar')['kwargs']['email_rcpt'] is None
|
||||
assert emails.get('foobar')['kwargs']['bcc'] == ['foo@localhost',
|
||||
'bar@localhost', 'baz@localhost']
|
||||
|
||||
# submitter as recipient, no known email address
|
||||
emails.empty()
|
||||
item.to = ['_submitter']
|
||||
item.perform(formdata)
|
||||
assert emails.count() == 0
|
||||
|
||||
# submitter as recipient, known email address
|
||||
emails.empty()
|
||||
formdata.user_id = user.id
|
||||
formdata.store()
|
||||
item.perform(formdata)
|
||||
assert emails.count() == 1
|
||||
assert emails.get('foobar')['kwargs']['email_rcpt'] == ['zorg@localhost']
|
||||
|
||||
# computed recipient
|
||||
emails.empty()
|
||||
item.to = ['=email']
|
||||
item.perform(formdata)
|
||||
assert emails.count() == 1
|
||||
assert emails.get('foobar')['kwargs']['email_rcpt'] == ['sub@localhost']
|
||||
|
||||
# string as recipient
|
||||
emails.empty()
|
||||
item.to = 'xyz@localhost'
|
||||
item.perform(formdata)
|
||||
assert emails.count() == 1
|
||||
assert emails.get('foobar')['kwargs']['email_rcpt'] == ['xyz@localhost']
|
||||
|
|
|
@ -47,9 +47,15 @@ class EmailsMocking(object):
|
|||
def get(self, subject):
|
||||
return self.emails.get(subject)
|
||||
|
||||
def empty(self):
|
||||
self.emails = {}
|
||||
|
||||
def count(self):
|
||||
return len(self.emails)
|
||||
|
||||
emails = EmailsMocking()
|
||||
|
||||
|
||||
class MockSubstitutionVariables(object):
|
||||
def get_substitution_variables(self):
|
||||
return {'bar': 'Foobar', 'foo': '1 < 3'}
|
||||
return {'bar': 'Foobar', 'foo': '1 < 3', 'email': 'sub@localhost'}
|
||||
|
|
Loading…
Reference in New Issue