summaryrefslogtreecommitdiff
path: root/tests/select_for_update
diff options
context:
space:
mode:
authorManuel Weitzman <manuelweitzman@gmail.com>2020-05-10 12:25:06 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-05-21 10:51:10 +0200
commita4e6030904df63b3f10aa0729b86dc6942b0458e (patch)
tree7a84def5f8bd0e0376a471fa238f74f429e25478 /tests/select_for_update
parent0e893248b28e30bf562d29e6d5745ffad4b1a1eb (diff)
downloaddjango-a4e6030904df63b3f10aa0729b86dc6942b0458e.tar.gz
Fixed #30375 -- Added FOR NO KEY UPDATE support to QuerySet.select_for_update() on PostgreSQL.
Diffstat (limited to 'tests/select_for_update')
-rw-r--r--tests/select_for_update/tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/select_for_update/tests.py b/tests/select_for_update/tests.py
index 3622a95c11..2197596a16 100644
--- a/tests/select_for_update/tests.py
+++ b/tests/select_for_update/tests.py
@@ -97,6 +97,16 @@ class SelectForUpdateTests(TransactionTestCase):
list(Person.objects.all().select_for_update(skip_locked=True))
self.assertTrue(self.has_for_update_sql(ctx.captured_queries, skip_locked=True))
+ @skipUnlessDBFeature('has_select_for_no_key_update')
+ def test_update_sql_generated_no_key(self):
+ """
+ The backend's FOR NO KEY UPDATE variant appears in generated SQL when
+ select_for_update() is invoked.
+ """
+ with transaction.atomic(), CaptureQueriesContext(connection) as ctx:
+ list(Person.objects.all().select_for_update(no_key=True))
+ self.assertIs(self.has_for_update_sql(ctx.captured_queries, no_key=True), True)
+
@skipUnlessDBFeature('has_select_for_update_of')
def test_for_update_sql_generated_of(self):
"""
@@ -291,6 +301,18 @@ class SelectForUpdateTests(TransactionTestCase):
with transaction.atomic():
Person.objects.select_for_update(of=('self',)).get()
+ @skipIfDBFeature('has_select_for_no_key_update')
+ @skipUnlessDBFeature('has_select_for_update')
+ def test_unsuported_no_key_raises_error(self):
+ """
+ NotSupportedError is raised if a SELECT...FOR NO KEY UPDATE... is run
+ on a database backend that supports FOR UPDATE but not NO KEY.
+ """
+ msg = 'FOR NO KEY UPDATE is not supported on this database backend.'
+ with self.assertRaisesMessage(NotSupportedError, msg):
+ with transaction.atomic():
+ Person.objects.select_for_update(no_key=True).get()
+
@skipUnlessDBFeature('has_select_for_update', 'has_select_for_update_of')
def test_unrelated_of_argument_raises_error(self):
"""