1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #33355 -- Added missing tests for database functions and expression on null values.

This commit is contained in:
Adam Johnson
2021-12-10 09:13:09 +00:00
committed by Mariusz Felisiak
parent 78f062f63e
commit a8fa3e5cd7
7 changed files with 22 additions and 0 deletions

View File

@@ -1246,6 +1246,12 @@ class ExpressionOperatorTests(TestCase):
Number.objects.filter(pk=self.n.pk).update(integer=F('integer') % 20)
self.assertEqual(Number.objects.get(pk=self.n.pk).integer, 2)
def test_lefthand_modulo_null(self):
# LH Modulo arithmetic on integers.
Employee.objects.create(firstname='John', lastname='Doe', salary=None)
qs = Employee.objects.annotate(modsalary=F('salary') % 20)
self.assertIsNone(qs.get().salary)
def test_lefthand_bitwise_and(self):
# LH Bitwise ands on integers
Number.objects.filter(pk=self.n.pk).update(integer=F('integer').bitand(56))
@@ -1294,6 +1300,12 @@ class ExpressionOperatorTests(TestCase):
employee.refresh_from_db()
self.assertIsNone(employee.salary)
def test_lefthand_bitwise_xor_right_null(self):
employee = Employee.objects.create(firstname='John', lastname='Doe', salary=48)
Employee.objects.update(salary=F('salary').bitxor(None))
employee.refresh_from_db()
self.assertIsNone(employee.salary)
@unittest.skipUnless(connection.vendor == 'oracle', "Oracle doesn't support bitwise XOR.")
def test_lefthand_bitwise_xor_not_supported(self):
msg = 'Bitwise XOR is not supported in Oracle.'