changeset 183fea18d0fe in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=183fea18d0fe
description:
        Add test for relation with PYSON domain

        issue9383
        review317531002
diffstat:

 trytond/tests/modelstorage.py      |  11 ++++++++++-
 trytond/tests/test_modelstorage.py |  27 +++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletions(-)

diffs (65 lines):

diff -r 728cb4a36144 -r 183fea18d0fe trytond/tests/modelstorage.py
--- a/trytond/tests/modelstorage.py     Fri Jun 12 12:36:47 2020 +0200
+++ b/trytond/tests/modelstorage.py     Fri Jun 12 12:37:50 2020 +0200
@@ -1,7 +1,7 @@
 # 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.model import ModelSQL, ModelStorage as ModelStorage_, fields
-from trytond.pyson import Eval
+from trytond.pyson import Eval, If
 from trytond.transaction import Transaction
 from trytond.pool import Pool
 
@@ -69,6 +69,15 @@
         domain=[
             ('value', '=', 'valid'),
             ])
+    relation_valid = fields.Boolean("Relation Valid")
+    relation_pyson = fields.Many2One(
+        'test.modelstorage.relation_domain.target', "Value",
+        domain=[
+            If(Eval('relation_valid', True),
+                ('value', '=', 'valid'),
+                ('value', '!=', 'valid')),
+            ],
+        depends=['relation_valid'])
 
 
 class ModelStorageRelationDomainTarget(ModelSQL):
diff -r 728cb4a36144 -r 183fea18d0fe trytond/tests/test_modelstorage.py
--- a/trytond/tests/test_modelstorage.py        Fri Jun 12 12:36:47 2020 +0200
+++ b/trytond/tests/test_modelstorage.py        Fri Jun 12 12:37:50 2020 +0200
@@ -367,6 +367,33 @@
         self.assertTrue(cm.exception.domain[1]['value'])
 
     @with_transaction()
+    def test_relation_pyson_domain(self):
+        "Test valid relation with PYSON"
+        pool = Pool()
+        Model = pool.get('test.modelstorage.relation_domain')
+        Target = pool.get('test.modelstorage.relation_domain.target')
+
+        target, = Target.create([{'value': 'valid'}])
+
+        record, = Model.create(
+            [{'relation_pyson': target.id, 'relation_valid': True}])
+
+    @with_transaction()
+    def test_relation_pyson_domain_invalid(self):
+        "Test valid relation with PYSON"
+        pool = Pool()
+        Model = pool.get('test.modelstorage.relation_domain')
+        Target = pool.get('test.modelstorage.relation_domain.target')
+
+        target, = Target.create([{'value': 'valid'}])
+
+        with self.assertRaises(DomainValidationError) as cm:
+            Model.create(
+                [{'relation_pyson': target.id, 'relation_valid': False}])
+        self.assertEqual(cm.exception.domain[0], [['value', '!=', 'valid']])
+        self.assertTrue(cm.exception.domain[1], 'value')
+
+    @with_transaction()
     def test_relation2_domain_invalid(self):
         "Test invalid relation domain with 2 level"
         pool = Pool()

Reply via email to