diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-12-03 11:56:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-03 11:56:22 +0100 |
| commit | 2c7846d992ca512d36a73f518205015c88ed088c (patch) | |
| tree | ed9bdd249723a5504d22a1ce433d3773ffe9c92a /tests | |
| parent | 9c1fe446b620963209df03b2fab1b3b9b5dc1988 (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')
| -rw-r--r-- | tests/queryset_pickle/models.py | 1 | ||||
| -rw-r--r-- | tests/queryset_pickle/tests.py | 4 | ||||
| -rw-r--r-- | tests/test_utils/models.py | 1 | ||||
| -rw-r--r-- | tests/test_utils/test_testcase.py | 20 |
4 files changed, 26 insertions, 0 deletions
diff --git a/tests/queryset_pickle/models.py b/tests/queryset_pickle/models.py index 689a11f65e..9a033ffe95 100644 --- a/tests/queryset_pickle/models.py +++ b/tests/queryset_pickle/models.py @@ -46,6 +46,7 @@ class Happening(models.Model): number1 = models.IntegerField(blank=True, default=standalone_number) number2 = models.IntegerField(blank=True, default=Numbers.get_static_number) event = models.OneToOneField(Event, models.CASCADE, null=True) + data = models.BinaryField(null=True) class Container: diff --git a/tests/queryset_pickle/tests.py b/tests/queryset_pickle/tests.py index bf61960419..60d30cd8ce 100644 --- a/tests/queryset_pickle/tests.py +++ b/tests/queryset_pickle/tests.py @@ -16,6 +16,10 @@ class PickleabilityTestCase(TestCase): def assert_pickles(self, qs): self.assertEqual(list(pickle.loads(pickle.dumps(qs))), list(qs)) + def test_binaryfield(self): + Happening.objects.create(data=b'binary data') + self.assert_pickles(Happening.objects.all()) + def test_related_field(self): g = Group.objects.create(name="Ponies Who Own Maybachs") self.assert_pickles(Event.objects.filter(group=g.id)) 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): |
