7
7
from timezone_field .fields import TimeZoneField
8
8
9
9
10
+ PST = 'America/Los_Angeles'
11
+ EST = 'America/New_York'
12
+
13
+
10
14
class TestModel (models .Model ):
11
15
timezone = TimeZoneField ()
12
16
17
+
13
18
class TestModelForm (forms .ModelForm ):
14
19
class Meta :
15
20
model = TestModel
@@ -18,33 +23,33 @@ class Meta:
18
23
class TimeZoneFieldTestCase (TestCase ):
19
24
20
25
def test_models_modelform_validation (self ):
21
- form = TestModelForm ({" timezone" : "America/Denver" })
26
+ form = TestModelForm ({' timezone' : PST })
22
27
self .assertTrue (form .is_valid ())
23
28
24
29
def test_models_modelform_save (self ):
25
- form = TestModelForm ({" timezone" : "America/Denver" })
30
+ form = TestModelForm ({' timezone' : EST })
26
31
self .assertTrue (form .is_valid ())
27
32
form .save ()
28
33
29
34
def test_models_string_value (self ):
30
- p = TestModel (timezone = "America/Denver" )
35
+ p = TestModel (timezone = PST )
31
36
p .save ()
32
37
p = TestModel .objects .get (pk = p .pk )
33
- self .assertEqual (p .timezone , pytz .timezone ("America/Denver" ))
38
+ self .assertEqual (p .timezone , pytz .timezone (PST ))
34
39
35
40
def test_models_string_value_lookup (self ):
36
- TestModel (timezone = "America/Denver" ).save ()
37
- qs = TestModel .objects .filter (timezone = "America/Denver" )
41
+ TestModel (timezone = EST ).save ()
42
+ qs = TestModel .objects .filter (timezone = EST )
38
43
self .assertEqual (qs .count (), 1 )
39
44
40
45
def test_models_tz_value (self ):
41
- tz = pytz .timezone ("America/Denver" )
46
+ tz = pytz .timezone (PST )
42
47
p = TestModel (timezone = tz )
43
48
p .save ()
44
49
p = TestModel .objects .get (pk = p .pk )
45
50
self .assertEqual (p .timezone , tz )
46
51
47
52
def test_models_tz_value_lookup (self ):
48
- TestModel (timezone = "America/Denver" ).save ()
49
- qs = TestModel .objects .filter (timezone = pytz .timezone ("America/Denver" ))
53
+ TestModel (timezone = PST ).save ()
54
+ qs = TestModel .objects .filter (timezone = pytz .timezone (PST ))
50
55
self .assertEqual (qs .count (), 1 )
0 commit comments