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 12:01:28 +0100
commitcb724ef6c0fd71cd5bdbdc27c02f4da0f7e2ad08 (patch)
tree3bdbc72d56135923d0c2159c4334bf434b5db271 /tests/test_utils
parent0cf2d48ba83543b16bdf390d941eb98e8d34f3bd (diff)
[3.2.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 5ec71f84d0..e833a29727 100644
--- a/tests/test_utils/test_testcase.py
+++ b/tests/test_utils/test_testcase.py
@@ -71,10 +71,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):
@@ -82,6 +87,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):