summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHannes Ljungberg <hannes@5monkeys.se>2020-03-20 23:08:32 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-03-25 10:16:30 +0100
commitf3da09df0f4147223ab76a00a841586ccf11005d (patch)
treee36e8116a5b7abaa453791545a65e3febe3adc87 /tests
parent39e1c88de67ea2035d5ad89cfe00bcd892c0d163 (diff)
Fixed #31396 -- Added binary XOR operator to F expressions.
Diffstat (limited to 'tests')
-rw-r--r--tests/expressions/tests.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index da6e04e8fd..46fe6fa89d 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -6,7 +6,7 @@ from copy import deepcopy
from unittest import mock
from django.core.exceptions import FieldError
-from django.db import DatabaseError, connection
+from django.db import DatabaseError, NotSupportedError, connection
from django.db.models import (
Avg, BooleanField, Case, CharField, Count, DateField, DateTimeField,
DurationField, Exists, Expression, ExpressionList, ExpressionWrapper, F,
@@ -1163,6 +1163,25 @@ class ExpressionOperatorTests(TestCase):
self.assertEqual(Number.objects.get(pk=self.n.pk).integer, 1764)
self.assertEqual(Number.objects.get(pk=self.n.pk).float, Approximate(61.02, places=2))
+ @unittest.skipIf(connection.vendor == 'oracle', "Oracle doesn't support bitwise XOR.")
+ def test_lefthand_bitwise_xor(self):
+ Number.objects.update(integer=F('integer').bitxor(48))
+ self.assertEqual(Number.objects.get(pk=self.n.pk).integer, 26)
+ self.assertEqual(Number.objects.get(pk=self.n1.pk).integer, -26)
+
+ @unittest.skipIf(connection.vendor == 'oracle', "Oracle doesn't support bitwise XOR.")
+ def test_lefthand_bitwise_xor_null(self):
+ employee = Employee.objects.create(firstname='John', lastname='Doe')
+ Employee.objects.update(salary=F('salary').bitxor(48))
+ 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.'
+ with self.assertRaisesMessage(NotSupportedError, msg):
+ Number.objects.update(integer=F('integer').bitxor(48))
+
def test_right_hand_addition(self):
# Right hand operators
Number.objects.filter(pk=self.n.pk).update(integer=15 + F('integer'), float=42.7 + F('float'))