2016-11-23 23:49:53 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
|
|
from model_utils.fields import StatusField
|
2017-02-15 23:00:10 +00:00
|
|
|
from tests.models import (
|
2020-11-29 20:58:00 +00:00
|
|
|
Article,
|
2016-11-23 23:49:53 +00:00
|
|
|
StatusFieldChoicesName,
|
2020-11-29 20:58:00 +00:00
|
|
|
StatusFieldDefaultFilled,
|
|
|
|
|
StatusFieldDefaultNotFilled,
|
2018-07-02 19:57:14 +00:00
|
|
|
)
|
2016-11-23 23:49:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class StatusFieldTests(TestCase):
|
|
|
|
|
|
|
|
|
|
def test_status_with_default_filled(self):
|
|
|
|
|
instance = StatusFieldDefaultFilled()
|
|
|
|
|
self.assertEqual(instance.status, instance.STATUS.yes)
|
|
|
|
|
|
|
|
|
|
def test_status_with_default_not_filled(self):
|
|
|
|
|
instance = StatusFieldDefaultNotFilled()
|
|
|
|
|
self.assertEqual(instance.status, instance.STATUS.no)
|
|
|
|
|
|
|
|
|
|
def test_no_check_for_status(self):
|
|
|
|
|
field = StatusField(no_check_for_status=True)
|
|
|
|
|
# this model has no STATUS attribute, so checking for it would error
|
|
|
|
|
field.prepare_class(Article)
|
|
|
|
|
|
|
|
|
|
def test_get_status_display(self):
|
|
|
|
|
instance = StatusFieldDefaultFilled()
|
|
|
|
|
self.assertEqual(instance.get_status_display(), "Yes")
|
|
|
|
|
|
|
|
|
|
def test_choices_name(self):
|
|
|
|
|
StatusFieldChoicesName()
|