summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2015-09-09 15:27:16 +0200
committerChristophe Simonis <chs@odoo.com>2015-09-09 15:38:12 +0200
commit5e1eb5f34c9aebd3ce04d6b4153b7bb9363a6ed0 (patch)
tree544235da961e3efea071be41d00017b7259f9a92 /addons
parent1e153e8aa56e71a196e46ce0b23ff9ada17e3660 (diff)
[IMP] mail: avoid followers with dissociative identity disorder
Diffstat (limited to 'addons')
-rw-r--r--addons/mail/models/mail_followers.py1
-rw-r--r--addons/mail/tests/test_mail_followers.py16
2 files changed, 17 insertions, 0 deletions
diff --git a/addons/mail/models/mail_followers.py b/addons/mail/models/mail_followers.py
index 05250a31de4..2dd62582b1d 100644
--- a/addons/mail/models/mail_followers.py
+++ b/addons/mail/models/mail_followers.py
@@ -128,4 +128,5 @@ class Followers(models.Model):
_sql_constraints = [
('mail_followers_res_partner_res_model_id_uniq', 'unique(res_model,res_id,partner_id)', 'Error, a partner cannot follow twice the same object.'),
('mail_followers_res_channel_res_model_id_uniq', 'unique(res_model,res_id,channel_id)', 'Error, a channel cannot follow twice the same object.'),
+ ('partner_xor_channel', 'CHECK((partner_id IS NULL) != (channel_id IS NULL))', 'Error: A follower must be either a partner or a channel (but not both).')
]
diff --git a/addons/mail/tests/test_mail_followers.py b/addons/mail/tests/test_mail_followers.py
index 7890e91294a..3342dcced8b 100644
--- a/addons/mail/tests/test_mail_followers.py
+++ b/addons/mail/tests/test_mail_followers.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
+from psycopg2 import IntegrityError
from openerp.addons.mail.tests.common import TestMail
@@ -102,3 +103,18 @@ class TestMailFollowers(TestMail):
('partner_id', '=', self.user_employee.partner_id.id)])
self.assertEqual(len(follower), 1)
self.assertEqual(follower.subtype_ids, self.mt_mg_nodef | self.mt_al_nodef)
+
+ def test_no_DID(self):
+ """Test that a follower cannot suffer from dissociative identity disorder.
+ It cannot be both a partner and a channel.
+ """
+ test_channel = self.env['mail.channel'].create({
+ 'name': 'I used to be schizo, but now we are alright.'
+ })
+ with self.assertRaises(IntegrityError):
+ self.env['mail.followers'].create({
+ 'res_model': 'mail.channel',
+ 'res_id': test_channel.id,
+ 'partner_id': self.user_employee.partner_id.id,
+ 'channel_id': self.group_pigs.id,
+ })