/usr/lib/python3/dist-packages/trytond/tests/test_multivalue.py is in tryton-server 4.6.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | # This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import unittest
from trytond.tests.test_tryton import activate_module, with_transaction
from trytond.pool import Pool
class MultiValueTestCase(unittest.TestCase):
"Test MultiValue"
@classmethod
def setUpClass(cls):
activate_module('tests')
@with_transaction()
def test_get_multivalue(self):
"Test get_multivalue"
pool = Pool()
ModelMultiValue = pool.get('test.model_multivalue')
ModelValue = pool.get('test.model_multivalue.value')
record = ModelMultiValue()
record.save()
value, = ModelValue.search([])
value.condition = "foo"
value.value = "bar"
value.save()
self.assertEqual(
record.get_multivalue('value', condition="foo"),
"bar")
@with_transaction()
def test_get_multivalue_default(self):
"Test get_multivalue default value"
pool = Pool()
ModelMultiValue = pool.get('test.model_multivalue')
record = ModelMultiValue()
record.save()
self.assertEqual(record.get_multivalue('value'), "default")
@with_transaction()
def test_get_multivalue_match_none(self):
"Test get_multivalue does not match None"
pool = Pool()
ModelMultiValue = pool.get('test.model_multivalue')
ModelValue = pool.get('test.model_multivalue.value')
record = ModelMultiValue()
record.save()
value = ModelValue(record=record, condition="foo", value="bar")
value.save()
self.assertEqual(
record.get_multivalue('value', condition="test"),
"default")
@with_transaction()
def test_set_multivalue(self):
"Test set_multivalue"
pool = Pool()
ModelMultiValue = pool.get('test.model_multivalue')
ModelValue = pool.get('test.model_multivalue.value')
record = ModelMultiValue()
record.save()
record.set_multivalue('value', "set", condition="test")
value, = ModelValue.search([('condition', '=', "test")])
self.assertEqual(value.record, record)
self.assertEqual(value.value, "set")
@with_transaction()
def test_set_multivalue_match_none(self):
"Test set_multivalue matches None"
pool = Pool()
ModelMultiValue = pool.get('test.model_multivalue')
ModelValue = pool.get('test.model_multivalue.value')
record = ModelMultiValue()
record.save()
record.set_multivalue('value', "set", condition="test")
self.assertEqual(len(ModelValue.search([])), 2)
@with_transaction()
def test_mutlivalue_setter(self):
"Test multivalue setter"
pool = Pool()
ModelMultiValue = pool.get('test.model_multivalue')
record, = ModelMultiValue.create([{
'value': "setter",
}])
self.assertEqual(record.get_multivalue('value'), "setter")
@with_transaction()
def test_mutlivalue_getter(self):
"Test multivalue getter"
pool = Pool()
ModelMultiValue = pool.get('test.model_multivalue')
record = ModelMultiValue(value="getter")
record.save()
read, = ModelMultiValue.read([record.id], ['value'])
self.assertEqual(read['value'], "getter")
def suite():
return unittest.TestLoader().loadTestsFromTestCase(MultiValueTestCase)
|