Skip to content

Commit d8bd708

Browse files
authored
Merge pull request #2960 from uw-it-aca/qa
Qa
2 parents b7664cc + 5f3ca66 commit d8bd708

File tree

8 files changed

+181
-142
lines changed

8 files changed

+181
-142
lines changed

myuw/dao/myuw_notice.py

+32-15
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
MyuwNotice, start_week_range, duration_range)
1313
from myuw.dao.gws import is_effective_member
1414
from myuw.dao.term import (
15-
get_current_quarter, get_comparison_date,
16-
get_comparison_datetime_with_tz)
15+
get_comparison_date, get_comparison_datetime_with_tz,
16+
get_current_and_next_quarters)
1717

1818
logger = logging.getLogger(__name__)
1919

@@ -125,31 +125,41 @@ def get_notices_by_date(request):
125125
def get_notices_by_term(request):
126126
# MUWM-5265
127127
selected_notices = []
128-
cur_term = get_current_quarter(request)
129-
cmp_date = get_comparison_date(request)
130-
if cur_term.is_summer_quarter():
128+
term, cmp_date = get_notice_term(request)
129+
130+
if term.is_summer_quarter():
131131
fetched_term_notices = MyuwNotice.objects.filter(
132132
Q(is_summer_a=True) | Q(is_summer_b=True))
133133
else:
134-
fltr = {"is_{}".format(cur_term.quarter.lower()): True}
134+
fltr = {"is_{}".format(term.quarter.lower()): True}
135135
fetched_term_notices = MyuwNotice.objects.filter(**fltr)
136136

137137
for notice in fetched_term_notices:
138138
if (notice.start_week in start_week_range and
139139
notice.duration in duration_range):
140-
start_sunday = get_prev_sunday(
141-
get_first_day_quarter(cur_term, notice))
142-
start_date = get_start_date(start_sunday, notice.start_week)
140+
first_day_quarter = get_first_day_quarter(request, notice)
141+
start_date = get_start_date(first_day_quarter, notice.start_week)
143142
end_date = start_date + timedelta(weeks=notice.duration)
144143
if start_date <= cmp_date < end_date:
145144
selected_notices.append(notice)
146145
return selected_notices
147146

148147

149-
def get_first_day_quarter(cur_term, notice):
150-
if notice.is_summer_b:
151-
return cur_term.bterm_first_date
152-
return cur_term.first_day_quarter
148+
def get_first_day_quarter(request, notice):
149+
term, cmp_date = get_notice_term(request)
150+
if term.is_summer_quarter() and notice.is_summer_b:
151+
if not notice.is_summer_a:
152+
return term.bterm_first_date
153+
# MUWM-5273: is_summer_a and is_summer_b both True, check start_date
154+
start_date = get_start_date(
155+
term.bterm_first_date, notice.start_week)
156+
if start_date <= cmp_date:
157+
return term.bterm_first_date
158+
return term.first_day_quarter
159+
160+
161+
def get_start_date(first_day_qtr, notice_start_week):
162+
return get_prev_sunday(first_day_qtr) + timedelta(weeks=notice_start_week)
153163

154164

155165
def get_prev_sunday(first_day_quarter):
@@ -158,5 +168,12 @@ def get_prev_sunday(first_day_quarter):
158168
return first_day_quarter - timedelta(days=week_day_idx)
159169

160170

161-
def get_start_date(start_sunday, notice_start_week):
162-
return start_sunday + timedelta(weeks=notice_start_week)
171+
def get_notice_term(request):
172+
# MUWM-5273 myuw notice display term switches after the last inst week
173+
cmp_date = get_comparison_date(request)
174+
terms = get_current_and_next_quarters(request, 1)
175+
cur_term = terms[0]
176+
next_term = terms[1]
177+
if cmp_date > (cur_term.last_day_instruction + timedelta(days=1)):
178+
return next_term, cmp_date
179+
return cur_term, cmp_date

