Skip to content

Commit

Permalink
MUWM-5272: return None if the term has no data
Browse files Browse the repository at this point in the history
  • Loading branch information
fanglinfang committed Dec 15, 2023
1 parent f8daa14 commit 7da727b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions myuw/dao/textbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ def get_order_url_by_schedule(schedule):

def get_iacourse_status(request, term):
"""
returns a TermIACourse object
MUWM-5272
returns a TermIACourse object if has data, otherwith return None
"""
terms_iacourses = bookstore.get_iacourse_status(
get_regid_of_current_user(request)
)
key = "{}{}".format(term.quarter, term.year)
if terms_iacourses:
if key in terms_iacourses:
return terms_iacourses.get(key)
return None
8 changes: 8 additions & 0 deletions myuw/test/api/test_textbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def test_digital_material_api(self):
self.assertEquals(data["year"], 2013)
self.assertEquals(data["balance"], 0)

response = self.get_response_by_reverse(
'myuw_iacourse_digital_material_api',
kwargs={'year': 2013,
'quarter': 'winter'})
self.assertEquals(response.status_code, 200)
data = json.loads(response.content)
self.assertIsNone(data)

self.set_user('jbothell')
response = self.get_response_by_reverse(
'myuw_iacourse_digital_material_api',
Expand Down
6 changes: 6 additions & 0 deletions myuw/test/dao/test_textbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ def test_get_iacourse_status(self):
term = get_current_quarter(req)
data = get_iacourse_status(req, term)
self.assertIsNotNone(data.json_data())

req = get_request_with_user(
'javerage', get_request_with_date("2013-12-31"))
term = get_current_quarter(req)
data = get_iacourse_status(req, term)
self.assertIsNone(data.json_data())
4 changes: 1 addition & 3 deletions myuw/views/api/textbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ def get(self, request, *args, **kwargs):
try:
ret_obj = get_iacourse_status(
request, get_payment_quarter(request))
if ret_obj:
return self.json_response(ret_obj.json_data())
return {}
return self.json_response(ret_obj.json_data())
except Exception:
return handle_exception(logger, timer, traceback)
finally:
Expand Down

0 comments on commit 7da727b

Please sign in to comment.