[IMP] mail: avoid followers with dissociative identity disorder

This commit is contained in:
Christophe Simonis
2015-09-09 15:38:12 +02:00
parent 1e153e8aa5
commit 5e1eb5f34c
2 changed files with 17 additions and 0 deletions
+1
View File
@@ -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).')
]
+16
View File
@@ -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,
})