summaryrefslogtreecommitdiff
path: root/tests/test_utils
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-12-03 11:56:22 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-12-03 11:58:55 +0100
commit2c20883cb0df8c56ecbb9a093fc4252410140b59 (patch)
treeacd8c2527619f1f9a1a6825346f1b78242c5d7ab /tests/test_utils
parent306fbf197a742b4b79e4ed23c94f5bbdbec9afdc (diff)
[4.0.x] Fixed #33333 -- Fixed setUpTestData() crash with models.BinaryField on PostgreSQL.
This makes models.BinaryField pickleable on PostgreSQL. Regression in 3cf80d3fcf7446afdde16a2be515c423f720e54d. Thanks Adam Zimmerman for the report. Backport of 2c7846d992ca512d36a73f518205015c88ed088c from main.
Diffstat (limited to 'tests/test_utils')
-rw-r--r--tests/test_utils/models.py1
-rw-r--r--tests/test_utils/test_testcase.py20
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_utils/models.py b/tests/test_utils/models.py
index b0497f12b9..57518aef90 100644
--- a/tests/test_utils/models.py
+++ b/tests/test_utils/models.py
@@ -8,6 +8,7 @@ class Car(models.Model):
class Person(models.Model):
name = models.CharField(max_length=100)
cars = models.ManyToManyField(Car, through='PossessedCar')
+ data = models.BinaryField(null=True)
class PossessedCar(models.Model):
diff --git a/tests/test_utils/test_testcase.py b/tests/test_utils/test_testcase.py
index 9b11168b13..0c2417c339 100644
--- a/tests/test_utils/test_testcase.py
+++ b/tests/test_utils/test_testcase.py
@@ -81,10 +81,15 @@ class TestDataTests(TestCase):
)
cls.non_deepcopy_able = NonDeepCopyAble()
+ cls.person_binary = Person.objects.create(name='Person', data=b'binary data')
+ cls.person_binary_get = Person.objects.get(pk=cls.person_binary.pk)
+
@assert_no_queries
def test_class_attribute_equality(self):
"""Class level test data is equal to instance level test data."""
self.assertEqual(self.jim_douglas, self.__class__.jim_douglas)
+ self.assertEqual(self.person_binary, self.__class__.person_binary)
+ self.assertEqual(self.person_binary_get, self.__class__.person_binary_get)
@assert_no_queries
def test_class_attribute_identity(self):
@@ -92,6 +97,21 @@ class TestDataTests(TestCase):
Class level test data is not identical to instance level test data.
"""
self.assertIsNot(self.jim_douglas, self.__class__.jim_douglas)
+ self.assertIsNot(self.person_binary, self.__class__.person_binary)
+ self.assertIsNot(self.person_binary_get, self.__class__.person_binary_get)
+
+ @assert_no_queries
+ def test_binaryfield_data_type(self):
+ self.assertEqual(bytes(self.person_binary.data), b'binary data')
+ self.assertEqual(bytes(self.person_binary_get.data), b'binary data')
+ self.assertEqual(
+ type(self.person_binary_get.data),
+ type(self.__class__.person_binary_get.data),
+ )
+ self.assertEqual(
+ type(self.person_binary.data),
+ type(self.__class__.person_binary.data),
+ )
@assert_no_queries
def test_identity_preservation(self):