-
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.
Merge pull request #61 from hzdg/issue-60
Restore cast-on-assign behavior on Django 1.8+
- Loading branch information
Showing
2 changed files
with
58 additions
and
2 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
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.all()[:1][0] # .first() not available on all Djangoes | ||
assert Color.RED == obj.color |