@@ -68,6 +68,11 @@ def test_invalid_uncommon_tz(self):
68
68
form = TestForm ({'tz' : UNCOMMON_TZ })
69
69
self .assertFalse (form .is_valid ())
70
70
71
+ def test_default_human_readable_choices_dont_have_underscores (self ):
72
+ form = TestForm ()
73
+ pst_choice = [c for c in form .fields ['tz' ].choices if c [0 ] == PST ]
74
+ self .assertEqual (pst_choice [0 ][1 ], 'America/Los Angeles' )
75
+
71
76
72
77
class TimeZoneFieldModelFormTestCase (TestCase ):
73
78
@@ -119,6 +124,11 @@ def test_invalid_uncommmon_tz(self):
119
124
self .assertFalse (form .is_valid ())
120
125
self .assertTrue (any ('choice' in e for e in form .errors ['tz' ]))
121
126
127
+ def test_default_human_readable_choices_dont_have_underscores (self ):
128
+ form = TestModelForm ()
129
+ pst_choice = [c for c in form .fields ['tz' ].choices if c [0 ] == PST_tz ]
130
+ self .assertEqual (pst_choice [0 ][1 ], 'America/Los Angeles' )
131
+
122
132
123
133
class TimeZoneFieldTestCase (TestCase ):
124
134
@@ -238,6 +248,10 @@ def createField():
238
248
TimeZoneField ('a verbose name' , 'a name' , True , 42 )
239
249
self .assertRaises (ValueError , createField )
240
250
251
+ def test_default_human_readable_choices_dont_have_underscores (self ):
252
+ m = TestModel (tz = PST_tz )
253
+ self .assertEqual (m .get_tz_display (), 'America/Los Angeles' )
254
+
241
255
242
256
class TimeZoneFieldLimitedChoicesTestCase (TestCase ):
243
257
@@ -368,12 +382,15 @@ def test_specifying_defaults_not_frozen(self):
368
382
name , path , args , kwargs = field .deconstruct ()
369
383
self .assertNotIn ('max_length' , kwargs )
370
384
371
- choices = [(pytz .timezone (tz ), tz ) for tz in pytz .common_timezones ]
385
+ choices = [
386
+ (pytz .timezone (tz ), tz .replace ('_' , ' ' ))
387
+ for tz in pytz .common_timezones
388
+ ]
372
389
field = TimeZoneField (choices = choices )
373
390
name , path , args , kwargs = field .deconstruct ()
374
391
self .assertNotIn ('choices' , kwargs )
375
392
376
- choices = [(tz , tz ) for tz in pytz .common_timezones ]
393
+ choices = [(tz , tz . replace ( '_' , ' ' ) ) for tz in pytz .common_timezones ]
377
394
field = TimeZoneField (choices = choices )
378
395
name , path , args , kwargs = field .deconstruct ()
379
396
self .assertNotIn ('choices' , kwargs )
0 commit comments