Coverage for ingadhoc-odoo-saas-adhoc / saas_provider_upgrade / tests / test_provider_upgrade_base.py: 94%
34 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 18:05 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 18:05 +0000
1from odoo import Command
2from odoo.tests import TransactionCase
5class TestProviderUpgradeCommon(TransactionCase):
6 """
7 Common base class for saas_provider_upgrade tests.
9 Extends TestProviderAdhocCommon with upgrade-specific data and functionality.
10 Uses existing data from parent classes to avoid duplication.
11 """
13 @classmethod
14 def setUpClass(cls):
15 super().setUpClass()
17 # Create upgrade-specific portal user (different from parent classes)
18 Users = cls.env["res.users"].with_context(no_reset_password=True)
19 cls.user_upgrade_portal = Users.create(
20 {
21 "name": "Gordon Freeman",
22 "login": "gordon.upgrade",
23 "email": "gordon@upgrade.portal",
24 "signature": "SignGordon",
25 "notification_type": "email",
26 "group_ids": [Command.set(cls.env.ref("base.group_portal").ids)],
27 }
28 )
30 # Create corresponding partner for the upgrade portal user
31 cls.partner_upgrade_portal = cls.env["res.partner"].create(
32 {
33 "name": "Gordon Freeman",
34 "email": "gordon@upgrade.portal",
35 "company_id": False,
36 "user_ids": [Command.link(cls.user_upgrade_portal.id)],
37 }
38 )
40 # Create upgrade-specific analytic account
41 cls.upgrade_analytic_account = cls.env["account.analytic.account"].create(
42 {
43 "name": "upgrade-test-analytic-account",
44 "partner_id": cls.partner_upgrade_portal.id,
45 "plan_id": cls.env.ref("analytic.analytic_plan_projects").id,
46 "use_databases": True,
47 }
48 )
50 # Upgrade project for tickets
51 cls.upgrade_project = (
52 cls.env["project.project"]
53 .with_context(mail_create_nolog=True)
54 .create(
55 {
56 "name": "Upgrade Customer Project",
57 "partner_id": cls.partner_upgrade_portal.id,
58 "account_id": cls.upgrade_analytic_account.id,
59 }
60 )
61 )
63 # Create upgrade-specific production database
64 cls.upgrade_production_database = cls.env["saas.database"].create(
65 {
66 "analytic_account_id": cls.upgrade_analytic_account.id,
67 "database_type_id": cls.env.ref("saas_provider.saas_database_type_production").id,
68 "odoo_version_id": cls.env.ref("saas_provider.odoo_version_16").id,
69 "odoo_version_group_id": cls.env.ref("saas_provider.odoo_version_group_16").id,
70 }
71 )
73 # Equipo de Actualización
74 cls.upgrade_team = cls.env["helpdesk.team"].create(
75 {
76 "name": "Actualización de versión Test",
77 "upgrade_team": True,
78 "use_helpdesk_timesheet": True,
79 "alias_name": "upgrade_request_test",
80 }
81 )
83 # Upgrade Types: model a two-step path 16 -> 18 -> 19
84 UpgradeType = cls.env["saas.upgrade.type"]
85 vg16 = cls.env.ref("saas_provider.odoo_version_group_16")
86 vg17 = cls.env.ref("saas_provider.odoo_version_group_17")
87 vg18 = cls.env.ref("saas_provider.odoo_version_group_18")
88 vg19 = cls.env.ref("saas_provider.odoo_version_group_19")
90 # Set sequences for version groups (lower sequence = newer version)
91 # This is needed for the version validation constraint
92 vg16.sequence = 4
93 vg17.sequence = 3
94 vg18.sequence = 2
95 vg19.sequence = 1
97 # Get or create intermediate database type for tests
98 cls.intermediate_database_type = cls.env["saas.database.type"].search([("name", "=", "Intermediate")], limit=1)
99 if not cls.intermediate_database_type: 99 ↛ 100line 99 didn't jump to line 100 because the condition on line 99 was never true
100 cls.intermediate_database_type = cls.env["saas.database.type"].create(
101 {
102 "name": "Intermediate",
103 "sequence": 55,
104 }
105 )
107 common_type_vals = {
108 "original_database_type_id": cls.env.ref("saas_provider.saas_database_type_old").id,
109 "intermediate_database_type_id": cls.intermediate_database_type.id,
110 "upgraded_database_type_id": cls.env.ref("saas_provider.saas_database_type_new").id,
111 "production_backup_database_type_id": cls.env.ref("saas_provider.saas_database_type_backup").id,
112 }
114 # First hop: v16 -> v18
115 cls.upgrade_type_16_18 = UpgradeType.create(
116 {
117 "name": "Mig v16 a v18",
118 "target_odoo_version_group_id": vg18.id,
119 "from_major_version_ids": [Command.link(vg16.id)],
120 **common_type_vals,
121 }
122 )
123 # Second hop: v18 -> v19
124 cls.upgrade_type_18_19 = UpgradeType.create(
125 {
126 "name": "Mig v18 a v19",
127 "target_odoo_version_group_id": vg19.id,
128 "from_major_version_ids": [Command.link(vg18.id)],
129 **common_type_vals,
130 }
131 )
133 # For most tests we use only the last hop (18 -> 19)
134 cls.upgrade_type = cls.upgrade_type_18_19
136 # Upgrade Line
137 cls.upgrade_line_02 = cls.env["saas.upgrade.line"].create(
138 {
139 "name": "[Test] Check only one request per day from portal",
140 "upgrade_type_ids": [Command.link(cls.upgrade_type.id)],
141 "type": "0_on_create",
142 "state": "approved",
143 "run_type": "test",
144 "description": "UL de Test 2",
145 "adhoc_product_id": cls.env.ref("saas_provider_adhoc.adhoc_product_actualizacion_actualizacion").id,
146 }
147 )
148 # Flush to ensure Many2many relationship is synced
149 cls.env.flush_all()
151 # Upgrade Line Script
152 cls.upgrade_line_script_02 = cls.env["saas.upgrade.line.script"].create(
153 {
154 "upgrade_line_id": cls.upgrade_line_02.id,
155 "version": 1,
156 "script": """
157if request.env.context.get('from_portal_upgrade') and request.ticket_id.request_line_ids.filtered(lambda x:x.id != request.id and x.notify_customer and x.aim == 'test' and x.create_date.date() == today.date()):
158 result = "[Test] Solo se puede generar una actualización de pruebas por día."
159""",
160 }
161 )
162 # Set the actual_script_id to link the UL to its initial script version
163 cls.upgrade_line_02.actual_script_id = cls.upgrade_line_script_02
165 # Ticket de actualización
166 cls.upgrade_ticket = cls.env["helpdesk.ticket"].create(
167 {
168 "name": "Actualización de test",
169 "team_id": cls.upgrade_team.id,
170 "upgrade_type_id": cls.upgrade_type.id,
171 "user_id": cls.env.ref("base.user_admin").id,
172 "partner_id": cls.partner_upgrade_portal.id,
173 "project_id": cls.upgrade_project.id,
174 "adhoc_product_id": cls.env.ref("saas_provider_adhoc.adhoc_product_actualizacion_actualizacion").id,
175 "main_database_id": cls.upgrade_production_database.id,
176 }
177 )