Skip to content

Commit

Permalink
Add a non regression test to deal with buffer types
Browse files Browse the repository at this point in the history
  • Loading branch information
hsmett committed Mar 5, 2018
1 parent d4569cb commit 4de4bc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tests/models.py
Expand Up @@ -137,3 +137,7 @@ class TestModelWithM2MAndSpecifiedFields(DirtyFieldsMixin, models.Model):
m2m2 = models.ManyToManyField(TestModel)
ENABLE_M2M_CHECK = True
FIELDS_TO_CHECK = ['m2m1']


class TestBinaryModel(DirtyFieldsMixin, models.Model):
bytea = models.BinaryField()
15 changes: 13 additions & 2 deletions tests/test_non_regression.py
@@ -1,11 +1,12 @@
import pytest

from base64 import b64encode
from django.db import IntegrityError
from django.test.utils import override_settings

from .models import (TestModel, TestModelWithForeignKey, TestModelWithNonEditableFields,
OrdinaryTestModel, OrdinaryTestModelWithForeignKey, TestModelWithSelfForeignKey,
TestExpressionModel, TestModelWithPreSaveSignal, TestDoubleForeignKeyModel)
TestExpressionModel, TestModelWithPreSaveSignal, TestDoubleForeignKeyModel,
TestBinaryModel)
from .utils import assert_select_number_queries_on_model


Expand Down Expand Up @@ -145,3 +146,13 @@ def test_foreign_key_deferred_field():
TestDoubleForeignKeyModel.objects.create(fkey1=tm)

list(TestDoubleForeignKeyModel.objects.only('fkey1')) # RuntimeError was raised here!


@pytest.mark.django_db
def test_bytea():
TestBinaryModel.objects.create(bytea=b64encode(b'Hello'))
tbm = TestBinaryModel.objects.get()
tbm.bytea = b'W\xc3\xb6rlD'
assert tbm.get_dirty_fields() == {
'bytea': b'SGVsbG8=',
}

0 comments on commit 4de4bc8

Please sign in to comment.