diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/select_for_update/tests.py | 22 |
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): """ |