myuw/dao/term.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from uw_sws.util import convert_to_begin_of_day, convert_to_end_of_day
1313
from uw_sws.section import is_a_term, is_b_term, is_full_summer_term
1414
from uw_sws.term import (
15-
get_term_by_date, get_specific_term, get_current_term,
15+
get_term_by_date, get_specific_term,
1616
get_term_before, get_term_after, get_next_autumn_term,
1717
get_next_non_summer_term)
1818
from restclients_core.exceptions import DataFailureException
@@ -36,13 +36,7 @@ def get_default_datetime():
3636
right in the middle of the "current" term.
3737
"""
3838
if is_using_file_dao():
39-
term = get_current_term()
40-
first_day = term.first_day_quarter
41-
default_date = first_day + timedelta(days=14)
42-
return datetime(default_date.year,
43-
default_date.month,
44-
default_date.day,
45-
0, 0, 1)
39+
return datetime(2013, 4, 15, 0, 0, 1)
4640
return sws_now()
4741

4842

@@ -538,11 +532,9 @@ def add_term_data_to_context(request, context):
538532

539533

540534
def current_terms_prefetch(request):
541-
# This triggers a call to get_current_term when using the file dao.
542-
# That request won't happen on test/production
543535
compare = get_comparison_date(request)
544536
year = compare.year
545-
month = compare.year
537+
month = compare.month
546538

547539
methods = []
548540

myuw/templates/admin/notice_edit.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ <h3>Display Window</h3>
110110
</div>
111111
<br />
112112
<div class="form-group {% if duration_error %}has-error{% endif %}">
113-
<label class="" for="notice_duration">Duration in weeks (1-11 weeks) </label>
113+
<label class="" for="notice_duration">Duration in weeks (1-11 weeks): </label>
114114
<input type="number" id="notice_duration" name="duration" min="1" max="11"
115-
class="form-control" value='{% if notice.duration %}{{ notice.duration }}{% endif %}'>
115+
class="form-control" aria-describedby="duration_explanation" value='{% if notice.duration %}{{ notice.duration }}{% endif %}'>
116+
<span class="help-block small" id="duration_explanation"><strong>DURATION NOTE:</strong> Regardless of duration, notice
117+
will not display after the Saturday following the last day of instruction (e.g. last week of classes) for the selected quarter.</span>
116118
</div>
117119
</div>
118120
</fieldset>

myuw/test/dao/test_myuw_notice.py

+60-32
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from myuw.dao.affiliation import get_all_affiliations
1010
from myuw.dao.myuw_notice import (
1111
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,
1313
is_employee_campus_matched, get_first_day_quarter,
1414
get_notices_by_date, get_notices_by_term, student_affiliation_matched)
1515
from myuw.dao.notice_mapping import categorize_notices
@@ -23,6 +23,23 @@ def get_datetime_with_tz(year, month, day, hour):
2323

2424
class TestMyuwNotice(TransactionTestCase):
2525

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+
2643
def test_get_prev_sunday(self):
2744
start_sun = get_prev_sunday(date(2013, 1, 2))
2845
self.assertEqual(str(start_sun), "2012-12-30")
@@ -34,90 +51,101 @@ def test_get_prev_sunday(self):
3451
self.assertEqual(str(start_sun), "2013-09-22")
3552

3653
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)
3855
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)
4057
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)
4259
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")
4560

4661
def test_get_first_day_quarter(self):
62+
# MUWM-5273
4763
notice = MyuwNotice(title="Test",
4864
content="Notice Content Five",
4965
notice_type="Banner",
5066
notice_category="MyUWNotice",
51-
start_week=-2,
52-
duration=1,
67+
start_week=0,
68+
duration=2,
69+
is_spring=True,
5370
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
5475
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)
5877
self.assertEqual(str(dt), "2013-07-25")
5978

6079
notice = MyuwNotice(title="Test",
6180
content="Notice Content Five",
6281
notice_type="Banner",
6382
notice_category="MyUWNotice",
64-
start_week=-2,
83+
start_week=-1,
6584
duration=1,
85+
is_summer_a=True,
86+
is_summer_b=True,
6687
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)
7199
self.assertEqual(str(dt), "2013-09-25")
72100

73101
def test_get_notices_by_term(self):
74102
notice = MyuwNotice(title="Test1",
75103
content="Notice Content Five",
76104
notice_type="Banner",
77105
notice_category="MyUWNotice",
78-
start_week=2,
79-
duration=1,
106+
start_week=-2,
107+
duration=4,
80108
is_summer_a=True)
81109
notice.save()
82110
notice = MyuwNotice(title="Test2",
83111
content="Notice Content Five",
84112
notice_type="Banner",
85113
start_week=-2,
86-
duration=1,
114+
duration=4,
87115
is_summer_b=True)
88116
notice.save()
89117
notice = MyuwNotice(title="Test3",
90118
content="Notice Content Five",
91119
notice_type="Banner",
92120
notice_category="MyUWNotice",
93-
start_week=3,
94-
duration=2,
121+
start_week=-2,
122+
duration=4,
95123
is_autumn=True)
96124
notice.save()
97-
request = get_request_with_date("2013-07-08")
125+
request = get_request_with_date("2013-06-09")
98126
notices = get_notices_by_term(request)
99-
self.assertEqual(len(notices), 2)
127+
self.assertEqual(len(notices), 1)
100128
self.assertEqual(notices[0].title, "Test1")
101-
self.assertEqual(notices[1].title, "Test2")
102129

103-
request = get_request_with_date("2013-08-25")
130+
request = get_request_with_date("2013-07-07")
104131
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")
106134

107-
request = get_request_with_date("2013-10-12")
135+
request = get_request_with_date("2013-08-11")
108136
notices = get_notices_by_term(request)
109137
self.assertEqual(len(notices), 0)
110138

111-
request = get_request_with_date("2013-10-13")
139+
request = get_request_with_date("2013-09-07")
112140
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)
115142

116-
request = get_request_with_date("2013-10-26")
143+
request = get_request_with_date("2013-09-08")
117144
notices = get_notices_by_term(request)
118145
self.assertEqual(len(notices), 1)
146+
self.assertEqual(notices[0].title, "Test3")
119147

120-
request = get_request_with_date("2013-10-27")
148+
request = get_request_with_date("2013-10-06")
121149
notices = get_notices_by_term(request)
122150
self.assertEqual(len(notices), 0)
123151

myuw/test/dao/test_term.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
from datetime import datetime
55
from django.test import TestCase
66
from commonconf import override_settings
7-
from uw_sws.models import ClassSchedule, Term, Section, Person
87
from myuw.dao.term import (
9-
get_specific_term, is_past, is_future, sws_now,
8+
get_specific_term, is_past, is_future, sws_now, current_terms_prefetch,
109
get_default_date, get_default_datetime, get_comparison_date,
1110
get_current_quarter, get_next_quarter, is_cur_term_before,
1211
get_previous_number_quarters, last_4instruction_weeks,
@@ -33,6 +32,20 @@ class TestTerm(TestCase):
3332
def setUp(self):
3433
get_request()
3534

35+
def test_current_terms_prefetch(self):
36+
request = get_request_with_date("2013-12-21")
37+
methods = current_terms_prefetch(request)
38+
self.assertEqual(len(methods), 6)
39+
request = get_request_with_date("2013-03-01")
40+
methods = current_terms_prefetch(request)
41+
self.assertEqual(len(methods), 5)
42+
request = get_request_with_date("2013-06-24")
43+
methods = current_terms_prefetch(request)
44+
self.assertEqual(len(methods), 4)
45+
request = get_request_with_date("2013-09-24")
46+
methods = current_terms_prefetch(request)
47+
self.assertEqual(len(methods), 5)
48+
3649
def test_get_term(self):
3750
term = get_specific_term(2013, "summer")
3851
self.assertEqual(term.year, 2013)

myuw/test/util/test_cache.py

+23-15
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,50 @@ def test_get_cache_time(self):
3434
self.assertEquals(cache.get_cache_expiration_time(
3535
"myplan_auth", "/oauth2/token"), 60 * 45)
3636
self.assertEquals(cache.get_cache_expiration_time(
37-
"sws", "/student/v5/term/2013,spring.json"), ONE_DAY)
37+
"sws", "/student/v5/term/2013,spring.json", status=200), ONE_DAY)
3838
self.assertEquals(cache.get_cache_expiration_time(
39-
"sws", "/student/v5/term/current.json"), ONE_DAY)
39+
"sws", "/student/v5/term/current.json", status=200), ONE_DAY)
4040
self.assertEquals(cache.get_cache_expiration_time(
41-
"sws", "/student/v5/course/.../status.json"), FOUR_HOURS)
41+
"sws", "/student/v5/course/.../status.json", status=200), FOUR_HOURS)
4242
self.assertEquals(cache.get_cache_expiration_time(
43-
"sws", "/student/v5/course/"), FIFTEEN_MINS)
43+
"sws", "/student/v5/course/", status=200), FIFTEEN_MINS)
4444
self.assertEquals(cache.get_cache_expiration_time(
45-
"sws", "/student/v5/person/"), ONE_HOUR)
45+
"sws", "/student/v5/person/", status=200), ONE_HOUR)
4646
self.assertEquals(cache.get_cache_expiration_time(
47-
"sws", "/student/v5/enrollment"), FIFTEEN_MINS)
47+
"sws", "/student/v5/enrollment", status=200), FIFTEEN_MINS)
4848
self.assertEquals(cache.get_cache_expiration_time(
49-
"sws", "/student/v5/notice"), FIFTEEN_MINS)
49+
"sws", "/student/v5/notice", status=200), FIFTEEN_MINS)
5050
self.assertEquals(cache.get_cache_expiration_time(
51-
"sws", "/student/v5/registration"), FIFTEEN_MINS)
51+
"sws", "/student/v5/registration", status=200), FIFTEEN_MINS)
5252
self.assertEquals(cache.get_cache_expiration_time(
53-
"sws", "/student/v5/section"), FIFTEEN_MINS)
53+
"sws", "/student/v5/section", status=200), FIFTEEN_MINS)
54+
self.assertEquals(cache.get_cache_expiration_time(
55+
"sws", "/student/v5/section", status=404), 60 * 7)
56+
self.assertEquals(cache.get_cache_expiration_time(
57+
"sws", "/student/v5/section", status=503), 60 * 15)
5458

5559
self.assertEquals(cache.get_cache_expiration_time(
5660
"gws", "/group_sws/v3", status=200), HALF_HOUR)
5761
self.assertEquals(cache.get_cache_expiration_time(
58-
"gws", "/group_sws/v3", status=404), 60 * 10)
62+
"gws", "/group_sws/v3", status=404), 60 * 7)
63+
self.assertEquals(cache.get_cache_expiration_time(
64+
"gws", "/group_sws/v3", status=500), 60 * 15)
5965

6066
self.assertEquals(cache.get_cache_expiration_time(
61-
"pws", "/identity/v2/person"), ONE_HOUR)
67+
"pws", "/identity/v2/person", status=200), ONE_HOUR)
6268
self.assertEquals(cache.get_cache_expiration_time(
63-
"pws", "/identity/v2/person", status=404), 60 * 5)
69+
"pws", "/identity/v2/person", status=404), 60 * 7)
6470
self.assertEquals(cache.get_cache_expiration_time(
6571
"pws", "/identity/v2/person", status=503), 60 * 15)
6672

6773
self.assertEquals(cache.get_cache_expiration_time(
68-
"uwnetid", "/nws/v1/uwnetid"), FOUR_HOURS)
74+
"uwnetid", "/nws/v1/uwnetid", status=200), FOUR_HOURS)
75+
self.assertEquals(cache.get_cache_expiration_time(
76+
"uwnetid", "/nws/v1/uwnetid", status=404), 60 * 7)
6977
self.assertEquals(cache.get_cache_expiration_time(
70-
"uwnetid", "/nws/v1/uwnetid", status=404), 60 * 5)
78+
"uwnetid", "/nws/v1/uwnetid", status=409), 60 * 7)
7179
self.assertEquals(cache.get_cache_expiration_time(
72-
"uwnetid", "/nws/v1/uwnetid", status=409), 60 * 5)
80+
"uwnetid", "/nws/v1/uwnetid", status=500), 60 * 15)
7381

7482
self.assertEquals(cache.get_cache_expiration_time(
7583
"grad", "/services/students"), FOUR_HOURS)

0 commit comments

Comments
 (0)