[IMP] test_mail: move some data into demo and update tests accordingly

Creating data directly in tests was done when tests were located in mail
module to avoid creating real data or demo. Now that mail tests have their
own module we can create demo data and use them in tests. It is simpler to
have demo data for things like subtype and email templates to ease
understanding and reuse.
This commit is contained in:
Thibault Delavallée
2017-12-12 15:46:37 +01:00
parent 56ae134bb2
commit cde06d5f5c
6 changed files with 66 additions and 24 deletions
+2
View File
@@ -15,6 +15,8 @@ tests independently to functional aspects of other models. """,
],
'demo': [
'data/demo.xml',
'data/subtype_demo.xml',
'data/template_demo.xml',
],
'installable': True,
'application': False,
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="st_mail_test_full_umbrella_upd" model="mail.message.subtype">
<field name="name">Umbrella Changed Subtype</field>
<field name="description">Umbrella Changed</field>
<field name="res_model">mail.test.full</field>
<field name="default" eval="True"/>
<field name="internal" eval="False"/>
</record>
<record id="st_mail_test_default" model="mail.message.subtype">
<field name="name">Umbrella Default Subtype</field>
<field name="res_model">mail.test</field>
<field name="default" eval="True"/>
<field name="internal" eval="False"/>
</record>
<!-- when subscribing to mail.test umbrella, delegate to mail.test.full child -->
<record id="st_mail_test_child_full" model="mail.message.subtype">
<field name="name">Umbrella Child Full Subtype</field>
<field name="res_model">mail.test</field>
<field name="parent_id" eval="ref('test_mail.st_mail_test_full_umbrella_upd')"/>
<field name="relation_field">umbrella_id</field>
<field name="default" eval="False"/>
<field name="internal" eval="False"/>
</record>
</odoo>
+24
View File
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="mail_test_full_tracking_tpl" model="mail.template">
<field name="name">Mail Test Full: Tracking Template</field>
<field name="subject">Test Template</field>
<field name="partner_to">${object.customer_id.id | safe}</field>
<field name="body_html" type="xml"><p>Hello ${object.name}</p></field>
<field name="model_id" ref="test_mail.model_mail_test_full"/>
<field name="auto_delete" eval="True"/>
</record>
<record id="mail_test_tpl" model="mail.template">
<field name="name">Mail Test: Template</field>
<field name="subject">Post on ${object.name}</field>
<field name="partner_to">${object.customer_id.id}</field>
<field name="body_html" type="xml"><p>Adding stuff on ${object.name}</p></field>
<field name="model_id" ref="test_mail.model_mail_test"/>
<field name="auto_delete" eval="True"/>
</record>
<template id="mail_test_full_tracking_view">
<p><span t-esc="object.name"/> datetime has been updated to <span t-esc="object.datetime"/></p>
</template>
</odoo>
+3 -2
View File
@@ -62,13 +62,13 @@ class MailTestFull(models.Model):
if 'customer_id' in changes and record.mail_template:
res['customer_id'] = (record.mail_template, {'composition_mode': 'mass_mail'})
elif 'datetime' in changes:
res['datetime'] = ('mail.track_template', {'composition_mode': 'mass_mail'})
res['datetime'] = ('test_mail.mail_test_full_tracking_view', {'composition_mode': 'mass_mail'})
return res
def _track_subtype(self, init_values):
self.ensure_one()
if 'umbrella_id' in init_values and self.umbrella_id:
return 'mail.track_subtype_umbrella'
return 'test_mail.st_mail_test_full_umbrella_upd'
return super(MailTestFull, self)._track_subtype(init_values)
@@ -82,6 +82,7 @@ class MailTestAlias(models.Model):
name = fields.Char()
description = fields.Text()
customer_id = fields.Many2one('res.partner', 'Customer')
alias_id = fields.Many2one(
'mail.alias', 'Alias',
delegate=True)
@@ -123,6 +123,10 @@ class AdvancedFollowersTest(common.BaseFunctionalTest):
})
Subtype = cls.env['mail.message.subtype']
# clean demo data to avoid interferences
Subtype.search([('res_model', 'in', ['mail.test', 'mail.test.track'])]).unlink()
cls.sub_nodef = Subtype.create({'name': 'Sub NoDefault', 'default': False, 'res_model': 'mail.test'})
cls.sub_umb1 = Subtype.create({'name': 'Sub Umbrella1', 'default': False, 'res_model': 'mail.test.track'})
cls.sub_umb2 = Subtype.create({'name': 'Sub Umbrella2', 'default': False, 'res_model': 'mail.test.track'})
@@ -187,7 +191,7 @@ class AdvancedFollowersTest(common.BaseFunctionalTest):
'umbrella_id': umbrella.id,
})
all_defaults = self.env['mail.message.subtype'].search([('default', '=', True), '|', ('res_model', '=', 'mail.test.full'), ('res_model', '=', False)])
all_defaults = self.env['mail.message.subtype'].search([('default', '=', True), '|', ('res_model', '=', 'mail.test.track'), ('res_model', '=', False)])
external_defaults = all_defaults.filtered(lambda subtype: not subtype.internal)
self.assertEqual(sub1.message_partner_ids, self.user_portal.partner_id | self.user_employee.partner_id)
+4 -21
View File
@@ -26,17 +26,6 @@ class TestTracking(common.BaseFunctionalTest, common.MockEmails):
def setUp(self):
super(TestTracking, self).setUp()
self.track_subtype_umbrella = self.env['mail.message.subtype'].create({
'name': 'Umbrella',
'description': 'Umbrella Changed',
})
self.env['ir.model.data'].create({
'name': 'track_subtype_umbrella',
'model': 'mail.message.subtype',
'module': 'mail',
'res_id': self.track_subtype_umbrella.id
})
record = self.env['mail.test.full'].sudo(self.user_employee).with_context(self._quick_create_ctx).create({
'name': 'Test',
})
@@ -78,10 +67,10 @@ class TestTracking(common.BaseFunctionalTest, common.MockEmails):
""" Update some tracked fields linked to some subtype -> message with onchange + always tracked values """
self.record.message_subscribe(
partner_ids=[self.user_admin.partner_id.id],
subtype_ids=[self.track_subtype_umbrella.id]
subtype_ids=[self.env.ref('test_mail.st_mail_test_full_umbrella_upd').id]
)
umbrella = self.env['mail.test'].create({'name': 'Umbrella'})
umbrella = self.env['mail.test'].with_context(mail_create_nosubscribe=True).create({'name': 'Umbrella'})
self.record.write({
'name': 'Test2',
'email_from': 'noone@example.com',
@@ -89,7 +78,7 @@ class TestTracking(common.BaseFunctionalTest, common.MockEmails):
})
# one new message containing tracking; subtype linked to tracking
self.assertEqual(len(self.record.message_ids), 1)
self.assertEqual(self.record.message_ids.subtype_id, self.track_subtype_umbrella)
self.assertEqual(self.record.message_ids.subtype_id, self.env.ref('test_mail.st_mail_test_full_umbrella_upd'))
# no specific recipients except those following umbrella
self.assertEqual(self.record.message_ids.partner_ids, self.env['res.partner'])
@@ -104,13 +93,7 @@ class TestTracking(common.BaseFunctionalTest, common.MockEmails):
def test_message_track_template(self):
""" Update some tracked fields linked to some template -> message with onchange + always tracked values """
mail_template = self.env['mail.template'].create({
'model_id': self.env.ref('test_mail.model_mail_test_full').id,
'body_html': '<p>Hello ${object.name}</p>',
'subject': 'Test Template',
'partner_to': '${object.customer_id.id | safe}',
})
self.record.write({'mail_template': mail_template.id})
self.record.write({'mail_template': self.env.ref('test_mail.mail_test_full_tracking_tpl').id})
self.assertEqual(self.record.message_ids, self.env['mail.message'])
self.record.write({