summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Kestenholz <mk@feinheit.ch>2019-03-23 17:04:39 +0100
committerTim Graham <timograham@gmail.com>2019-03-23 12:04:39 -0400
commitea60b7bc7464808e34e3cb0aac04455fdd8545eb (patch)
tree41bb2baed64e856d167d8fe7ce9ca38376e76b9b
parent2ee1e1a1744c4d0679058124eb7ceba78a0a5a84 (diff)
Removed redundant model field choices tests.
-rw-r--r--tests/choices/__init__.py0
-rw-r--r--tests/choices/models.py25
-rw-r--r--tests/choices/tests.py25
-rw-r--r--tests/model_fields/models.py2
-rw-r--r--tests/model_fields/tests.py6
5 files changed, 8 insertions, 50 deletions
diff --git a/tests/choices/__init__.py b/tests/choices/__init__.py
deleted file mode 100644
index e69de29bb2..0000000000
--- a/tests/choices/__init__.py
+++ /dev/null
diff --git a/tests/choices/models.py b/tests/choices/models.py
deleted file mode 100644
index 37ef8daf60..0000000000
--- a/tests/choices/models.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""
-Specifying 'choices' for a field
-
-Most fields take a ``choices`` parameter, which should be a tuple of tuples
-specifying which are the valid values for that field.
-
-For each field that has ``choices``, a model instance gets a
-``get_fieldname_display()`` method, where ``fieldname`` is the name of the
-field. This method returns the "human-readable" value of the field.
-"""
-
-from django.db import models
-from django.utils.translation import gettext_lazy as _
-
-
-class Person(models.Model):
- GENDER_CHOICES = (
- ('M', _('Male')),
- ('F', _('Female')),
- )
- name = models.CharField(max_length=20)
- gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
-
- def __str__(self):
- return self.name
diff --git a/tests/choices/tests.py b/tests/choices/tests.py
deleted file mode 100644
index 88b8bf7fe2..0000000000
--- a/tests/choices/tests.py
+++ /dev/null
@@ -1,25 +0,0 @@
-from django.test import TestCase
-
-from .models import Person
-
-
-class ChoicesTests(TestCase):
- def test_display(self):
- a = Person.objects.create(name='Adrian', gender='M')
- s = Person.objects.create(name='Sara', gender='F')
- self.assertEqual(a.gender, 'M')
- self.assertEqual(s.gender, 'F')
-
- self.assertEqual(a.get_gender_display(), 'Male')
- self.assertEqual(s.get_gender_display(), 'Female')
-
- # If the value for the field doesn't correspond to a valid choice,
- # the value itself is provided as a display value.
- a.gender = ''
- self.assertEqual(a.get_gender_display(), '')
-
- a.gender = 'U'
- self.assertEqual(a.get_gender_display(), 'U')
-
- # _get_FIELD_display() coerces lazy strings.
- self.assertIsInstance(a.get_gender_display(), str)
diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py
index 93e424a2aa..cbf3ec26ea 100644
--- a/tests/model_fields/models.py
+++ b/tests/model_fields/models.py
@@ -12,6 +12,7 @@ from django.db.models.fields.files import ImageField, ImageFieldFile
from django.db.models.fields.related import (
ForeignKey, ForeignObject, ManyToManyField, OneToOneField,
)
+from django.utils.translation import gettext_lazy as _
try:
from PIL import Image
@@ -46,6 +47,7 @@ class Whiz(models.Model):
)
),
(0, 'Other'),
+ (5, _('translated')),
)
c = models.IntegerField(choices=CHOICES, null=True)
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
index f55175aa9e..bb82c7b93d 100644
--- a/tests/model_fields/tests.py
+++ b/tests/model_fields/tests.py
@@ -162,6 +162,12 @@ class GetFieldDisplayTests(SimpleTestCase):
self.assertEqual(Whiz(c='').get_c_display(), '') # Empty value
self.assertEqual(WhizDelayed(c=0).get_c_display(), 'Other') # Delayed choices
+ def test_get_FIELD_display_translated(self):
+ """A translated display value is coerced to str."""
+ val = Whiz(c=5).get_c_display()
+ self.assertIsInstance(val, str)
+ self.assertEqual(val, 'translated')
+
def test_iterator_choices(self):
"""
get_choices() works with Iterators.