From 58c97a02c5a5b2b0d9fd387386c3c7fb40740293 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 29 Jul 2017 13:30:43 +0200 Subject: [PATCH] [IMP] web_widget_digitized_signature: Add tests --- .../models/res_users.py | 17 ++++++++-- .../tests/__init__.py | 4 +++ .../tests/test_signature_tracking.py | 34 +++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 web_widget_digitized_signature/tests/__init__.py create mode 100644 web_widget_digitized_signature/tests/test_signature_tracking.py diff --git a/web_widget_digitized_signature/models/res_users.py b/web_widget_digitized_signature/models/res_users.py index c1275b66..7816ba91 100644 --- a/web_widget_digitized_signature/models/res_users.py +++ b/web_widget_digitized_signature/models/res_users.py @@ -4,13 +4,24 @@ # Copyright 2017 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields +from openerp import api, fields, models -class Users(models.Model): +class ResUsers(models.Model): _name = 'res.users' - _inherit = 'res.users' + _inherit = ['res.users', 'mail.thread'] signature_image = fields.Binary( string='Signature', ) + + @api.model + def create(self, vals): + res = super(ResUsers, self).create(vals) + res._track_signature(vals, 'signature') + return res + + @api.multi + def write(self, vals): + self._track_signature(vals, 'signature') + return super(ResUsers, self).write(vals) diff --git a/web_widget_digitized_signature/tests/__init__.py b/web_widget_digitized_signature/tests/__init__.py new file mode 100644 index 00000000..3dc777d5 --- /dev/null +++ b/web_widget_digitized_signature/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_signature_tracking diff --git a/web_widget_digitized_signature/tests/test_signature_tracking.py b/web_widget_digitized_signature/tests/test_signature_tracking.py new file mode 100644 index 00000000..1b6ee0af --- /dev/null +++ b/web_widget_digitized_signature/tests/test_signature_tracking.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests import common + + +class TestSignatureTracking(common.SavepointCase): + @classmethod + def setUpClass(cls): + super(TestSignatureTracking, cls).setUpClass() + cls.user = cls.env.user + cls.user.lang = 'en_US' + # Simple 1x1 transparent base64 encoded GIF + cls.image = 'R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' + cls.attachment_obj = cls.env['ir.attachment'] + cls.message_obj = cls.env['mail.message'] + + def test_signature_tracking(self): + """We have to test in a tricky way, as res.users doesn't allow a + direct chatter""" + prev_attachment_num = self.attachment_obj.search_count([]) + prev_messages = self.message_obj.search([]) + self.user.signature = self.image + current_attachment_num = self.attachment_obj.search_count([]) + self.assertEqual(current_attachment_num - prev_attachment_num, 1) + current_messages = self.message_obj.search([]) + message = current_messages - prev_messages + self.assertIn('Signature has been created.', message.body) + prev_messages = current_messages + self.user.signature = False + current_messages = self.message_obj.search([]) + message = current_messages - prev_messages + self.assertIn('Signature has been deleted.', message.body)