Add electronic mail tests
This commit is contained in:
parent
fdb49c47a2
commit
1280bc27ba
|
@ -438,10 +438,6 @@ class SendTemplateStart(ModelView):
|
|||
help='Total emails to send')
|
||||
template = fields.Many2One("electronic.mail.template", 'Template')
|
||||
|
||||
@staticmethod
|
||||
def default_use_tmpl_fields():
|
||||
return True
|
||||
|
||||
|
||||
class SendTemplate(Wizard):
|
||||
"Send Email from template"
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
========================
|
||||
Electronic Mail Scenario
|
||||
========================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Install electronic_mail::
|
||||
|
||||
>>> config = activate_modules('electronic_mail')
|
|
@ -2,13 +2,10 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
import unittest
|
||||
|
||||
import doctest
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
from trytond.tests.test_tryton import suite as test_suite
|
||||
from trytond.tests.test_tryton import doctest_teardown
|
||||
from trytond.tests.test_tryton import doctest_checker
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.tests.tools import activate_modules
|
||||
from trytond.pool import Pool
|
||||
|
||||
|
||||
class ElectronicMailTestCase(ModuleTestCase):
|
||||
|
@ -16,13 +13,61 @@ class ElectronicMailTestCase(ModuleTestCase):
|
|||
module = 'electronic_mail'
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(ElectronicMailTestCase, cls).setUpClass()
|
||||
activate_modules(['party', 'electronic_mail'])
|
||||
|
||||
@with_transaction()
|
||||
def test_template(self):
|
||||
'Test electronic mail template'
|
||||
pool = Pool()
|
||||
Party = pool.get('party.party')
|
||||
Model = pool.get('ir.model')
|
||||
Template = pool.get('electronic.mail.template')
|
||||
Lang = pool.get('ir.lang')
|
||||
|
||||
lang, = Lang.search([('code', '=', 'ca')])
|
||||
mparty, = Model.search([('model', '=', 'party.party')])
|
||||
|
||||
template, = Template.create([{
|
||||
'name': 'Test Party',
|
||||
'model': mparty,
|
||||
'from_': 'from@domain.com',
|
||||
'sender': 'sender@domain.com',
|
||||
'to': "${record.get_mechanism('email') or ''}",
|
||||
'cc': 'suport@domain.com',
|
||||
'bcc': 'bbc@domain.com',
|
||||
'subject': 'Email ${record.name}',
|
||||
'language': "${record.lang and record.lang.code or 'en'}",
|
||||
'plain': 'Hello ${record.name}',
|
||||
'html': 'Hello <strong>${record.name}</strong>',
|
||||
}])
|
||||
self.assertEqual(template.wizard.name, 'Test Party')
|
||||
|
||||
party, = Party.create([{
|
||||
'name': 'Iona',
|
||||
'lang': lang.id,
|
||||
'contact_mechanisms': [('create', [{
|
||||
'type': 'email',
|
||||
'value': 'iona@domain.com',
|
||||
}])]
|
||||
}])
|
||||
self.assertEqual(party.get_mechanism('email'), 'iona@domain.com')
|
||||
self.assertEqual(template.eval(template.language, party), 'ca')
|
||||
|
||||
data, = template.pre_render([party])
|
||||
self.assertEqual(data['to'], 'iona@domain.com')
|
||||
self.assertEqual(data['plain'], 'Hello Iona')
|
||||
self.assertEqual(data['subject'], 'Email Iona')
|
||||
|
||||
data['subject'] = 'A coffe break, ${record.name}'
|
||||
val, = Template.render(template, [party], data)
|
||||
self.assertEqual(val['subject'], 'A coffe break, Iona')
|
||||
|
||||
|
||||
def suite():
|
||||
suite = test_suite()
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||
ElectronicMailTestCase))
|
||||
suite.addTests(doctest.DocFileSuite(
|
||||
'scenario_electronic_mail.rst',
|
||||
tearDown=doctest_teardown, encoding='utf-8',
|
||||
checker=doctest_checker,
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
ElectronicMailTestCase))
|
||||
return suite
|
||||
|
|
|
@ -3,6 +3,7 @@ version=4.3.0
|
|||
depends:
|
||||
ir
|
||||
activity
|
||||
smtp
|
||||
xml:
|
||||
electronic_mail.xml
|
||||
template.xml
|
||||
|
|
Loading…
Reference in New Issue