django-model-utils/tests/test_fields/test_status_field.py
Maarten ter Huurne aeeb69a9dd Enable postponed evaluation of annotations for all test modules
This allows using the latest annotation syntax supported by the type
checker regardless of the runtime Python version.
2024-06-13 12:02:05 +02:00

34 lines
1 KiB
Python

from __future__ import annotations
from django.test import TestCase
from model_utils.fields import StatusField
from tests.models import (
Article,
StatusFieldChoicesName,
StatusFieldDefaultFilled,
StatusFieldDefaultNotFilled,
)
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()