From 6c821603fffe299bc80104ae2668df12421783fb Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 28 Sep 2012 16:54:18 +0200 Subject: [PATCH] [FIX] portal test bzr revid: chm@openerp.com-20120928145418-0qu5xft9a2miz3h2 --- addons/portal/tests/test_portal.py | 116 ++++++++++++++--------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/addons/portal/tests/test_portal.py b/addons/portal/tests/test_portal.py index fd95f6c1e26..653a05d40aa 100644 --- a/addons/portal/tests/test_portal.py +++ b/addons/portal/tests/test_portal.py @@ -41,7 +41,7 @@ class test_portal(test_mail.TestMailMockups): {'name': 'Pigs', 'description': 'Fans of Pigs, unite !'}) # Find Portal group - group_portal_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'portal', 'group_portal_member') + group_portal_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'portal', 'group_portal') self.group_portal_id = group_portal_ref and group_portal_ref[1] or False # Create Chell (portal user) @@ -49,71 +49,71 @@ class test_portal(test_mail.TestMailMockups): self.user_chell = self.res_users.browse(cr, uid, self.user_chell_id) self.partner_chell_id = self.user_chell.partner_id.id - # def test_00_access_rights(self): - # """ Test basic mail_message and mail_group access rights for portal users. """ - # cr, uid = self.cr, self.uid - # partner_chell_id = self.partner_chell_id - # user_chell_id = self.user_chell_id + def test_00_access_rights(self): + """ Test basic mail_message and mail_group access rights for portal users. """ + cr, uid = self.cr, self.uid + partner_chell_id = self.partner_chell_id + user_chell_id = self.user_chell_id - # # Prepare group: Pigs (portal) - # self.mail_group.message_post(cr, uid, self.group_pigs_id, body='Message') - # self.mail_group.write(cr, uid, [self.group_pigs_id], {'name': 'Jobs', 'public': 'groups', 'group_public_id': self.group_portal_id}) + # Prepare group: Pigs (portal) + self.mail_group.message_post(cr, uid, self.group_pigs_id, body='Message') + self.mail_group.write(cr, uid, [self.group_pigs_id], {'name': 'Jobs', 'public': 'groups', 'group_public_id': self.group_portal_id}) - # # ---------------------------------------- - # # CASE1: Chell will use the Chatter - # # ---------------------------------------- + # ---------------------------------------- + # CASE1: Chell will use the Chatter + # ---------------------------------------- - # # Do: Chell reads Pigs messages, ok because restricted to portal group - # message_ids = self.mail_group.read(cr, user_chell_id, self.group_pigs_id, ['message_ids'])['message_ids'] - # self.mail_message.read(cr, user_chell_id, message_ids) - # # Do: Chell posts a message on Pigs, crash because can not write on group or is not in the followers - # self.assertRaises(except_orm, - # self.mail_group.message_post, - # cr, user_chell_id, self.group_pigs_id, body='Message') - # # Do: Chell is added to Pigs followers - # self.mail_group.message_subscribe(cr, uid, [self.group_pigs_id], [partner_chell_id]) - # # Test: Chell posts a message on Pigs, ok because in the followers - # self.mail_group.message_post(cr, user_chell_id, self.group_pigs_id, body='Message') + # Do: Chell reads Pigs messages, ok because restricted to portal group + message_ids = self.mail_group.read(cr, user_chell_id, self.group_pigs_id, ['message_ids'])['message_ids'] + self.mail_message.read(cr, user_chell_id, message_ids) + # Do: Chell posts a message on Pigs, crash because can not write on group or is not in the followers + self.assertRaises(except_orm, + self.mail_group.message_post, + cr, user_chell_id, self.group_pigs_id, body='Message') + # Do: Chell is added to Pigs followers + self.mail_group.message_subscribe(cr, uid, [self.group_pigs_id], [partner_chell_id]) + # Test: Chell posts a message on Pigs, ok because in the followers + self.mail_group.message_post(cr, user_chell_id, self.group_pigs_id, body='Message') - # def test_50_mail_invite(self): - # cr, uid = self.cr, self.uid - # user_admin = self.res_users.browse(cr, uid, uid) - # self.mail_invite = self.registry('mail.wizard.invite') - # base_url = self.registry('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='') - # portal_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'portal', 'group_portal') - # portal_id = portal_ref and portal_ref[1] or False + def test_50_mail_invite(self): + cr, uid = self.cr, self.uid + user_admin = self.res_users.browse(cr, uid, uid) + self.mail_invite = self.registry('mail.wizard.invite') + base_url = self.registry('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='') + portal_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'portal', 'group_portal') + portal_id = portal_ref and portal_ref[1] or False - # # 0 - Admin - # p_a_id = user_admin.partner_id.id - # # 1 - Bert Tartopoils, with email, should receive emails for comments and emails - # p_b_id = self.res_partner.create(cr, uid, {'name': 'Bert Tartopoils', 'email': 'b@b'}) + # 0 - Admin + p_a_id = user_admin.partner_id.id + # 1 - Bert Tartopoils, with email, should receive emails for comments and emails + p_b_id = self.res_partner.create(cr, uid, {'name': 'Bert Tartopoils', 'email': 'b@b'}) - # # ---------------------------------------- - # # CASE1: generated URL - # # ---------------------------------------- + # ---------------------------------------- + # CASE1: generated URL + # ---------------------------------------- - # url = self.mail_mail._generate_signin_url(cr, uid, p_b_id, portal_id, 1234) - # self.assertEqual(url, base_url + '/login?action=signin&partner_id=%s&group=%s&key=%s' % (p_b_id, portal_id, 1234), - # 'generated signin URL incorrect') + url = self.mail_mail._generate_signin_url(cr, uid, p_b_id, portal_id, 1234) + self.assertEqual(url, base_url + '/login?action=signin&partner_id=%s&group=%s&key=%s' % (p_b_id, portal_id, 1234), + 'generated signin URL incorrect') - # # ---------------------------------------- - # # CASE2: invite Bert - # # ---------------------------------------- + # ---------------------------------------- + # CASE2: invite Bert + # ---------------------------------------- - # _sent_email_subject = 'Invitation to follow Pigs' - # _sent_email_body = append_content_to_html('
You have been invited to follow Pigs.
', url) + _sent_email_subject = 'Invitation to follow Pigs' + _sent_email_body = append_content_to_html('
You have been invited to follow Pigs.
', url) - # # Do: create a mail_wizard_invite, validate it - # self._init_mock_build_email() - # mail_invite_id = self.mail_invite.create(cr, uid, {'partner_ids': [(4, p_b_id)]}, {'default_res_model': 'mail.group', 'default_res_id': self.group_pigs_id}) - # self.mail_invite.add_followers(cr, uid, [mail_invite_id]) - # group_pigs = self.mail_group.browse(cr, uid, self.group_pigs_id) + # Do: create a mail_wizard_invite, validate it + self._init_mock_build_email() + mail_invite_id = self.mail_invite.create(cr, uid, {'partner_ids': [(4, p_b_id)]}, {'default_res_model': 'mail.group', 'default_res_id': self.group_pigs_id}) + self.mail_invite.add_followers(cr, uid, [mail_invite_id]) + group_pigs = self.mail_group.browse(cr, uid, self.group_pigs_id) - # # Test: Pigs followers should contain Admin and Bert - # follower_ids = [follower.id for follower in group_pigs.message_follower_ids] - # self.assertEqual(set(follower_ids), set([p_a_id, p_b_id]), 'Pigs followers after invite is incorrect') - # # Test: sent email subject, body - # self.assertEqual(len(self._build_email_kwargs_list), 1, 'sent email number incorrect, should be only for Bert') - # for sent_email in self._build_email_kwargs_list: - # self.assertEqual(sent_email.get('subject'), _sent_email_subject, 'sent email subject incorrect') - # self.assertEqual(sent_email.get('body'), _sent_email_body, 'sent email body incorrect') + # Test: Pigs followers should contain Admin and Bert + follower_ids = [follower.id for follower in group_pigs.message_follower_ids] + self.assertEqual(set(follower_ids), set([p_a_id, p_b_id]), 'Pigs followers after invite is incorrect') + # Test: sent email subject, body + self.assertEqual(len(self._build_email_kwargs_list), 1, 'sent email number incorrect, should be only for Bert') + for sent_email in self._build_email_kwargs_list: + self.assertEqual(sent_email.get('subject'), _sent_email_subject, 'sent email subject incorrect') + self.assertEqual(sent_email.get('body'), _sent_email_body, 'sent email body incorrect')