diff options
| author | Raphael Collet <rco@openerp.com> | 2014-07-06 16:44:26 +0200 |
|---|---|---|
| committer | Antony Lesuisse <al@openerp.com> | 2014-07-06 17:05:41 +0200 |
| commit | cbe2dbb672a6c55d86f2e515f9d1cdfee426ef80 (patch) | |
| tree | d6ff62b719fce32392397783c961b734b1e4c50e /addons/mail/tests | |
| parent | d78192c489d3be66cd6487b39f5ce7ba4733a187 (diff) | |
[MERGE] new v8 api by rco
A squashed merge is required as the conversion of the apiculture branch from
bzr to git was not correctly done. The git history contains irrelevant blobs
and commits. This branch brings a lot of changes and fixes, too many to list
exhaustively.
- New orm api, objects are now used instead of ids
- Environements to encapsulates cr uid context while maintaining backward compatibility
- Field compute attribute is a new object oriented way to define function fields
- Shared browse record cache
- New onchange protocol
- Optional copy flag on fields
- Documentation update
- Dead code cleanup
- Lots of fixes
Diffstat (limited to 'addons/mail/tests')
| -rw-r--r-- | addons/mail/tests/common.py | 30 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_features.py | 14 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_gateway.py | 12 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_group.py | 2 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_message.py | 61 | ||||
| -rw-r--r-- | addons/mail/tests/test_message_read.py | 2 |
6 files changed, 59 insertions, 62 deletions
diff --git a/addons/mail/tests/common.py b/addons/mail/tests/common.py index d53a8078c96..5a5c28f95d7 100644 --- a/addons/mail/tests/common.py +++ b/addons/mail/tests/common.py @@ -24,30 +24,28 @@ from openerp.tests import common class TestMail(common.TransactionCase): - def _mock_smtp_gateway(self, *args, **kwargs): - return args[2]['Message-Id'] - def _init_mock_build_email(self): self._build_email_args_list = [] self._build_email_kwargs_list = [] - def _mock_build_email(self, *args, **kwargs): - """ Mock build_email to be able to test its values. Store them into - some internal variable for latter processing. """ - self._build_email_args_list.append(args) - self._build_email_kwargs_list.append(kwargs) - return self._build_email(*args, **kwargs) - def setUp(self): super(TestMail, self).setUp() cr, uid = self.cr, self.uid # Install mock SMTP gateway + test = self + + def build_email(self, *args, **kwargs): + test._build_email_args_list.append(args) + test._build_email_kwargs_list.append(kwargs) + return build_email.origin(self, *args, **kwargs) + + def send_email(self, cr, uid, message, *args, **kwargs): + return message['Message-Id'] + self._init_mock_build_email() - self._build_email = self.registry('ir.mail_server').build_email - self.registry('ir.mail_server').build_email = self._mock_build_email - self._send_email = self.registry('ir.mail_server').send_email - self.registry('ir.mail_server').send_email = self._mock_smtp_gateway + self.registry('ir.mail_server')._patch_method('build_email', build_email) + self.registry('ir.mail_server')._patch_method('send_email', send_email) # Usefull models self.ir_model = self.registry('ir.model') @@ -129,6 +127,6 @@ class TestMail(common.TransactionCase): def tearDown(self): # Remove mocks - self.registry('ir.mail_server').build_email = self._build_email - self.registry('ir.mail_server').send_email = self._send_email + self.registry('ir.mail_server')._revert_method('build_email') + self.registry('ir.mail_server')._revert_method('send_email') super(TestMail, self).tearDown() diff --git a/addons/mail/tests/test_mail_features.py b/addons/mail/tests/test_mail_features.py index 2bf7bb91264..fdd87bbcfab 100644 --- a/addons/mail/tests/test_mail_features.py +++ b/addons/mail/tests/test_mail_features.py @@ -280,7 +280,7 @@ class test_mail(TestMail): self.assertNotIn('res_id=%s' % group_pigs.id, url, 'notification email: link based on message should not contain res_id') - @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm') + @mute_logger('openerp.addons.mail.mail_thread', 'openerp.models') def test_12_inbox_redirection(self): """ Tests designed to test the inbox redirection of emails notification URLs. """ cr, uid, user_admin, group_pigs = self.cr, self.uid, self.user_admin, self.group_pigs @@ -654,7 +654,7 @@ class test_mail(TestMail): { 'attachment_ids': [(0, 0, _attachments[0]), (0, 0, _attachments[1])] }, context={ - 'default_composition_mode': 'reply', + 'default_composition_mode': 'comment', 'default_res_id': self.group_pigs_id, 'default_parent_id': message.id }) @@ -772,14 +772,13 @@ class test_mail(TestMail): def test_30_needaction(self): """ Tests for mail.message needaction. """ cr, uid, user_admin, user_raoul, group_pigs = self.cr, self.uid, self.user_admin, self.user_raoul, self.group_pigs - group_pigs_demo = self.mail_group.browse(cr, self.user_raoul_id, self.group_pigs_id) na_admin_base = self.mail_message._needaction_count(cr, uid, domain=[]) na_demo_base = self.mail_message._needaction_count(cr, user_raoul.id, domain=[]) # Test: number of unread notification = needaction on mail.message notif_ids = self.mail_notification.search(cr, uid, [ ('partner_id', '=', user_admin.partner_id.id), - ('read', '=', False) + ('is_read', '=', False) ]) na_count = self.mail_message._needaction_count(cr, uid, domain=[]) self.assertEqual(len(notif_ids), na_count, 'unread notifications count does not match needaction count') @@ -787,13 +786,14 @@ class test_mail(TestMail): # Do: post 2 message on group_pigs as admin, 3 messages as demo user for dummy in range(2): group_pigs.message_post(body='My Body', subtype='mt_comment') + raoul_pigs = group_pigs.sudo(user_raoul) for dummy in range(3): - group_pigs_demo.message_post(body='My Demo Body', subtype='mt_comment') + raoul_pigs.message_post(body='My Demo Body', subtype='mt_comment') # Test: admin has 3 new notifications (from demo), and 3 new needaction notif_ids = self.mail_notification.search(cr, uid, [ ('partner_id', '=', user_admin.partner_id.id), - ('read', '=', False) + ('is_read', '=', False) ]) self.assertEqual(len(notif_ids), na_admin_base + 3, 'Admin should have 3 new unread notifications') na_admin = self.mail_message._needaction_count(cr, uid, domain=[]) @@ -803,7 +803,7 @@ class test_mail(TestMail): # Test: demo has 0 new notifications (not a follower, not receiving its own messages), and 0 new needaction notif_ids = self.mail_notification.search(cr, uid, [ ('partner_id', '=', user_raoul.partner_id.id), - ('read', '=', False) + ('is_read', '=', False) ]) self.assertEqual(len(notif_ids), na_demo_base + 0, 'Demo should have 0 new unread notifications') na_demo = self.mail_message._needaction_count(cr, user_raoul.id, domain=[]) diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index 3fbf3d40405..1b16f151cdf 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -164,7 +164,7 @@ class TestMailgateway(TestMail): self.assertIn('<div dir="ltr">Should create a multipart/mixed: from gmail, <b>bold</b>, with attachment.<br clear="all"><div><br></div>', res.get('body', ''), 'message_parse: html version should be in body after parsing multipart/mixed') - @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm') + @mute_logger('openerp.addons.mail.mail_thread', 'openerp.models') def test_10_message_process(self): """ Testing incoming emails processing. """ cr, uid, user_raoul = self.cr, self.uid, self.user_raoul @@ -203,8 +203,8 @@ class TestMailgateway(TestMail): # Test: one group created by mailgateway administrator self.assertEqual(len(frog_groups), 1, 'message_process: a new mail.group should have been created') frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) - res = self.mail_group.perm_read(cr, uid, [frog_group.id], details=False) - self.assertEqual(res[0].get('create_uid'), uid, + res = self.mail_group.get_metadata(cr, uid, [frog_group.id])[0].get('create_uid') or [None] + self.assertEqual(res[0], uid, 'message_process: group should have been created by uid as alias_user__id is False on the alias') # Test: one message that is the incoming email self.assertEqual(len(frog_group.message_ids), 1, @@ -271,8 +271,8 @@ class TestMailgateway(TestMail): # Test: one group created by Raoul self.assertEqual(len(frog_groups), 1, 'message_process: a new mail.group should have been created') frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) - res = self.mail_group.perm_read(cr, uid, [frog_group.id], details=False) - self.assertEqual(res[0].get('create_uid'), self.user_raoul_id, + res = self.mail_group.get_metadata(cr, uid, [frog_group.id])[0].get('create_uid') or [None] + self.assertEqual(res[0], self.user_raoul_id, 'message_process: group should have been created by alias_user_id') # Test: one message that is the incoming email self.assertEqual(len(frog_group.message_ids), 1, @@ -536,7 +536,7 @@ class TestMailgateway(TestMail): self.assertIn('<pre>\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n</pre>', msg.body, 'message_process: plaintext incoming email incorrectly parsed') - @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm') + @mute_logger('openerp.addons.mail.mail_thread', 'openerp.models') def test_20_thread_parent_resolution(self): """ Testing parent/child relationships are correctly established when processing incoming mails """ cr, uid = self.cr, self.uid diff --git a/addons/mail/tests/test_mail_group.py b/addons/mail/tests/test_mail_group.py index 34c7f0c00e0..c131ce0bd0b 100644 --- a/addons/mail/tests/test_mail_group.py +++ b/addons/mail/tests/test_mail_group.py @@ -27,7 +27,7 @@ from openerp.tools import mute_logger class TestMailGroup(TestMail): - @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.osv.orm') + @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.models') def test_00_mail_group_access_rights(self): """ Testing mail_group access rights and basic mail_thread features """ cr, uid, user_noone_id, user_employee_id = self.cr, self.uid, self.user_noone_id, self.user_employee_id diff --git a/addons/mail/tests/test_mail_message.py b/addons/mail/tests/test_mail_message.py index d4a7ae75df3..40d6786e2c9 100644 --- a/addons/mail/tests/test_mail_message.py +++ b/addons/mail/tests/test_mail_message.py @@ -161,7 +161,7 @@ class TestMailMessage(TestMail): self.assertEqual(mail.reply_to, 'someone@example.com', 'mail_mail: reply_to should equal the rpely_to given to create') - @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.osv.orm') + @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.models') def test_10_mail_message_search_access_rights(self): """ Testing mail_message.search() using specific _search implementation """ cr, uid, group_pigs_id = self.cr, self.uid, self.group_pigs_id @@ -196,7 +196,7 @@ class TestMailMessage(TestMail): msg_ids = self.mail_message.search(cr, uid, [('subject', 'like', '_Test')]) self.assertEqual(set([msg_id1, msg_id2, msg_id3, msg_id4, msg_id5, msg_id6, msg_id7, msg_id8]), set(msg_ids), 'mail_message search failed') - @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.osv.orm') + @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.models') def test_15_mail_message_check_access_rule(self): """ Testing mail_message.check_access_rule() """ cr, uid = self.cr, self.uid @@ -218,8 +218,8 @@ class TestMailMessage(TestMail): message_id = self.mail_message.create(cr, uid, {'body': 'My Body', 'attachment_ids': [(4, attachment_id)]}) # Test: Bert reads the message, crash because not notification/not in doc followers/not read on doc - self.assertRaises(except_orm, self.mail_message.read, - cr, user_bert_id, message_id) + with self.assertRaises(except_orm): + self.mail_message.read(cr, user_bert_id, message_id) # Do: message is pushed to Bert notif_id = self.mail_notification.create(cr, uid, {'message_id': message_id, 'partner_id': partner_bert_id}) # Test: Bert reads the message, ok because notification pushed @@ -229,11 +229,11 @@ class TestMailMessage(TestMail): # Do: remove notification self.mail_notification.unlink(cr, uid, notif_id) # Test: Bert reads the message, crash because not notification/not in doc followers/not read on doc - self.assertRaises(except_orm, self.mail_message.read, - cr, self.user_bert_id, message_id) + with self.assertRaises(except_orm): + self.mail_message.read(cr, self.user_bert_id, message_id) # Test: Bert downloads attachment, crash because he can't read message - self.assertRaises(except_orm, self.mail_message.download_attachment, - cr, user_bert_id, message_id, attachment_id) + with self.assertRaises(except_orm): + self.mail_message.download_attachment(cr, user_bert_id, message_id, attachment_id) # Do: Bert is now the author self.mail_message.write(cr, uid, [message_id], {'author_id': partner_bert_id}) # Test: Bert reads the message, ok because Bert is the author @@ -241,8 +241,8 @@ class TestMailMessage(TestMail): # Do: Bert is not the author anymore self.mail_message.write(cr, uid, [message_id], {'author_id': partner_raoul_id}) # Test: Bert reads the message, crash because not notification/not in doc followers/not read on doc - self.assertRaises(except_orm, self.mail_message.read, - cr, user_bert_id, message_id) + with self.assertRaises(except_orm): + self.mail_message.read(cr, user_bert_id, message_id) # Do: message is attached to a document Bert can read, Jobs self.mail_message.write(cr, uid, [message_id], {'model': 'mail.group', 'res_id': self.group_jobs_id}) # Test: Bert reads the message, ok because linked to a doc he is allowed to read @@ -250,33 +250,33 @@ class TestMailMessage(TestMail): # Do: message is attached to a document Bert cannot read, Pigs self.mail_message.write(cr, uid, [message_id], {'model': 'mail.group', 'res_id': self.group_pigs_id}) # Test: Bert reads the message, crash because not notification/not in doc followers/not read on doc - self.assertRaises(except_orm, self.mail_message.read, - cr, user_bert_id, message_id) + with self.assertRaises(except_orm): + self.mail_message.read(cr, user_bert_id, message_id) # ---------------------------------------- # CASE2: create # ---------------------------------------- # Do: Bert creates a message on Pigs -> ko, no creation rights - self.assertRaises(AccessError, self.mail_message.create, - cr, user_bert_id, {'model': 'mail.group', 'res_id': self.group_pigs_id, 'body': 'Test'}) + with self.assertRaises(AccessError): + self.mail_message.create(cr, user_bert_id, {'model': 'mail.group', 'res_id': self.group_pigs_id, 'body': 'Test'}) # Do: Bert create a message on Jobs -> ko, no creation rights - self.assertRaises(AccessError, self.mail_message.create, - cr, user_bert_id, {'model': 'mail.group', 'res_id': self.group_jobs_id, 'body': 'Test'}) + with self.assertRaises(AccessError): + self.mail_message.create(cr, user_bert_id, {'model': 'mail.group', 'res_id': self.group_jobs_id, 'body': 'Test'}) # Do: Bert create a private message -> ko, no creation rights - self.assertRaises(AccessError, self.mail_message.create, - cr, user_bert_id, {'body': 'Test'}) + with self.assertRaises(AccessError): + self.mail_message.create(cr, user_bert_id, {'body': 'Test'}) # Do: Raoul creates a message on Jobs -> ok, write access to the related document self.mail_message.create(cr, user_raoul_id, {'model': 'mail.group', 'res_id': self.group_jobs_id, 'body': 'Test'}) # Do: Raoul creates a message on Priv -> ko, no write access to the related document - self.assertRaises(except_orm, self.mail_message.create, - cr, user_raoul_id, {'model': 'mail.group', 'res_id': self.group_priv_id, 'body': 'Test'}) + with self.assertRaises(except_orm): + self.mail_message.create(cr, user_raoul_id, {'model': 'mail.group', 'res_id': self.group_priv_id, 'body': 'Test'}) # Do: Raoul creates a private message -> ok self.mail_message.create(cr, user_raoul_id, {'body': 'Test'}) # Do: Raoul creates a reply to a message on Priv -> ko - self.assertRaises(except_orm, self.mail_message.create, - cr, user_raoul_id, {'model': 'mail.group', 'res_id': self.group_priv_id, 'body': 'Test', 'parent_id': priv_msg_id}) + with self.assertRaises(except_orm): + self.mail_message.create(cr, user_raoul_id, {'model': 'mail.group', 'res_id': self.group_priv_id, 'body': 'Test', 'parent_id': priv_msg_id}) # Do: Raoul creates a reply to a message on Priv-> ok if has received parent self.mail_notification.create(cr, uid, {'message_id': priv_msg_id, 'partner_id': self.partner_raoul_id}) self.mail_message.create(cr, user_raoul_id, {'model': 'mail.group', 'res_id': self.group_priv_id, 'body': 'Test', 'parent_id': priv_msg_id}) @@ -335,7 +335,7 @@ class TestMailMessage(TestMail): self.assertEqual(len(notif_ids), 1, 'mail_message set_message_read: more than one notification created') # Test: notification read notif = self.mail_notification.browse(cr, uid, notif_ids[0]) - self.assertTrue(notif.read, 'mail_notification read failed') + self.assertTrue(notif['is_read'], 'mail_notification read failed') self.assertFalse(msg.to_read, 'mail_message read failed') # Do: Raoul reads msg @@ -346,7 +346,7 @@ class TestMailMessage(TestMail): self.assertEqual(len(notif_ids), 1, 'mail_message set_message_read: more than one notification created') # Test: notification read notif = self.mail_notification.browse(cr, uid, notif_ids[0]) - self.assertTrue(notif.read, 'mail_notification starred failed') + self.assertTrue(notif['is_read'], 'mail_notification starred failed') self.assertFalse(msg_raoul.to_read, 'mail_message starred failed') # Do: Admin unreads msg @@ -383,7 +383,7 @@ class TestMailMessage(TestMail): self.assertEqual(set(msg.vote_user_ids), set([self.user_raoul]), 'mail_message vote: after unvoting, Bert should be in the voter') self.assertEqual(set(msg_raoul.vote_user_ids), set([self.user_raoul]), 'mail_message vote: after unvoting, Bert should be in the voter') - @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.osv.orm') + @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.models') def test_50_mail_flow_access_rights(self): """ Test a Chatter-looks alike flow to test access rights """ cr, uid = self.cr, self.uid @@ -400,9 +400,9 @@ class TestMailMessage(TestMail): # ---------------------------------------- # Do: Bert reads Jobs basic fields, ok because public = read access on the group - self.mail_group.read(cr, user_bert_id, self.group_jobs_id, ['name', 'description']) + self.mail_group.read(cr, user_bert_id, [self.group_jobs_id], ['name', 'description']) # Do: Bert reads Jobs messages, ok because read access on the group => read access on its messages - jobs_message_ids = self.mail_group.read(cr, user_bert_id, self.group_jobs_id, ['message_ids'])['message_ids'] + jobs_message_ids = self.mail_group.read(cr, user_bert_id, [self.group_jobs_id], ['message_ids'])[0]['message_ids'] self.mail_message.read(cr, user_bert_id, jobs_message_ids) # Do: Bert browses Jobs, ok (no direct browse of partners), ok for messages, ko for followers (accessible to employees or partner manager) bert_jobs = self.mail_group.browse(cr, user_bert_id, self.group_jobs_id) @@ -413,9 +413,8 @@ class TestMailMessage(TestMail): with self.assertRaises(AccessError): trigger_read = partner.name # Do: Bert comments Jobs, ko because no creation right - self.assertRaises(AccessError, - self.mail_group.message_post, - cr, user_bert_id, self.group_jobs_id, body='I love Pigs') + with self.assertRaises(AccessError): + self.mail_group.message_post(cr, user_bert_id, self.group_jobs_id, body='I love Pigs') # Do: Bert writes on its own profile, ko because no message create access with self.assertRaises(AccessError): @@ -444,5 +443,5 @@ class TestMailMessage(TestMail): # Do: Raoul replies to a Jobs message using the composer compose_id = mail_compose.create(cr, user_raoul_id, {'subject': 'Subject', 'body': 'Body text'}, - {'default_composition_mode': 'reply', 'default_parent_id': pigs_msg_id}) + {'default_composition_mode': 'comment', 'default_parent_id': pigs_msg_id}) mail_compose.send_mail(cr, user_raoul_id, [compose_id]) diff --git a/addons/mail/tests/test_message_read.py b/addons/mail/tests/test_message_read.py index c02e9a32278..fbf30f2ed22 100644 --- a/addons/mail/tests/test_message_read.py +++ b/addons/mail/tests/test_message_read.py @@ -46,7 +46,7 @@ class test_mail_access_rights(TestMail): ordered_msg_ids = [msg_id2, msg_id4, msg_id6, msg_id8, msg_id10, msg_id1, msg_id3, msg_id5, msg_id7, msg_id9, msg_id0] # Test: raoul received notifications - raoul_notification_ids = self.mail_notification.search(cr, user_raoul.id, [('read', '=', False), ('message_id', 'in', msg_ids), ('partner_id', '=', user_raoul.partner_id.id)]) + raoul_notification_ids = self.mail_notification.search(cr, user_raoul.id, [('is_read', '=', False), ('message_id', 'in', msg_ids), ('partner_id', '=', user_raoul.partner_id.id)]) self.assertEqual(len(raoul_notification_ids), 11, 'message_post: wrong number of produced notifications') # Test: read some specific ids |
