From ebb6d71be3940a465b40d44dd148271a2d895981 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Wed, 7 Jun 2023 19:24:43 +0200 Subject: [PATCH] test: add context to product-create --- tests/asset.py | 82 +++++++++++++++++++++++++++---------------------- tests/rate.py | 8 +++-- tests/source.py | 7 +++-- 3 files changed, 55 insertions(+), 42 deletions(-) diff --git a/tests/asset.py b/tests/asset.py index f63395c..98497d1 100644 --- a/tests/asset.py +++ b/tests/asset.py @@ -80,9 +80,10 @@ class AssetTestCase(object): Asset = Pool().get('investment.asset') company = self.prep_asset_company() - product = self.prep_asset_product( - name='Product 1', - description='some asset') + with Transaction().set_context({'company': company.id}): + product = self.prep_asset_product( + name='Product 1', + description='some asset') asset = self.prep_asset_item( company=company, @@ -111,9 +112,10 @@ class AssetTestCase(object): Asset = Pool().get('investment.asset') company = self.prep_asset_company() - product = self.prep_asset_product( - name='Product 1', - description='some asset') + with Transaction().set_context({'company': company.id}): + product = self.prep_asset_product( + name='Product 1', + description='some asset') asset = self.prep_asset_item( company=company, @@ -141,12 +143,13 @@ class AssetTestCase(object): Asset = Pool().get('investment.asset') company = self.prep_asset_company() - product1 = self.prep_asset_product( - name='Product 1', - description='some asset') - product2 = self.prep_asset_product( - name='Product 2', - description='some asset') + with Transaction().set_context({'company': company.id}): + product1 = self.prep_asset_product( + name='Product 1', + description='some asset') + product2 = self.prep_asset_product( + name='Product 2', + description='some asset') asset1 = self.prep_asset_item( company=company, @@ -223,9 +226,10 @@ class AssetTestCase(object): cursor = Transaction().connection.cursor() company = self.prep_asset_company() - product = self.prep_asset_product( - name='Product 1', - description='some asset') + with Transaction().set_context({'company': company.id}): + product = self.prep_asset_product( + name='Product 1', + description='some asset') asset1 = self.prep_asset_item( company=company, @@ -289,9 +293,10 @@ class AssetTestCase(object): Asset = Pool().get('investment.asset') company = self.prep_asset_company() - product = self.prep_asset_product( - name='Product 1', - description='some asset') + with Transaction().set_context({'company': company.id}): + product = self.prep_asset_product( + name='Product 1', + description='some asset') asset1 = self.prep_asset_item( company=company, @@ -399,9 +404,10 @@ class AssetTestCase(object): Asset = Pool().get('investment.asset') company = self.prep_asset_company() - product = self.prep_asset_product( - name='Product 1', - description='some asset') + with Transaction().set_context({'company': company.id}): + product = self.prep_asset_product( + name='Product 1', + description='some asset') asset1 = self.prep_asset_item( company=company, @@ -484,9 +490,10 @@ class AssetTestCase(object): OnlineSource = pool.get('investment.source') company = self.prep_asset_company() - product = self.prep_asset_product( - name='Product 1', - description='some asset') + with Transaction().set_context({'company': company.id}): + product = self.prep_asset_product( + name='Product 1', + description='some asset') asset = self.prep_asset_item( company=company, @@ -521,9 +528,10 @@ class AssetTestCase(object): Asset = pool.get('investment.asset') company = self.prep_asset_company() - product = self.prep_asset_product( - name='Product 1', - description='some asset') + with Transaction().set_context({'company': company.id}): + product = self.prep_asset_product( + name='Product 1', + description='some asset') asset = self.prep_asset_item( company=company, @@ -626,10 +634,11 @@ class AssetTestCase(object): Asset = pool.get('investment.asset') company = self.prep_asset_company() - product1 = self.prep_asset_product( - name='Product unit', unit='u') - product2 = self.prep_asset_product( - name='Product gram', unit='g') + with Transaction().set_context({'company': company.id}): + product1 = self.prep_asset_product( + name='Product unit', unit='u') + product2 = self.prep_asset_product( + name='Product gram', unit='g') asset1 = self.prep_asset_item(company=company, product=product1) asset2 = self.prep_asset_item(company=company, product=product2) @@ -733,11 +742,12 @@ class AssetTestCase(object): """ check update of product on asset """ company = self.prep_asset_company() - product1 = self.prep_asset_product( - name='Product unit', unit='u') - product2 = self.prep_asset_product( - name='Product gram', unit='g') - self.assertEqual(product2.default_uom.digits, 2) + with Transaction().set_context({'company': company.id}): + product1 = self.prep_asset_product( + name='Product unit', unit='u') + product2 = self.prep_asset_product( + name='Product gram', unit='g') + self.assertEqual(product2.default_uom.digits, 2) asset = self.prep_asset_item(company=company, product=product1) diff --git a/tests/rate.py b/tests/rate.py index 175cf5f..bc8b75d 100644 --- a/tests/rate.py +++ b/tests/rate.py @@ -4,6 +4,7 @@ # full copyright notices and license terms. from trytond.tests.test_tryton import with_transaction +from trytond.transaction import Transaction from trytond.pool import Pool from decimal import Decimal from datetime import date @@ -19,9 +20,10 @@ class RateTestCase(object): Asset = Pool().get('investment.asset') company = self.prep_asset_company() - product = self.prep_asset_product( - name='Product 1', - description='some asset') + with Transaction().set_context({'company': company.id}): + product = self.prep_asset_product( + name='Product 1', + description='some asset') asset = self.prep_asset_item( company=company, diff --git a/tests/source.py b/tests/source.py index d1456a9..141463a 100644 --- a/tests/source.py +++ b/tests/source.py @@ -36,9 +36,10 @@ class SourceTestCase(object): }]) self.assertEqual(osource.rec_name, 'Source 1') - product = self.prep_asset_product( - name='Product 1', - description='some asset') + with Transaction().set_context({'company': company.id}): + product = self.prep_asset_product( + name='Product 1', + description='some asset') Product.write(*[ [product],