Add test for copy of One2Many

This commit is contained in:
Cédric Krier committed 2013-02-04 20:03:18 +01:00
1 parent 60d4e28911
commit 289eaac537
4 files changed
+107

No files matched your search

+5
View File
@@ -10,6 +10,7 @@ from .trigger import *
from .access import *
from .wizard import *
from .workflow import *
from .copy import *
def register():
@@ -121,6 +122,10 @@ def register():
TestAccess,
TestWizardStart,
WorkflowedModel,
CopyOne2Many,
CopyOne2ManyTarget,
CopyOne2ManyReference,
CopyOne2ManyReferenceTarget,
module='test', type_='model')
Pool.register(
TestWizard,
+42
View File
@@ -0,0 +1,42 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
"Test for copy"
from trytond.model import ModelSQL, fields
__all__ = [
'CopyOne2Many', 'CopyOne2ManyTarget',
'CopyOne2ManyReference', 'CopyOne2ManyReferenceTarget',
]
class CopyOne2Many(ModelSQL):
"Copy One2Many"
__name__ = 'test.copy.one2many'
name = fields.Char('Name')
one2many = fields.One2Many('test.copy.one2many.target', 'one2many',
'One2Many')
class CopyOne2ManyTarget(ModelSQL):
"Copy One2Many Target"
__name__ = 'test.copy.one2many.target'
name = fields.Char('Name')
one2many = fields.Many2One('test.copy.one2many', 'One2Many')
class CopyOne2ManyReference(ModelSQL):
"Copy One2Many Reference"
__name__ = 'test.copy.one2many_reference'
name = fields.Char('Name')
one2many = fields.One2Many('test.copy.one2many_reference.target',
'one2many', 'One2Many')
class CopyOne2ManyReferenceTarget(ModelSQL):
"Copy One2Many ReferenceTarget"
__name__ = 'test.copy.one2many_reference.target'
name = fields.Char('Name')
one2many = fields.Reference('One2Many', [
(None, ''),
('test.copy.one2many_reference', 'One2Many'),
])
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#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 POOL, DB_NAME, USER, CONTEXT, \
install_module
from trytond.transaction import Transaction
class CopyTestCase(unittest.TestCase):
'''
Test copy.
'''
def setUp(self):
install_module('test')
self.one2many = POOL.get('test.copy.one2many')
self.one2many_target = POOL.get('test.copy.one2many.target')
self.one2many_reference = POOL.get('test.copy.one2many_reference')
self.one2many_reference_target = \
POOL.get('test.copy.one2many_reference.target')
def test0130one2many(self):
'''
Test one2many.
'''
with Transaction().start(DB_NAME, USER,
context=CONTEXT) as transaction:
for One2many, Target in (
(self.one2many, self.one2many_target),
(self.one2many_reference, self.one2many_reference_target),
):
one2many = One2many(name='Test')
one2many.one2many = [
Target(name='Target 1'),
Target(name='Target 2'),
]
one2many.save()
one2many_copy, = One2many.copy([one2many])
self.assertNotEqual(one2many, one2many_copy)
self.assertEqual(len(one2many.one2many),
len(one2many_copy.one2many))
self.assertNotEqual(one2many.one2many, one2many_copy.one2many)
self.assertEqual([x.name for x in one2many.one2many],
[x.name for x in one2many_copy.one2many])
transaction.cursor.rollback()
def suite():
return unittest.TestLoader().loadTestsFromTestCase(CopyTestCase)
if __name__ == '__main__':
suite = suite()
unittest.TextTestRunner(verbosity=2).run(suite)
+2
View File
@@ -261,6 +261,8 @@ def all_suite():
suite_.addTests(test_modelsql.suite())
import trytond.tests.test_cache as test_cache
suite_.addTests(test_cache.suite())
import trytond.tests.test_copy as test_copy
suite_.addTests(test_copy.suite())
return suite_