Files
tryton/trytond/tests/test_modelstorage.py
T
Cédric Krier da1be07832 Make TestCase create and drop its database
and add with_transaction decorator.

issue5263
review20711002
2016-02-06 19:10:35 +01:00

40 lines
1.2 KiB
Python

# 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.pool import Pool
from trytond.tests.test_tryton import install_module, with_transaction
class ModelStorageTestCase(unittest.TestCase):
'Test ModelStorage'
@classmethod
def setUpClass(cls):
install_module('tests')
@with_transaction()
def test_search_read_order(self):
'Test search_read order'
pool = Pool()
ModelStorage = pool.get('test.modelstorage')
ModelStorage.create([{'name': i} for i in ['foo', 'bar', 'test']])
rows = ModelStorage.search_read([])
self.assertTrue(
all(x['id'] < y['id'] for x, y in zip(rows, rows[1:])))
rows = ModelStorage.search_read([], order=[('name', 'ASC')])
self.assertTrue(
all(x['name'] <= y['name'] for x, y in zip(rows, rows[1:])))
rows = ModelStorage.search_read([], order=[('name', 'DESC')])
self.assertTrue(
all(x['name'] >= y['name'] for x, y in zip(rows, rows[1:])))
def suite():
return unittest.TestLoader().loadTestsFromTestCase(ModelStorageTestCase)