diff options
| author | Adam Chainz <adam@adamj.eu> | 2015-06-01 18:00:34 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-06-15 14:03:17 -0400 |
| commit | d34d39ade76e6b67299d8d88a7e5a2278a793dc3 (patch) | |
| tree | 60b65b404ce1e901eecb65fc7de3f99817d080ad /tests/postgres_tests/test_functions.py | |
| parent | 3872a33132a4bb6aa22b237927597bbfdf6f21d7 (diff) | |
Fixed #24894 -- Added contrib.postgres.functions.TransactionNow
Diffstat (limited to 'tests/postgres_tests/test_functions.py')
| -rw-r--r-- | tests/postgres_tests/test_functions.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_functions.py b/tests/postgres_tests/test_functions.py new file mode 100644 index 0000000000..620b561325 --- /dev/null +++ b/tests/postgres_tests/test_functions.py @@ -0,0 +1,28 @@ +from datetime import datetime +from time import sleep + +from django.contrib.postgres.functions import TransactionNow + +from . import PostgreSQLTestCase +from .models import NowTestModel + + +class TestTransactionNow(PostgreSQLTestCase): + + def test_transaction_now(self): + """ + The test case puts everything under a transaction, so two models + updated with a short gap should have the same time. + """ + m1 = NowTestModel.objects.create() + m2 = NowTestModel.objects.create() + + NowTestModel.objects.filter(id=m1.id).update(when=TransactionNow()) + sleep(0.1) + NowTestModel.objects.filter(id=m2.id).update(when=TransactionNow()) + + m1.refresh_from_db() + m2.refresh_from_db() + + self.assertIsInstance(m1.when, datetime) + self.assertEqual(m1.when, m2.when) |
