| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from django.test import TestCase |
| 4 |
|
| 5 |
from model_utils.fields import StatusField |
| 6 |
from tests.models import ( |
| 7 |
Article, |
| 8 |
StatusFieldChoicesName, |
| 9 |
StatusFieldDefaultFilled, |
| 10 |
StatusFieldDefaultNotFilled, |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
class StatusFieldTests(TestCase): |
| 15 |
|
| 16 |
def test_status_with_default_filled(self) -> None: |
| 17 |
instance = StatusFieldDefaultFilled() |
| 18 |
self.assertEqual(instance.status, instance.STATUS.yes) |
| 19 |
|
| 20 |
def test_status_with_default_not_filled(self) -> None: |
| 21 |
instance = StatusFieldDefaultNotFilled() |
| 22 |
self.assertEqual(instance.status, instance.STATUS.no) |
| 23 |
|
| 24 |
def test_no_check_for_status(self) -> None: |
| 25 |
field = StatusField(no_check_for_status=True) |
| 26 |
# this model has no STATUS attribute, so checking for it would error |
| 27 |
field.prepare_class(Article) |
| 28 |
|
| 29 |
def test_get_status_display(self) -> None: |
| 30 |
instance = StatusFieldDefaultFilled() |
| 31 |
self.assertEqual(instance.get_status_display(), "Yes") |
| 32 |
|
| 33 |
def test_choices_name(self) -> None: |
| 34 |
StatusFieldChoicesName() |