Skip to content

Commit

Permalink
Merge pull request #2963 from uw-it-aca/main
Browse files Browse the repository at this point in the history
handle status being None
  • Loading branch information
fanglinfang committed Jun 22, 2023
2 parents 5f3ca66 + 6d65b16 commit 1ebe5d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions myuw/test/util/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,44 @@ def test_get_cache_time(self):
self.assertEquals(cache.get_cache_expiration_time(
"myplan_auth", "/oauth2/token"), 60 * 45)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/term/2013,spring.json", status=200), ONE_DAY)
"sws", "/student/v5/term/2013,spring.json"), ONE_DAY)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/term/current.json", status=200), ONE_DAY)
"sws", "/student/v5/term/current.json"), ONE_DAY)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/course/.../status.json", status=200), FOUR_HOURS)
"sws", "/student/v5/course/.../status.json"), FOUR_HOURS)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/course/", status=200), FIFTEEN_MINS)
"sws", "/student/v5/course/"), FIFTEEN_MINS)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/person/", status=200), ONE_HOUR)
"sws", "/student/v5/person/"), ONE_HOUR)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/enrollment", status=200), FIFTEEN_MINS)
"sws", "/student/v5/enrollment"), FIFTEEN_MINS)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/notice", status=200), FIFTEEN_MINS)
"sws", "/student/v5/notice"), FIFTEEN_MINS)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/registration", status=200), FIFTEEN_MINS)
"sws", "/student/v5/registration"), FIFTEEN_MINS)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/section", status=200), FIFTEEN_MINS)
"sws", "/student/v5/section"), FIFTEEN_MINS)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/section", status=404), 60 * 7)
self.assertEquals(cache.get_cache_expiration_time(
"sws", "/student/v5/section", status=503), 60 * 15)

self.assertEquals(cache.get_cache_expiration_time(
"gws", "/group_sws/v3", status=200), HALF_HOUR)
"gws", "/group_sws/v3"), HALF_HOUR)
self.assertEquals(cache.get_cache_expiration_time(
"gws", "/group_sws/v3", status=404), 60 * 7)
self.assertEquals(cache.get_cache_expiration_time(
"gws", "/group_sws/v3", status=500), 60 * 15)

self.assertEquals(cache.get_cache_expiration_time(
"pws", "/identity/v2/person", status=200), ONE_HOUR)
"pws", "/identity/v2/person"), ONE_HOUR)
self.assertEquals(cache.get_cache_expiration_time(
"pws", "/identity/v2/person", status=404), 60 * 7)
self.assertEquals(cache.get_cache_expiration_time(
"pws", "/identity/v2/person", status=503), 60 * 15)

self.assertEquals(cache.get_cache_expiration_time(
"uwnetid", "/nws/v1/uwnetid", status=200), FOUR_HOURS)
"uwnetid", "/nws/v1/uwnetid"), FOUR_HOURS)
self.assertEquals(cache.get_cache_expiration_time(
"uwnetid", "/nws/v1/uwnetid", status=404), 60 * 7)
self.assertEquals(cache.get_cache_expiration_time(
Expand Down
8 changes: 4 additions & 4 deletions myuw/util/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_cache_expiration_time(self, service, url, status=None):
return FIVE_SECONDS

if "sws" == service:
if status != 200:
if status and status != 200:
if status >= 500:
return FIFTEEN_MINS
return SEVEN_MINS
Expand All @@ -48,21 +48,21 @@ def get_cache_expiration_time(self, service, url, status=None):
return ONE_DAY

if "gws" == service:
if status != 200:
if status and status != 200:
if status >= 500:
return FIFTEEN_MINS
return SEVEN_MINS
return HALF_HOUR

if "pws" == service:
if status != 200:
if status and status != 200:
if status >= 500:
return FIFTEEN_MINS
return SEVEN_MINS
return ONE_HOUR

if "uwnetid" == service:
if status != 200:
if status and status != 200:
if status >= 500:
return FIFTEEN_MINS
return SEVEN_MINS
Expand Down

0 comments on commit 1ebe5d2

Please sign in to comment.