summaryrefslogtreecommitdiff
path: root/tests/test_utils
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-12-03 11:56:22 +0100
committerGitHub <noreply@github.com>2021-12-03 11:56:22 +0100
commit2c7846d992ca512d36a73f518205015c88ed088c (patch)
treeed9bdd249723a5504d22a1ce433d3773ffe9c92a /tests/test_utils
parent9c1fe446b620963209df03b2fab1b3b9b5dc1988 (diff)
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.
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 eefca4b32d..dbf609b8fe 100644
--- a/tests/test_utils/test_testcase.py
+++ b/tests/test_utils/test_testcase.py
@@ -74,10 +74,15 @@ class TestDataTests(TestCase):
belongs_to=cls.jim_douglas,
)
+ 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):
@@ -85,6 +90,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):