-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore cast-on-assign behavior on Django 1.8+
Turns out the future-deprecated SubfieldBase class did more than what was initially thought. Since it is removed in Django 1.10+, for clarity we no longer use it at all. Instead we intern the behavior of its `Creator` descriptor class as `CastOnAssignDescriptor`. Fixes #60 Refs https://code.djangoproject.com/ticket/26807 Refs 8260050
- Loading branch information
Showing
3 changed files
with
58 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
|
||
from .models import MyModel | ||
|
||
try: | ||
from .enums import Color # Use the new location of Color enum | ||
except ImportError: | ||
Color = MyModel.Color # Attempt the 0.7.4 location of color enum | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_fields_value_is_enum_when_unsaved(): | ||
obj = MyModel(color='r') | ||
assert Color.RED == obj.color | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_fields_value_is_enum_when_saved(): | ||
obj = MyModel(color='r') | ||
obj.save() | ||
assert Color.RED == obj.color | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_fields_value_is_enum_when_created(): | ||
obj = MyModel.objects.create(color='r') | ||
assert Color.RED == obj.color | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_fields_value_is_enum_when_retrieved(): | ||
MyModel.objects.create(color='r') | ||
obj = MyModel.objects.first() | ||
assert Color.RED == obj.color |