[FIX] mail: make basic mail tests pass again, remove useless/dead test code
authorOlivier Dony <odo@openerp.com>
Wed, 22 Aug 2012 13:30:28 +0000 (15:30 +0200)
committerOlivier Dony <odo@openerp.com>
Wed, 22 Aug 2012 13:30:28 +0000 (15:30 +0200)
bzr revid: odo@openerp.com-20120822133028-hms3xfhibhn1j38l

addons/mail/mail_thread.py
addons/mail/tests/test_mail.py
addons/mail/tests/write_test.py [deleted file]

index c8e5ba3..1be8dfd 100644 (file)
@@ -297,7 +297,6 @@ class mail_thread(osv.Model):
                                     thread_id, custom_values,
                                     context=context)
         msg = self.parse_message(cr, uid, msg_txt, save_original=save_original, context=context)
-        msg['state'] = 'received'
         if strip_attachments and 'attachments' in msg:
             del msg['attachments']
         for model, thread_id, custom_values, user_id in routes:
@@ -543,7 +542,7 @@ class mail_thread(osv.Model):
 
         values = kwargs
         values.update( {
-            'model': thread_id and self._name or False,
+            'model': thread_id and context.get('thread_model', self._name) or False,
             'res_id': thread_id or False,
             'body': body,
             'subject': subject,
index 0940d72..a9da19e 100644 (file)
@@ -82,26 +82,27 @@ class test_mail(common.TransactionCase):
         self.group_tech_id = self.mail_group.create(self.cr, self.uid, {'name': 'tech'})
 
     def test_message_process(self):
+        cr, uid = self.cr, self.uid
         # Incoming mail creates a new mail_group "frogs"
-        self.assertEqual(self.mail_group.search(self.cr, self.uid, [('name','=','frogs')]), [])
+        self.assertEqual(self.mail_group.search(cr, uid, [('name','=','frogs')]), [])
         mail_frogs = MAIL_TEMPLATE.format(to='groups@example.com, other@gmail.com', subject='frogs', extra='')
-        self.mail_thread.message_process(self.cr, self.uid, None, mail_frogs)
-        frog_groups = self.mail_group.search(self.cr, self.uid, [('name','=','frogs')])
+        self.mail_thread.message_process(cr, uid, None, mail_frogs)
+        frog_groups = self.mail_group.search(cr, uid, [('name','=','frogs')])
         self.assertTrue(len(frog_groups) == 1)
 
         # Previously-created group can be emailed now - it should have an implicit alias group+frogs@...
-        frog_group = self.mail_group.browse(self.cr, self.uid, frog_groups[0])
+        frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
         group_messages = frog_group.message_ids
         self.assertTrue(len(group_messages) == 1, 'New group should only have the original message')
         mail_frog_news = MAIL_TEMPLATE.format(to='Friendly Frogs <group+frogs@example.com>', subject='news', extra='')
-        self.mail_thread.message_process(self.cr, self.uid, None, mail_frog_news)
+        self.mail_thread.message_process(cr, uid, None, mail_frog_news)
         frog_group.refresh()
         self.assertTrue(len(frog_group.message_ids) == 2, 'Group should contain 2 messages now')
 
         # Even with a wrong destination, a reply should end up in the correct thread
         mail_reply = MAIL_TEMPLATE.format(to='erroneous@example.com>', subject='Re: news',
                                           extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n'%frog_group.id)
-        self.mail_thread.message_process(self.cr, self.uid, None, mail_reply)
+        self.mail_thread.message_process(cr, uid, None, mail_reply)
         frog_group.refresh()
         self.assertTrue(len(frog_group.message_ids) == 3, 'Group should contain 3 messages now')
         
@@ -109,4 +110,4 @@ class test_mail(common.TransactionCase):
         mail_spam = MAIL_TEMPLATE.format(to='noone@example.com', subject='spam', extra='')
         self.assertRaises(Exception,
                           self.mail_thread.message_process,
-                          self.cr, self.uid, None, mail_spam)
+                          cr, uid, None, mail_spam)
diff --git a/addons/mail/tests/write_test.py b/addons/mail/tests/write_test.py
deleted file mode 100644 (file)
index 920fbb9..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
-#                    Fabien Pinckaers <fp@tiny.Be>
-#
-# WARNING: This program as such is intended to be used by professional
-# programmers who take the whole responsability of assessing all potential
-# consequences resulting from its eventual inadequacies and bugs
-# End users who are looking for a ready-to-use solution with commercial
-# garantees and support are strongly adviced to contract a Free Software
-# Service Company
-#
-# This program is Free Software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#
-##############################################################################
-
-#
-# This module test all RPC methods
-#
-
-import xmlrpclib
-
-uid = 1
-passwd='admin'
-server = 'localhost'
-db = 'trunk'
-
-sock = xmlrpclib.ServerProxy('http://'+server+':8069/xmlrpc/object')
-
-def _print_data(data, level=0):
-    for d in data:
-        print '    '*level, d['id']
-        _print_data(d['child_ids'], level+1)
-
-print 'With Domain', [('model','=','mail.group')], 'thread_level'
-data = sock.execute(db, uid, passwd, 'mail.message', 'message_read', False, [('model','=','mail.group')], 1)
-_print_data(data)
-
-print 'With Domain', [('model','=','mail.group')], 'no thread_level'
-data = sock.execute(db, uid, passwd, 'mail.message', 'message_read', False, [('model','=','mail.group')], 0)
-_print_data(data)
-
-
-print 'With Domain', [('model','=','mail.group'), ('parent_id','=',False)], 'thread_level=0'
-data = sock.execute(db, uid, passwd, 'mail.message', 'message_read', False, [('model','=','mail.group'), ('parent_id','=',False)], 0)
-_print_data(data)
-
-print 'With Domain', [('model','=','mail.group'), ('parent_id','=',False)], 'thread_level=2'
-data = sock.execute(db, uid, passwd, 'mail.message', 'message_read', False, [('model','=','mail.group'), ('parent_id','=',False)], 2)
-_print_data(data)
-
-print 'Fixed IDS', [2,3,41,43], 'thread_level'
-data = sock.execute(db, uid, passwd, 'mail.message', 'message_read', [2,3,41,43], [], 1)
-_print_data(data)
-
-print 'Fixed IDS', [2,43], 'no thread_level'
-data = sock.execute(db, uid, passwd, 'mail.message', 'message_read', [2,43], [], 0)
-_print_data(data)
-
-print 'Fixed IDS', [2,43], 'thread_level'
-data = sock.execute(db, uid, passwd, 'mail.message', 'message_read', [2,43], [], 1)
-_print_data(data)
-
-print 'domain [id in 3,41]', 'thread_level'
-data = sock.execute(db, uid, passwd, 'mail.message', 'message_read', False, [('id','in',[3,41])], 1)
-_print_data(data)
-