Skip to content

Commit e8c4bef

Browse files
sridharjeking3
authored andcommitted
add unit tests for verbose name plural
1 parent ca07aba commit e8c4bef

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 4.0.1 on 2022-01-28 11:26
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('migration_test_app', '0006_alter_historicalmodelwithcustomattronetoonefield_options_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name='historicalmodelwithcustomattrforeignkey',
15+
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical model with custom attr foreign key', 'verbose_name_plural': 'historical model with custom attr foreign keys'},
16+
),
17+
migrations.AlterModelOptions(
18+
name='historicalmodelwithcustomattronetoonefield',
19+
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical model with custom attr one to one field', 'verbose_name_plural': 'historical model with custom attr one to one fields'},
20+
),
21+
migrations.AlterModelOptions(
22+
name='historicalyar',
23+
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical yar', 'verbose_name_plural': 'historical yars'},
24+
),
25+
]

simple_history/tests/models.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ class State(models.Model):
291291

292292
class Book(models.Model):
293293
isbn = models.CharField(max_length=15, primary_key=True)
294-
history = HistoricalRecords(verbose_name="dead trees")
294+
history = HistoricalRecords(
295+
verbose_name="dead trees", verbose_name_plural="dead trees plural"
296+
)
295297

296298

297299
class HardbackBook(Book):
@@ -308,6 +310,7 @@ class Library(models.Model):
308310

309311
class Meta:
310312
verbose_name = "quiet please"
313+
verbose_name_plural = "quiet please plural"
311314

312315

313316
class BaseModel(models.Model):
@@ -377,6 +380,14 @@ class Meta:
377380
verbose_name = "\u570b"
378381

379382

383+
class UnicodeVerboseNamePlural(models.Model):
384+
name = models.CharField(max_length=100)
385+
history = HistoricalRecords()
386+
387+
class Meta:
388+
verbose_name_plural = "\u570b"
389+
390+
380391
class CustomFKError(models.Model):
381392
fk = models.ForeignKey(SecondLevelInheritedModel, on_delete=models.CASCADE)
382393
history = HistoricalRecords()

simple_history/tests/tests/test_models.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
Street,
9292
Temperature,
9393
UnicodeVerboseName,
94+
UnicodeVerboseNamePlural,
9495
UserTextFieldChangeReasonModel,
9596
UUIDDefaultModel,
9697
UUIDModel,
@@ -510,6 +511,28 @@ def test_historical_verbose_name_follows_model_verbose_name(self):
510511
"historical quiet please", library.history.get()._meta.verbose_name
511512
)
512513

514+
def test_unicode_verbose_name_plural(self):
515+
instance = UnicodeVerboseNamePlural()
516+
instance.save()
517+
self.assertEqual(
518+
"historical \u570b", instance.history.all()[0]._meta.verbose_name_plural
519+
)
520+
521+
def test_user_can_set_verbose_name_plural(self):
522+
b = Book(isbn="54321")
523+
b.save()
524+
self.assertEqual(
525+
"dead trees plural", b.history.all()[0]._meta.verbose_name_plural
526+
)
527+
528+
def test_historical_verbose_name_plural_follows_model_verbose_name_plural(self):
529+
library = Library()
530+
library.save()
531+
self.assertEqual(
532+
"historical quiet please plural",
533+
library.history.get()._meta.verbose_name_plural
534+
)
535+
513536
def test_foreignkey_primarykey(self):
514537
"""Test saving a tracked model with a `ForeignKey` primary key."""
515538
poll = Poll(pub_date=today)

0 commit comments

Comments
 (0)