diff --git a/runbot/models/build_config.py b/runbot/models/build_config.py index c6fdb4a5..1b937365 100644 --- a/runbot/models/build_config.py +++ b/runbot/models/build_config.py @@ -26,7 +26,7 @@ class Config(models.Model): name = fields.Char('Config name', required=True, unique=True, track_visibility='onchange', help="Unique name for config please use trigram as postfix for custom configs") description = fields.Char('Config description') - step_order_ids = fields.One2many('runbot.build.config.step.order', 'config_id') + step_order_ids = fields.One2many('runbot.build.config.step.order', 'config_id', copy=True) update_github_state = fields.Boolean('Notify build state to github', default=False, track_visibility='onchange') protected = fields.Boolean('Protected', default=False, track_visibility='onchange') group = fields.Many2one('runbot.build.config', 'Configuration group', help="Group of config's and config steps") @@ -55,7 +55,7 @@ class Config(models.Model): def step_ids(self): self.ensure_one() - return [ordered_step.step_id for ordered_step in self.step_order_ids] + return [ordered_step.step_id for ordered_step in self.step_order_ids.sorted('sequence')] def _check_step_ids_order(self): install_job = False diff --git a/runbot/tests/test_build_config_step.py b/runbot/tests/test_build_config_step.py index ad71d7a8..29dba737 100644 --- a/runbot/tests/test_build_config_step.py +++ b/runbot/tests/test_build_config_step.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from unittest.mock import patch, mock_open -from odoo.tests import common +from odoo.exceptions import UserError from odoo.addons.runbot.models.repo import RunbotException from .common import RunbotCase @@ -83,6 +83,67 @@ class TestBuildConfigStep(RunbotCase): self.assertFalse(self.parent_build.global_result) + def test_config_step_raises(self): + """ Test a config raises when run step position is wrong""" + + run_step = self.ConfigStep.create({ + 'name': 'run_step', + 'job_type': 'run_odoo', + }) + + create_step = self.ConfigStep.create({ + 'name': 'test_step', + 'job_type': 'create_build', + }) + + config = self.Config.create({'name': 'test_config'}) + + # test that the run_odoo step has to be the last one + with self.assertRaises(UserError): + config.write({ + 'step_order_ids': [ + (0, 0, {'sequence': 10, 'step_id': run_step.id}), + (0, 0, {'sequence': 15, 'step_id': create_step.id}), + ] + }) + + # test that the run_odoo step should be preceded by an install step + with self.assertRaises(UserError): + config.write({ + 'step_order_ids': [ + (0, 0, {'sequence': 15, 'step_id': run_step.id}), + (0, 0, {'sequence': 10, 'step_id': create_step.id}), + ] + }) + + def test_config_step_copy(self): + """ Test a config copy with step_order_ids """ + + install_step = self.ConfigStep.create({ + 'name': 'install_step', + 'job_type': 'install_odoo' + }) + + run_step = self.ConfigStep.create({ + 'name': 'run_step', + 'job_type': 'run_odoo', + }) + + create_step = self.ConfigStep.create({ + 'name': 'test_step', + 'job_type': 'create_build', + }) + + config = self.Config.create({'name': 'test_config'}) + StepOrder = self.env['runbot.build.config.step.order'] + # Creation order is impoortant to reproduce the Odoo copy bug/feature :-) + StepOrder.create({'sequence': 15, 'step_id': run_step.id, 'config_id': config.id}) + StepOrder.create({'sequence': 10, 'step_id': create_step.id, 'config_id': config.id}) + StepOrder.create({'sequence': 12, 'step_id': install_step.id, 'config_id': config.id}) + + dup_config = config.copy() + self.assertEqual(dup_config.step_order_ids.mapped('step_id'), config.step_order_ids.mapped('step_id')) + @patch('odoo.addons.runbot.models.build.runbot_build._checkout') def test_coverage(self, mock_checkout): config_step = self.ConfigStep.create({