From faf9c29775219209addae6fd96642b3eb0b2c59d Mon Sep 17 00:00:00 2001 From: Eric Lembregts Date: Mon, 24 Jul 2017 16:31:13 +0200 Subject: [PATCH] [RFR] Rewrite and add test case --- auditlog/tests/test_auditlog.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/auditlog/tests/test_auditlog.py b/auditlog/tests/test_auditlog.py index 225624584..48676da91 100644 --- a/auditlog/tests/test_auditlog.py +++ b/auditlog/tests/test_auditlog.py @@ -124,14 +124,13 @@ class TestMethods(TransactionCase): existing_audit_logs = self.env['auditlog.log'].search([]) existing_audit_logs.unlink() - # Create account period to test - self.partner = self.env['res.partner'].create({ - 'name': 'Test User' - }) + # Get partner to test + self.partner = self.env['res.partner'].search([], limit=1) self.partner_model = self.env['ir.model'].search([ ('model', '=', 'res.partner')]) + # Setup auditlog rules self.auditlog_rule = self.env['auditlog.rule'].create({ 'name': 'res.partner', 'model_id': self.partner_model.id, @@ -142,8 +141,8 @@ class TestMethods(TransactionCase): 'log_unlink': False, 'log_custom_method': True, 'custom_method_ids': [(0, 0, { - 'name': 'copy', - 'message': 'execute_copy', + 'name': 'onchange_type', + 'message': 'onchange_type', })] }) @@ -159,12 +158,26 @@ class TestMethods(TransactionCase): self.auditlog_rule.subscribe() def test_02_copy_res_partner_logging(self): - self.partner.copy() + """ Copy partner and see if the action gets logged """ + self.partner.onchange_type(False) + + logs = self.env['auditlog.log'].search([ + ('res_id', '=', self.partner.id), + ('model_id', '=', self.partner_model.id), + ('method', '=', 'onchange_type') + ]) + + self.assertEqual(len(logs), 1) + + def test_03_copy_res_partner_logging_old_api(self): + """ Perform the same test as 02 but with the old API """ + self.registry('res.partner').onchange_type( + self.cr, self.uid, self.partner.id, False) logs = self.env['auditlog.log'].search([ ('res_id', '=', self.partner.id), ('model_id', '=', self.partner_model.id), - ('method', '=', 'execute_copy') + ('method', '=', 'onchange_type') ]) self.assertEqual(len(logs), 1)