<commit_before># -*- coding: utf-8 -*-

import mock

import openerp.tests.common as common

from ..event import (
    on_record_create,
    on_record_write,
    on_record_unlink
)


class test_producers(common.TransactionCase):
    """ Test producers """

    def setUp(self):
        super(test_producers, self).setUp()

        class Recipient(object):
            pass

        self.recipient = Recipient()

        # use env, not registry, to use new ai
        self.model = self.env('res.partner')
        self.partner = self.model.create({'name': 'new'})

    def test_on_record_create(self):
        """
        Create a record and check if the event is called
        """
        @on_record_create(model_names='res.partner')
        def event(session, model_name, record):
            self.recipient.name = record.name

        record = self.model.create({'name': '<NAME>'})
        self.assertEqual(self.recipient.name, record.name)
        on_record_create.unsubscribe(event)

    def test_on_record_write(self):
        """
        Write on a record and check if the event is called<commit_msg>Fix env to use dict syntax<commit_after># -*- coding: utf-8 -*-

import mock

import openerp.tests.common as common

from ..event import (
    on_record_create,
    on_record_write,
    on_record_unlink
)


class test_producers(common.TransactionCase):
    """ Test producers """

    def setUp(self):
        super(test_producers, self).setUp()

        class Recipient(object):
            pass

        self.recipient = Recipient()

        # use env, not registry, to use new ai
        self.model = self.env['res.partner']
        self.partner = self.model.create({'name': 'new'})

    def test_on_record_create(self):
        """
        Create a record and check if the event is called
        """
        @on_record_create(model_names='res.partner')
        def event(session, model_name, record):
            self.recipient.name = record.name

        record = self.model.create({'name': '<NAME>'})
        self.assertEqual(self.recipient.name, record.name)
        on_record_create.unsubscribe(event)

    def test_on_record_write(self):
        """
        Write on a record and check if the event is called
{'fraction_non_alphanumeric': 0.11246063877642826, 'fraction_numerical': 0.000899685110211426, 'mean_word_length': 2.5078864353312302, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1862433', 'n_tokens_mistral': 686, 'n_tokens_neox': 657, 'n_words': 162}