From 19667f95fcc843826f6b706149ef0454e933420d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 31 Oct 2025 12:03:02 +0100 Subject: [PATCH] Add test to check replaced field of replace party wizard --- modules/account/tests/test_module.py | 4 ++- modules/account_invoice/tests/test_module.py | 4 ++- modules/account_payment/tests/test_module.py | 4 ++- .../tests/test_module.py | 3 +- .../account_payment_sepa/tests/test_module.py | 4 ++- .../tests/test_module.py | 3 +- .../account_statement/tests/test_module.py | 4 ++- modules/bank/tests/test_module.py | 3 +- modules/carrier/tests/test_module.py | 3 +- modules/commission/tests/test_module.py | 4 ++- modules/company/tests/test_module.py | 6 ++-- modules/party/tests/__init__.py | 4 +-- modules/party/tests/test_module.py | 30 ++++++++++++++++++- modules/project/tests/test_module.py | 4 ++- modules/purchase/tests/test_module.py | 4 ++- modules/purchase_request/tests/test_module.py | 3 +- modules/sale/tests/test_module.py | 4 ++- modules/sale_opportunity/tests/test_module.py | 4 ++- .../sale_subscription/tests/test_module.py | 4 ++- .../tests/test_module.py | 4 ++- modules/stock/tests/test_module.py | 4 ++- modules/web_shop_shopify/tests/test_module.py | 3 +- modules/web_user/tests/test_module.py | 6 ++-- 23 files changed, 90 insertions(+), 26 deletions(-) diff --git a/modules/account/tests/test_module.py b/modules/account/tests/test_module.py index 64d2e9b66a..41521b0994 100644 --- a/modules/account/tests/test_module.py +++ b/modules/account/tests/test_module.py @@ -13,6 +13,7 @@ from trytond.modules.account.tax import TaxableMixin from trytond.modules.company.tests import ( CompanyTestMixin, PartyCompanyCheckEraseMixin, create_company, set_company) from trytond.modules.currency.tests import create_currency +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction from trytond.transaction import Transaction, inactive_records @@ -167,7 +168,8 @@ def close_fiscalyear(fiscalyear): class AccountTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test Account module' module = 'account' maxDiff = None diff --git a/modules/account_invoice/tests/test_module.py b/modules/account_invoice/tests/test_module.py index 6c98309077..647718dfb6 100644 --- a/modules/account_invoice/tests/test_module.py +++ b/modules/account_invoice/tests/test_module.py @@ -9,6 +9,7 @@ from trytond.modules.account_invoice.exceptions import ( from trytond.modules.company.tests import ( CompanyTestMixin, PartyCompanyCheckEraseMixin) from trytond.modules.currency.tests import create_currency +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction @@ -35,7 +36,8 @@ def set_invoice_sequences(fiscalyear): class AccountInvoiceTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test AccountInvoice module' module = 'account_invoice' diff --git a/modules/account_payment/tests/test_module.py b/modules/account_payment/tests/test_module.py index 011e743389..a3c4e24d13 100644 --- a/modules/account_payment/tests/test_module.py +++ b/modules/account_payment/tests/test_module.py @@ -3,11 +3,13 @@ from trytond.modules.company.tests import ( CompanyTestMixin, PartyCompanyCheckEraseMixin) +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.tests.test_tryton import ModuleTestCase class AccountPaymentTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test Account Payment module' module = 'account_payment' extras = ['account_invoice', 'account_statement', 'account_statement_rule'] diff --git a/modules/account_payment_braintree/tests/test_module.py b/modules/account_payment_braintree/tests/test_module.py index ef5ca8e19c..9ca33e9689 100644 --- a/modules/account_payment_braintree/tests/test_module.py +++ b/modules/account_payment_braintree/tests/test_module.py @@ -1,10 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.tests.test_tryton import ModuleTestCase -class AccountPaymentBraintreeTestCase(ModuleTestCase): +class AccountPaymentBraintreeTestCase(PartyCheckReplaceMixin, ModuleTestCase): 'Test Account Payment Braintree module' module = 'account_payment_braintree' diff --git a/modules/account_payment_sepa/tests/test_module.py b/modules/account_payment_sepa/tests/test_module.py index 91e9d1e2d0..5cc00f63cd 100644 --- a/modules/account_payment_sepa/tests/test_module.py +++ b/modules/account_payment_sepa/tests/test_module.py @@ -15,6 +15,7 @@ from trytond.modules.account_payment_sepa.payment import CAMT054 from trytond.modules.company.tests import ( CompanyTestMixin, create_company, set_company) from trytond.modules.currency.tests import create_currency +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction from trytond.transaction import Transaction @@ -149,7 +150,8 @@ def validate_file(flavor, kind, xsd=None): schema.assertValid(sepa_xml) -class AccountPaymentSepaTestCase(CompanyTestMixin, ModuleTestCase): +class AccountPaymentSepaTestCase( + PartyCheckReplaceMixin, CompanyTestMixin, ModuleTestCase): 'Test Account Payment SEPA module' module = 'account_payment_sepa' diff --git a/modules/account_payment_stripe/tests/test_module.py b/modules/account_payment_stripe/tests/test_module.py index a6a9e3334c..10b2e99d0b 100644 --- a/modules/account_payment_stripe/tests/test_module.py +++ b/modules/account_payment_stripe/tests/test_module.py @@ -1,10 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.tests.test_tryton import ModuleTestCase -class AccountPaymentStripeTestCase(ModuleTestCase): +class AccountPaymentStripeTestCase(PartyCheckReplaceMixin, ModuleTestCase): 'Test Account Payment Stripe module' module = 'account_payment_stripe' diff --git a/modules/account_statement/tests/test_module.py b/modules/account_statement/tests/test_module.py index 39461b5444..2c9ff994ac 100644 --- a/modules/account_statement/tests/test_module.py +++ b/modules/account_statement/tests/test_module.py @@ -2,10 +2,12 @@ # this repository contains the full copyright notices and license terms. from trytond.modules.company.tests import CompanyTestMixin +from trytond.modules.party.tests import PartyCheckEraseMixin from trytond.tests.test_tryton import ModuleTestCase -class AccountStatementTestCase(CompanyTestMixin, ModuleTestCase): +class AccountStatementTestCase( + CompanyTestMixin, PartyCheckEraseMixin, ModuleTestCase): 'Test AccountStatement module' module = 'account_statement' diff --git a/modules/bank/tests/test_module.py b/modules/bank/tests/test_module.py index 7d600ea1f1..bfcf65b68b 100644 --- a/modules/bank/tests/test_module.py +++ b/modules/bank/tests/test_module.py @@ -11,11 +11,12 @@ except ImportError: from trytond.model.exceptions import SQLConstraintError from trytond.modules.bank.exceptions import InvalidBIC from trytond.modules.currency.tests import create_currency +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction -class BankTestCase(ModuleTestCase): +class BankTestCase(PartyCheckReplaceMixin, ModuleTestCase): 'Test Bank module' module = 'bank' diff --git a/modules/carrier/tests/test_module.py b/modules/carrier/tests/test_module.py index a55058bf9a..50179eaff2 100644 --- a/modules/carrier/tests/test_module.py +++ b/modules/carrier/tests/test_module.py @@ -4,6 +4,7 @@ from decimal import Decimal from trytond.modules.company.tests import create_company, set_company +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction @@ -35,7 +36,7 @@ def create_carrier(list_price=None, cost_price=None): return carrier -class CarrierTestCase(ModuleTestCase): +class CarrierTestCase(PartyCheckReplaceMixin, ModuleTestCase): 'Test Carrier module' module = 'carrier' diff --git a/modules/commission/tests/test_module.py b/modules/commission/tests/test_module.py index 26f916cb98..f08f389c18 100644 --- a/modules/commission/tests/test_module.py +++ b/modules/commission/tests/test_module.py @@ -5,6 +5,7 @@ from decimal import Decimal from trytond.modules.company.tests import ( CompanyTestMixin, PartyCompanyCheckEraseMixin, create_company, set_company) +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction @@ -46,7 +47,8 @@ def create_plan(lines): class CommissionTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test Commission module' module = 'commission' extras = ['sale', 'stock', 'account_invoice_stock'] diff --git a/modules/company/tests/test_module.py b/modules/company/tests/test_module.py index 5db7d58fc0..be27984e52 100644 --- a/modules/company/tests/test_module.py +++ b/modules/company/tests/test_module.py @@ -10,7 +10,8 @@ from unittest.mock import patch from trytond.model import ModelStorage, ModelView from trytond.modules.company.model import CompanyMultiValueMixin from trytond.modules.currency.tests import add_currency_rate, create_currency -from trytond.modules.party.tests import PartyCheckEraseMixin +from trytond.modules.party.tests import ( + PartyCheckEraseMixin, PartyCheckReplaceMixin) from trytond.pool import Pool, isregisteredby from trytond.pyson import Eval, PYSONEncoder from trytond.tests.test_tryton import ModuleTestCase, with_transaction @@ -152,7 +153,8 @@ class CompanyTestMixin: class CompanyTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test Company module' module = 'company' diff --git a/modules/party/tests/__init__.py b/modules/party/tests/__init__.py index 80f92fc36a..c6c44141a3 100644 --- a/modules/party/tests/__init__.py +++ b/modules/party/tests/__init__.py @@ -1,6 +1,6 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from .test_module import PartyCheckEraseMixin +from .test_module import PartyCheckEraseMixin, PartyCheckReplaceMixin -__all__ = ['PartyCheckEraseMixin'] +__all__ = [PartyCheckEraseMixin, PartyCheckReplaceMixin] diff --git a/modules/party/tests/test_module.py b/modules/party/tests/test_module.py index 2333b56ce6..b50fbaf128 100644 --- a/modules/party/tests/test_module.py +++ b/modules/party/tests/test_module.py @@ -16,6 +16,7 @@ from trytond.modules.party.party import ( IDENTIFIER_TYPES, IDENTIFIER_VAT, replace_vat) from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction +from trytond.tools import is_instance_method from trytond.transaction import Transaction @@ -43,7 +44,34 @@ class PartyCheckEraseMixin: return party -class PartyTestCase(PartyCheckEraseMixin, ModuleTestCase): +class PartyCheckReplaceMixin: + + @with_transaction() + def test_check_replace_party(self): + "Test fields to replace" + pool = Pool() + Replace = pool.get('party.replace', type='wizard') + + for model_name, field_name in Replace.fields_to_replace(): + with self.subTest(model_name=model_name, field_name=field_name): + Model = pool.get(model_name) + field = getattr(Model, field_name) + if field._type == 'reference': + if isinstance(field.selection, (tuple, list)): + self.assertIn('party.party', dict(field.selection)) + else: + sel_func = getattr(Model, field.selection) + instance_sel_func = is_instance_method( + Model, field.selection) + if not instance_sel_func: + self.assertIn('party.party', dict(sel_func())) + else: + self.assertEqual(field._type, 'many2one') + self.assertEqual(field.model_name, 'party.party') + + +class PartyTestCase( + PartyCheckEraseMixin, PartyCheckReplaceMixin, ModuleTestCase): 'Test Party module' module = 'party' diff --git a/modules/project/tests/test_module.py b/modules/project/tests/test_module.py index f27fa7b4ff..d644a35866 100644 --- a/modules/project/tests/test_module.py +++ b/modules/project/tests/test_module.py @@ -4,13 +4,15 @@ import datetime from trytond.modules.company.tests import ( CompanyTestMixin, PartyCompanyCheckEraseMixin, create_company, set_company) +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction from trytond.transaction import Transaction class ProjectTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test Project module' module = 'project' diff --git a/modules/purchase/tests/test_module.py b/modules/purchase/tests/test_module.py index 80dbcb4302..bd624f1b21 100644 --- a/modules/purchase/tests/test_module.py +++ b/modules/purchase/tests/test_module.py @@ -7,13 +7,15 @@ from decimal import Decimal from trytond.modules.account.tests import create_chart from trytond.modules.company.tests import ( CompanyTestMixin, PartyCompanyCheckEraseMixin, create_company, set_company) +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction from trytond.transaction import Transaction class PurchaseTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test Purchase module' module = 'purchase' diff --git a/modules/purchase_request/tests/test_module.py b/modules/purchase_request/tests/test_module.py index 55fd8d905a..b938e94ff5 100644 --- a/modules/purchase_request/tests/test_module.py +++ b/modules/purchase_request/tests/test_module.py @@ -4,11 +4,12 @@ import datetime as dt from trytond.modules.company.tests import create_company, set_company +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction -class PurchaseRequestTestCase(ModuleTestCase): +class PurchaseRequestTestCase(PartyCheckReplaceMixin, ModuleTestCase): 'Test Purchase Request module' module = 'purchase_request' diff --git a/modules/sale/tests/test_module.py b/modules/sale/tests/test_module.py index 631757fe75..82cdcf5320 100644 --- a/modules/sale/tests/test_module.py +++ b/modules/sale/tests/test_module.py @@ -5,13 +5,15 @@ from decimal import Decimal from trytond.modules.account.tests import create_chart from trytond.modules.company.tests import ( CompanyTestMixin, PartyCompanyCheckEraseMixin, create_company, set_company) +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction from trytond.transaction import Transaction class SaleTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test Sale module' module = 'sale' diff --git a/modules/sale_opportunity/tests/test_module.py b/modules/sale_opportunity/tests/test_module.py index b8daff020c..0a70763e00 100644 --- a/modules/sale_opportunity/tests/test_module.py +++ b/modules/sale_opportunity/tests/test_module.py @@ -2,10 +2,12 @@ # this repository contains the full copyright notices and license terms. from trytond.modules.company.tests import CompanyTestMixin +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.tests.test_tryton import ModuleTestCase -class SaleOpportunityTestCase(CompanyTestMixin, ModuleTestCase): +class SaleOpportunityTestCase( + PartyCheckReplaceMixin, CompanyTestMixin, ModuleTestCase): 'Test SaleOpportunity module' module = 'sale_opportunity' diff --git a/modules/sale_subscription/tests/test_module.py b/modules/sale_subscription/tests/test_module.py index 5d6112c0e8..f2ce8dae86 100644 --- a/modules/sale_subscription/tests/test_module.py +++ b/modules/sale_subscription/tests/test_module.py @@ -3,11 +3,13 @@ from trytond.modules.company.tests import ( CompanyTestMixin, PartyCompanyCheckEraseMixin) +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.tests.test_tryton import ModuleTestCase class SaleSubscriptionTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test Sale Subscription module' module = 'sale_subscription' diff --git a/modules/sale_supply_drop_shipment/tests/test_module.py b/modules/sale_supply_drop_shipment/tests/test_module.py index 1ff1268c7f..cec088139e 100644 --- a/modules/sale_supply_drop_shipment/tests/test_module.py +++ b/modules/sale_supply_drop_shipment/tests/test_module.py @@ -3,11 +3,13 @@ from trytond.modules.company.tests import ( CompanyTestMixin, PartyCompanyCheckEraseMixin) +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.tests.test_tryton import ModuleTestCase class SaleSupplyDropShipmentTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test SaleSupplyDropShipment module' module = 'sale_supply_drop_shipment' extras = ['sale_amendment', 'stock_split'] diff --git a/modules/stock/tests/test_module.py b/modules/stock/tests/test_module.py index eb9713bd5d..42fe6ab160 100644 --- a/modules/stock/tests/test_module.py +++ b/modules/stock/tests/test_module.py @@ -11,6 +11,7 @@ from dateutil.relativedelta import relativedelta from trytond.model.exceptions import AccessError from trytond.modules.company.tests import ( CompanyTestMixin, PartyCompanyCheckEraseMixin, create_company, set_company) +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.modules.stock.exceptions import ( LocationValidationError, MoveOriginWarning, PeriodCloseError, ProductStockWarning) @@ -20,7 +21,8 @@ from trytond.transaction import Transaction, check_access class StockTestCase( - PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase): + PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin, + ModuleTestCase): 'Test Stock module' module = 'stock' longMessage = True diff --git a/modules/web_shop_shopify/tests/test_module.py b/modules/web_shop_shopify/tests/test_module.py index b0ee4d9544..52291664cb 100644 --- a/modules/web_shop_shopify/tests/test_module.py +++ b/modules/web_shop_shopify/tests/test_module.py @@ -1,10 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from trytond.modules.party.tests import PartyCheckReplaceMixin from trytond.tests.test_tryton import ModuleTestCase -class WebShopShopifyTestCase(ModuleTestCase): +class WebShopShopifyTestCase(PartyCheckReplaceMixin, ModuleTestCase): 'Test Web Shop Shopify module' module = 'web_shop_shopify' diff --git a/modules/web_user/tests/test_module.py b/modules/web_user/tests/test_module.py index 4b53bd8778..0e6f50d569 100644 --- a/modules/web_user/tests/test_module.py +++ b/modules/web_user/tests/test_module.py @@ -4,7 +4,8 @@ from unittest.mock import patch import trytond.config as config -from trytond.modules.party.tests import PartyCheckEraseMixin +from trytond.modules.party.tests import ( + PartyCheckEraseMixin, PartyCheckReplaceMixin) from trytond.modules.web_user import user as user_module from trytond.pool import Pool from trytond.tests.test_tryton import ModuleTestCase, with_transaction @@ -14,7 +15,8 @@ RESET_PASSWORD_URL = 'http://www.example.com/reset_password' FROM = 'tryton@example.com' -class WebUserTestCase(PartyCheckEraseMixin, ModuleTestCase): +class WebUserTestCase( + PartyCheckEraseMixin, PartyCheckReplaceMixin, ModuleTestCase): 'Test Web User module' module = 'web_user'