Skip to content

Commit

Permalink
MUWM-5272: adjust payment quarter
Browse files Browse the repository at this point in the history
  • Loading branch information
fanglinfang committed Dec 15, 2023
1 parent b2ef3c7 commit 53881f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
23 changes: 18 additions & 5 deletions myuw/test/api/test_textbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# SPDX-License-Identifier: Apache-2.0

import json
from myuw.views.api.textbook import get_payment_quarter
from myuw.test import get_request_with_date
from myuw.test.api import MyuwApiTest, require_url, fdao_bookstore_override
from myuw.test import get_request_with_user, get_request_with_date


VERBACOMPARE_URL_PREFIX = 'http://uw-seattle.verbacompare.com'
IMAGE_URL_PREFIX = 'www7.bookstore.washington.edu/MyUWImage.taf'
Expand All @@ -14,7 +14,7 @@
class TestApiBooks(MyuwApiTest):
'''Tests textbooks api'''

@require_url('myuw_home')
@require_url('myuw_book_api')
def test_javerage_books(self):
self.set_user('javerage')
response = self.get_response_by_reverse(
Expand Down Expand Up @@ -54,8 +54,8 @@ def test_no_sche_books(self):
'summer_term': ''})
self.assertEquals(response.status_code, 200)

@require_url('myuw_home')
def test_javerage_digital_material(self):
@require_url('myuw_iacourse_digital_material_api')
def test_digital_material_api(self):
self.set_user('javerage')
response = self.get_response_by_reverse(
'myuw_iacourse_digital_material')
Expand Down Expand Up @@ -94,3 +94,16 @@ def test_javerage_digital_material(self):
response = self.get_response_by_reverse(
'myuw_iacourse_digital_material')
self.assertEquals(response.status_code, 404)

def test_get_payment_quarter(self):
request = get_request_with_date('2013-04-19')
q = get_payment_quarter(request)
self.assertEquals(q.quarter, "spring")

request = get_request_with_date('2013-04-22')
q = get_payment_quarter(request)
self.assertEquals(q.quarter, "summer")

request = get_request_with_date('2013-07-15')
q = get_payment_quarter(request)
self.assertEquals(q.quarter, "autumn")
8 changes: 4 additions & 4 deletions myuw/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from myuw.views.api.category_links import CategoryLinks
from myuw.views.api.other_quarters import RegisteredFutureQuarters
from myuw.views.api.textbook import (
Textbook, TextbookCur, CurIACDigitalItems, IACDigitalItems)
Textbook, TextbookCur, IACDigitalItemsCur, IACDigitalItems)
from myuw.views.api.notices import Notices
from myuw.views.api.myplan import MyPlan
from myuw.views.api.academic_events import AcademicEvents
Expand Down Expand Up @@ -140,7 +140,7 @@
re_path(r'^api/v1/affiliation/?$',
Affiliation.as_view(),
name="myuw_affiliation"),
re_path(r'^api/v1/book/current$',
re_path(r'^api/v1/book/current/?$',
TextbookCur.as_view(),
name="myuw_current_book"),
re_path(r'^api/v1/book/(?P<year>\d{4}),(?P<quarter>[a-z]+)'
Expand All @@ -150,8 +150,8 @@
re_path(r'^api/v1/iacourse/(?P<year>\d{4}),(?P<quarter>[a-z]+)',
IACDigitalItems.as_view(),
name="myuw_iacourse_digital_material_api"),
re_path(r'^api/v1/iacourse/current$',
CurIACDigitalItems.as_view(),
re_path(r'^api/v1/iacourse/current/?$',
IACDigitalItemsCur.as_view(),
name="myuw_iacourse_digital_material"),
re_path(r'^api/v1/categorylinks/(?P<category_id>.*?)$',
CategoryLinks.as_view(),
Expand Down
18 changes: 14 additions & 4 deletions myuw/views/api/textbook.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Copyright 2023 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from datetime import timedelta
import logging
import traceback
from restclients_core.exceptions import DataFailureException
from myuw.dao.registration import get_schedule_by_term
from myuw.dao.instructor_schedule import get_instructor_schedule_by_term
from myuw.dao.term import get_specific_term, get_current_quarter
from myuw.dao.term import (
get_specific_term, get_comparison_date, get_current_quarter, get_term_after)
from myuw.dao.textbook import (
get_textbook_by_schedule, get_order_url_by_schedule,
get_iacourse_status)
Expand Down Expand Up @@ -129,7 +131,7 @@ def get(self, request, *args, **kwargs):
year, quarter))


class CurIACDigitalItems(ProtectedAPI):
class IACDigitalItemsCur(ProtectedAPI):
def get(self, request, *args, **kwargs):
"""
myuw_iacourse_digital_material
Expand All @@ -138,11 +140,19 @@ def get(self, request, *args, **kwargs):
timer = Timer()
try:
ret_obj = get_iacourse_status(
request, get_current_quarter(request))
request, get_payment_quarter(request))
if ret_obj:
return self.json_response(ret_obj.json_data())
return {}
except Exception:
return handle_exception(logger, timer, traceback)
finally:
log_api_call(timer, request, "CurIACDigitalItems")
log_api_call(timer, request, "IACDigitalItemsCur")


def get_payment_quarter(request):
term = get_current_quarter(request)
comparison_date = get_comparison_date(request)
if comparison_date > term.first_day_quarter + timedelta(days=20):
return get_term_after(term)
return term

0 comments on commit 53881f4

Please sign in to comment.