<commit_before># Copyright 2016-2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from odoo import api, models
from odoo.tests.common import TransactionCase


class BaseKanbanAbstractTester(models.Model):
    _name = 'base.kanban.abstract.tester'
    _inherit = 'base.kanban.abstract'


class TestBaseKanbanAbstract(TransactionCase):

    def _init_test_model(self, model_cls):
        model_cls._build_model(self.registry, self.cr)
        model = self.env[model_cls._name].with_context(todo=[])
        model._prepare_setup()
        model._setup_base(partial=False)
        model._setup_fields(partial=False)
        model._setup_complete()
        model._auto_init()
        model.init()
        model._auto_end()
        return model

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

        self.registry.enter_test_mode(self.cr)
        self.old_cursor = self.cr
        self.cr = self.registry.cursor()
        self.env = api.Environment(self.cr, self.uid, {})
        self.test_model = self._init_test_model(BaseKanbanAbstractTester)

        test_model_record = self.env['ir.model'].search([
            ('name', '=', self.test_model._name),
        ])
        self.test_stage = self.env['base.kanban.stage'].create({
            'name': 'Test Stage',
            'res_model_id': test_model_record.id,
            'sequence': 2,
        })
        self.test_stage_2 = self.env['base.kanban.stage'].create({
            'name': 'Test Stage 2',
            'res_model_id': test_model_record.id,
            'sequence': 1,
        })

    def tearDown(self):
        self.registry.leave_test_mode()
        self.registry[self.test_model._name]._abstract = True
        self.registry[self.test_model._name]._auto = False
        self.cr = self.old_cursor
        self.env = api.Environment(self.cr, self.uid, {})

        super(TestBaseKanbanAbstract, self).tearDown()

    def test_default_stage_id_no_stages(self):
        """It should return empty recordset when model has no stages"""
        self.env['base.kanban.stage'].search([
            ('res_model_id.model', '=', self.test_model._name),
        ]).unlink()
        result = self.test_model._default_stage_id()

        self.assertEqual(result, self.env['base.kanban.stage'])

    def test_default_stage_id_available_stages(self):
        """It should return lowest sequence stage when model has stages"""
        result = self.test_model._default_stage_id()

        self.assertEqual(result, self.test_stage_2)

    def test_read_group_stage_ids(self):
        """It should return all corresponding stages in requested sort order"""
        result = self.test_model._read_group_stage_ids(
            self.env['base.kanban.stage'], None, 'id'
        )

        expected = self.env['base.kanban.stage'].search(
            [('res_model_id.model', '=', self.test_model._name)],
            order='id',
        )
        self.assertEqual(result[0], expected[0])
        self.assertEqual(result[1], expected[1])
<commit_msg>[FIX] Adapt tests to v12<commit_after># Copyright 2016-2017 LasLabs Inc.
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from odoo import api, models
from odoo.tests.common import TransactionCase


class BaseKanbanAbstractTester(models.Model):
    _name = 'base.kanban.abstract.tester'
    _inherit = 'base.kanban.abstract'


class TestBaseKanbanAbstract(TransactionCase):

    def _init_test_model(self, model_cls):
        model_cls._build_model(self.registry, self.cr)
        model = self.env[model_cls._name]
        # setup_models():
        model._prepare_setup()
        model._setup_base()
        model._setup_fields()
        # init_models():
        model._setup_complete()
        model._auto_init()
        model.init()
        while self.registry._post_init_queue:
            func = self.registry._post_init_queue.popleft()
            func()
        return model

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

        self.registry.enter_test_mode(self.cr)
        self.old_cursor = self.cr
        self.cr = self.registry.cursor()
        self.env = api.Environment(self.cr, self.uid, {})
        self.test_model = self._init_test_model(BaseKanbanAbstractTester)

        test_model_record = self.env['ir.model'].search([
            ('name', '=', self.test_model._name),
        ], limit=1)
        self.test_stage = self.env['base.kanban.stage'].create({
            'name': 'Test Stage',
            'res_model_id': test_model_record.id,
            'sequence': 2,
        })
        self.test_stage_2 = self.env['base.kanban.stage'].create({
            'name': 'Test Stage 2',
            'res_model_id': test_model_record.id,
            'sequence': 1,
        })

    def tearDown(self):
        self.registry.leave_test_mode()
        self.registry[self.test_model._name]._abstract = True
        self.registry[self.test_model._name]._auto = False
        self.cr = self.old_cursor
        self.env = api.Environment(self.cr, self.uid, {})

        super(TestBaseKanbanAbstract, self).tearDown()

    def test_default_stage_id_no_stages(self):
        """It should return empty recordset when model has no stages"""
        self.env['base.kanban.stage'].search([
            ('res_model_id.model', '=', self.test_model._name),
        ]).unlink()
        result = self.test_model._default_stage_id()

        self.assertEqual(result, self.env['base.kanban.stage'])

    def test_default_stage_id_available_stages(self):
        """It should return lowest sequence stage when model has stages"""
        result = self.test_model._default_stage_id()

        self.assertEqual(result, self.test_stage_2)

    def test_read_group_stage_ids(self):
        """It should return all corresponding stages in requested sort order"""
        result = self.test_model._read_group_stage_ids(
            self.env['base.kanban.stage'], None, 'id'
        )

        expected = self.env['base.kanban.stage'].search(
            [('res_model_id.model', '=', self.test_model._name)],
            order='id',
        )
        self.assertEqual(result[0], expected[0])
        self.assertEqual(result[1], expected[1])

{'fraction_non_alphanumeric': 0.1263107721639657, 'fraction_numerical': 0.007149666348903718, 'mean_word_length': 2.6641443538998835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6955376', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1911, 'n_words': 332}