9
9
from myuw .dao .affiliation import get_all_affiliations
10
10
from myuw .dao .myuw_notice import (
11
11
get_myuw_notices_for_user , get_prev_sunday , get_start_date ,
12
- get_current_quarter , campus_neutral , is_stud_campus_matched ,
12
+ get_notice_term , campus_neutral , is_stud_campus_matched ,
13
13
is_employee_campus_matched , get_first_day_quarter ,
14
14
get_notices_by_date , get_notices_by_term , student_affiliation_matched )
15
15
from myuw .dao .notice_mapping import categorize_notices
@@ -23,6 +23,23 @@ def get_datetime_with_tz(year, month, day, hour):
23
23
24
24
class TestMyuwNotice (TransactionTestCase ):
25
25
26
+ def test_get_notice_term (self ):
27
+ request = get_request_with_date ("2013-03-16" )
28
+ term , cmp_date = get_notice_term (request )
29
+ self .assertEqual (term .quarter , "winter" )
30
+ request = get_request_with_date ("2013-03-17" )
31
+ term , cmp_date = get_notice_term (request )
32
+ self .assertEqual (term .quarter , "spring" )
33
+ request = get_request_with_date ("2013-06-09" )
34
+ term , cmp_date = get_notice_term (request )
35
+ self .assertEqual (term .quarter , "summer" )
36
+ request = get_request_with_date ("2013-08-25" )
37
+ term , cmp_date = get_notice_term (request )
38
+ self .assertEqual (term .quarter , "autumn" )
39
+ request = get_request_with_date ("2013-12-08" )
40
+ term , cmp_date = get_notice_term (request )
41
+ self .assertEqual (term .quarter , "winter" )
42
+
26
43
def test_get_prev_sunday (self ):
27
44
start_sun = get_prev_sunday (date (2013 , 1 , 2 ))
28
45
self .assertEqual (str (start_sun ), "2012-12-30" )
@@ -34,90 +51,101 @@ def test_get_prev_sunday(self):
34
51
self .assertEqual (str (start_sun ), "2013-09-22" )
35
52
36
53
def test_get_start_date (self ):
37
- dt = get_start_date (date (2013 , 1 , 6 ), - 1 )
54
+ dt = get_start_date (date (2013 , 1 , 7 ), - 1 )
38
55
self .assertEqual (str (dt ), "2012-12-30" )
39
- dt = get_start_date (date (2013 , 1 , 6 ), 0 )
56
+ dt = get_start_date (date (2013 , 1 , 7 ), 0 )
40
57
self .assertEqual (str (dt ), "2013-01-06" )
41
- dt = get_start_date (date (2013 , 1 , 6 ), 1 )
58
+ dt = get_start_date (date (2013 , 1 , 7 ), 1 )
42
59
self .assertEqual (str (dt ), "2013-01-13" )
43
- dt = get_start_date (date (2013 , 9 , 22 ), - 2 )
44
- self .assertEqual (str (dt ), "2013-09-08" )
45
60
46
61
def test_get_first_day_quarter (self ):
62
+ # MUWM-5273
47
63
notice = MyuwNotice (title = "Test" ,
48
64
content = "Notice Content Five" ,
49
65
notice_type = "Banner" ,
50
66
notice_category = "MyUWNotice" ,
51
- start_week = - 2 ,
52
- duration = 1 ,
67
+ start_week = 0 ,
68
+ duration = 2 ,
69
+ is_spring = True ,
53
70
is_summer_b = True )
71
+ request = get_request_with_date ("2013-04-11" )
72
+ dt = get_first_day_quarter (request , notice )
73
+ self .assertEqual (str (dt ), "2013-04-01" )
74
+ # notice.is_summer_a is False
54
75
request = get_request_with_date ("2013-07-11" )
55
- cur_term = get_current_quarter (request )
56
- self .assertEqual (cur_term .quarter , "summer" )
57
- dt = get_first_day_quarter (cur_term , notice )
76
+ dt = get_first_day_quarter (request , notice )
58
77
self .assertEqual (str (dt ), "2013-07-25" )
59
78
60
79
notice = MyuwNotice (title = "Test" ,
61
80
content = "Notice Content Five" ,
62
81
notice_type = "Banner" ,
63
82
notice_category = "MyUWNotice" ,
64
- start_week = - 2 ,
83
+ start_week = - 1 ,
65
84
duration = 1 ,
85
+ is_summer_a = True ,
86
+ is_summer_b = True ,
66
87
is_autumn = True )
67
- request = get_request_with_date ("2013-09-01" )
68
- cur_term = get_current_quarter (request )
69
- self .assertEqual (cur_term .quarter , "autumn" )
70
- dt = get_first_day_quarter (cur_term , notice )
88
+ # summer A-term
89
+ request = get_request_with_date ("2013-07-11" )
90
+ dt = get_first_day_quarter (request , notice )
91
+ self .assertEqual (str (dt ), "2013-06-24" )
92
+ # summer B-term
93
+ request = get_request_with_date ("2013-07-14" )
94
+ dt = get_first_day_quarter (request , notice )
95
+ self .assertEqual (str (dt ), "2013-07-25" )
96
+
97
+ request = get_request_with_date ("2013-08-28" )
98
+ dt = get_first_day_quarter (request , notice )
71
99
self .assertEqual (str (dt ), "2013-09-25" )
72
100
73
101
def test_get_notices_by_term (self ):
74
102
notice = MyuwNotice (title = "Test1" ,
75
103
content = "Notice Content Five" ,
76
104
notice_type = "Banner" ,
77
105
notice_category = "MyUWNotice" ,
78
- start_week = 2 ,
79
- duration = 1 ,
106
+ start_week = - 2 ,
107
+ duration = 4 ,
80
108
is_summer_a = True )
81
109
notice .save ()
82
110
notice = MyuwNotice (title = "Test2" ,
83
111
content = "Notice Content Five" ,
84
112
notice_type = "Banner" ,
85
113
start_week = - 2 ,
86
- duration = 1 ,
114
+ duration = 4 ,
87
115
is_summer_b = True )
88
116
notice .save ()
89
117
notice = MyuwNotice (title = "Test3" ,
90
118
content = "Notice Content Five" ,
91
119
notice_type = "Banner" ,
92
120
notice_category = "MyUWNotice" ,
93
- start_week = 3 ,
94
- duration = 2 ,
121
+ start_week = - 2 ,
122
+ duration = 4 ,
95
123
is_autumn = True )
96
124
notice .save ()
97
- request = get_request_with_date ("2013-07-08 " )
125
+ request = get_request_with_date ("2013-06-09 " )
98
126
notices = get_notices_by_term (request )
99
- self .assertEqual (len (notices ), 2 )
127
+ self .assertEqual (len (notices ), 1 )
100
128
self .assertEqual (notices [0 ].title , "Test1" )
101
- self .assertEqual (notices [1 ].title , "Test2" )
102
129
103
- request = get_request_with_date ("2013-08-25 " )
130
+ request = get_request_with_date ("2013-07-07 " )
104
131
notices = get_notices_by_term (request )
105
- self .assertEqual (len (notices ), 0 )
132
+ self .assertEqual (len (notices ), 1 )
133
+ self .assertEqual (notices [0 ].title , "Test2" )
106
134
107
- request = get_request_with_date ("2013-10-12 " )
135
+ request = get_request_with_date ("2013-08-11 " )
108
136
notices = get_notices_by_term (request )
109
137
self .assertEqual (len (notices ), 0 )
110
138
111
- request = get_request_with_date ("2013-10-13 " )
139
+ request = get_request_with_date ("2013-09-07 " )
112
140
notices = get_notices_by_term (request )
113
- self .assertEqual (len (notices ), 1 )
114
- self .assertEqual (notices [0 ].title , "Test3" )
141
+ self .assertEqual (len (notices ), 0 )
115
142
116
- request = get_request_with_date ("2013-10-26 " )
143
+ request = get_request_with_date ("2013-09-08 " )
117
144
notices = get_notices_by_term (request )
118
145
self .assertEqual (len (notices ), 1 )
146
+ self .assertEqual (notices [0 ].title , "Test3" )
119
147
120
- request = get_request_with_date ("2013-10-27 " )
148
+ request = get_request_with_date ("2013-10-06 " )
121
149
notices = get_notices_by_term (request )
122
150
self .assertEqual (len (notices ), 0 )
123
151
0 commit comments