changeset 50a7bcc0a36b in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=50a7bcc0a36b
description:
        Test 'id' not removed from read result when in context field

        issue8470
        review263841002
diffstat:

 trytond/tests/modelsql.py      |  10 ++++++++++
 trytond/tests/test_modelsql.py |  11 +++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diffs (55 lines):

diff -r 03f313fcebba -r 50a7bcc0a36b trytond/tests/modelsql.py
--- a/trytond/tests/modelsql.py Mon Jul 08 21:30:43 2019 +0200
+++ b/trytond/tests/modelsql.py Mon Jul 08 21:31:26 2019 +0200
@@ -4,6 +4,7 @@
 
 from trytond.model import ModelSQL, fields, Check, Unique, Exclude
 from trytond.pool import Pool
+from trytond.pyson import Eval
 
 
 class ModelSQLRead(ModelSQL):
@@ -24,6 +25,14 @@
     target = fields.Many2One('test.modelsql.read.target', "Target")
 
 
+class ModelSQLReadContextID(ModelSQL):
+    "ModelSQL to test read with ID in context"
+    __name__ = 'test.modelsql.read.context_id'
+    name = fields.Char("Name", context={
+            'test': Eval('id'),
+            })
+
+
 class ModelSQLRequiredField(ModelSQL):
     'model with a required field'
     __name__ = 'test.modelsql'
@@ -131,6 +140,7 @@
     Pool.register(
         ModelSQLRead,
         ModelSQLReadTarget,
+        ModelSQLReadContextID,
         ModelSQLRequiredField,
         ModelSQLTimestamp,
         ModelSQLFieldSet,
diff -r 03f313fcebba -r 50a7bcc0a36b trytond/tests/test_modelsql.py
--- a/trytond/tests/test_modelsql.py    Mon Jul 08 21:30:43 2019 +0200
+++ b/trytond/tests/test_modelsql.py    Mon Jul 08 21:31:26 2019 +0200
@@ -36,6 +36,17 @@
             [{'id': foo.id, 'name': "Foo"}, {'id': bar.id, 'name': "Bar"}])
 
     @with_transaction()
+    def test_read_context_id(self):
+        "Test read with ID in context of field"
+        pool = Pool()
+        Model = pool.get('test.modelsql.read.context_id')
+
+        record, = Model.create([{'name': "Record"}])
+        values = Model.read([record.id], ['name'])
+
+        self.assertEqual(values, [{'id': record.id, 'name': "Record"}])
+
+    @with_transaction()
     def test_read_related_2one(self):
         "Test read with related Many2One"
         pool = Pool()

Reply via email to