From 50cf1c2d0415dd5036d7b4788e4c2f9332516f38 Mon Sep 17 00:00:00 2001 From: Fang Lin Date: Tue, 24 Sep 2024 08:20:27 -0700 Subject: [PATCH] Apply error case policy to all services (#3154) --- myuw/test/util/test_cache.py | 5 +++++ myuw/util/cache.py | 26 +++++--------------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/myuw/test/util/test_cache.py b/myuw/test/util/test_cache.py index 6a28a9dcc..27ca87eac 100644 --- a/myuw/test/util/test_cache.py +++ b/myuw/test/util/test_cache.py @@ -101,6 +101,11 @@ def test_get_cache_time(self): self.assertEqual(cache.get_cache_expiration_time( "mailman", "/uw_list_manager/api/v1/list/", status=500), 60 * 15) + self.assertEqual(cache.get_cache_expiration_time( + "uwidp", "/idp/profile/oidc/keyset", status=404), 60 * 7) + self.assertEqual(cache.get_cache_expiration_time( + "uwidp", "/idp/profile/oidc/keyset", status=500), 60 * 15) + class TestMyUWCache(TestCase): diff --git a/myuw/util/cache.py b/myuw/util/cache.py index 6a6a45938..78ef7033e 100644 --- a/myuw/util/cache.py +++ b/myuw/util/cache.py @@ -24,12 +24,12 @@ def get_cache_expiration_time(self, service, url, status=None): if "myplan" == service: return FIVE_SECONDS - if "sws" == service: - if status and status != 200: - if status >= 500: - return FIFTEEN_MINS - return SEVEN_MINS + if status and status != 200: + if status >= 500: + return FIFTEEN_MINS + return SEVEN_MINS + if "sws" == service: if re.match(r'^/student/v5/term/', url): return ONE_DAY @@ -52,31 +52,15 @@ def get_cache_expiration_time(self, service, url, status=None): return ONE_DAY if "gws" == service: - if status and status != 200: - if status >= 500: - return FIFTEEN_MINS - return SEVEN_MINS return HALF_HOUR if "pws" == service: - if status and status != 200: - if status >= 500: - return FIFTEEN_MINS - return SEVEN_MINS return ONE_HOUR if "uwnetid" == service: - if status and status != 200: - if status >= 500: - return FIFTEEN_MINS - return SEVEN_MINS return FOUR_HOURS if "mailman" == service: - if status and status != 200: - if status >= 500: - return FIFTEEN_MINS - return SEVEN_MINS return ONE_DAY return FOUR_HOURS