Files
tryton/trytond/tests/test_backend.py
T
Cédric Krier 190657e0ef Make CurrentTimestamp transactional for SQLite backend
It must return the same timestamp during the all transaction.

issue8457
review271641002
2019-07-08 21:27:55 +02:00

65 lines
1.9 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 sql import Select
from sql.functions import CurrentTimestamp
from trytond.tests.test_tryton import activate_module, with_transaction
from trytond.transaction import Transaction
class BackendTestCase(unittest.TestCase):
"Test the backend"
@classmethod
def setUpClass(cls):
activate_module('tests')
@with_transaction()
def test_current_timestamp_static_transaction(self):
"Test CURRENT_TIMESTAMP is static during transaction"
query = Select([CurrentTimestamp()])
cursor = Transaction().connection.cursor()
cursor.execute(*query)
current, = cursor.fetchone()
cursor.execute(*query)
second, = cursor.fetchone()
self.assertEqual(current, second)
@with_transaction()
def test_current_timestamp_reset_after_commit(self):
"Test CURRENT_TIMESTAMP is reset after commit"
query = Select([CurrentTimestamp()])
cursor = Transaction().connection.cursor()
cursor.execute(*query)
current, = cursor.fetchone()
Transaction().commit()
cursor.execute(*query)
second, = cursor.fetchone()
self.assertNotEqual(current, second)
@with_transaction()
def test_current_timestamp_different_transaction(self):
"Test CURRENT_TIMESTAMP is different per transaction"
query = Select([CurrentTimestamp()])
cursor = Transaction().connection.cursor()
cursor.execute(*query)
current, = cursor.fetchone()
with Transaction().new_transaction() as transaction:
cursor = transaction.connection.cursor()
cursor.execute(*query)
second, = cursor.fetchone()
self.assertNotEqual(current, second)
def suite():
return unittest.TestLoader().loadTestsFromTestCase(BackendTestCase)