Add test on browsing history
review5451002
This commit is contained in:
@@ -150,6 +150,7 @@ def register():
|
||||
Many2OneTarget,
|
||||
Many2OneDomainValidation,
|
||||
TestHistory,
|
||||
TestHistoryLine,
|
||||
module='tests', type_='model')
|
||||
Pool.register(
|
||||
TestWizard,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import ModelSQL, fields
|
||||
|
||||
__all__ = ['TestHistory']
|
||||
__all__ = ['TestHistory', 'TestHistoryLine']
|
||||
|
||||
|
||||
class TestHistory(ModelSQL):
|
||||
@@ -10,3 +10,12 @@ class TestHistory(ModelSQL):
|
||||
__name__ = 'test.history'
|
||||
_history = True
|
||||
value = fields.Integer('Value')
|
||||
lines = fields.One2Many('test.history.line', 'history', 'Lines')
|
||||
|
||||
|
||||
class TestHistoryLine(ModelSQL):
|
||||
'Test History Line'
|
||||
__name__ = 'test.history.line'
|
||||
_history = True
|
||||
history = fields.Many2One('test.history', 'History')
|
||||
name = fields.Char('Name')
|
||||
|
||||
@@ -320,6 +320,59 @@ class HistoryTestCase(unittest.TestCase):
|
||||
self.assertEqual(records, instances)
|
||||
self.assertEqual([x.value for x in records], values)
|
||||
|
||||
def test0070_browse(self):
|
||||
'Test browsing history'
|
||||
History = POOL.get('test.history')
|
||||
Line = POOL.get('test.history.line')
|
||||
|
||||
with Transaction().start(DB_NAME, USER,
|
||||
context=CONTEXT) as transaction:
|
||||
history = History(value=1)
|
||||
history.save()
|
||||
history_id = history.id
|
||||
line_a = Line(name='a', history=history)
|
||||
line_a.save()
|
||||
line_a_id = line_a.id
|
||||
line_b = Line(name='b', history=history)
|
||||
line_b.save()
|
||||
line_b_id = line_b.id
|
||||
|
||||
first_stamp = line_b.create_date
|
||||
|
||||
transaction.cursor.commit()
|
||||
|
||||
with Transaction().start(DB_NAME, USER,
|
||||
context=CONTEXT) as transaction:
|
||||
history = History(history_id)
|
||||
history.value = 2
|
||||
history.save()
|
||||
|
||||
Line.delete([Line(line_b_id)])
|
||||
|
||||
line_a = Line(line_a_id)
|
||||
line_a.name = 'c'
|
||||
line_a.save()
|
||||
|
||||
second_stamp = line_a.write_date
|
||||
|
||||
transaction.cursor.commit()
|
||||
|
||||
with Transaction().start(DB_NAME, USER,
|
||||
context=CONTEXT) as transaction:
|
||||
history = History(history_id)
|
||||
self.assertEqual(history.value, 2)
|
||||
self.assertEqual([l.name for l in history.lines], ['c'])
|
||||
|
||||
with Transaction().set_context(_datetime=first_stamp):
|
||||
history = History(history_id)
|
||||
self.assertEqual(history.value, 1)
|
||||
self.assertEqual([l.name for l in history.lines], ['a', 'b'])
|
||||
|
||||
with Transaction().set_context(_datetime=second_stamp):
|
||||
history = History(history_id)
|
||||
self.assertEqual(history.value, 2)
|
||||
self.assertEqual([l.name for l in history.lines], ['c'])
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(HistoryTestCase)
|
||||
|
||||
Reference in New Issue
Block a user