From 0a9b1839eea2a7ea4b29e9d07aa669f90ed463db Mon Sep 17 00:00:00 2001 From: kyokukou Date: Fri, 20 Sep 2024 08:17:20 -0700 Subject: [PATCH] fix catchup redirect --- browse/controllers/catchup_page.py | 9 ++++----- tests/test_catchup.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/browse/controllers/catchup_page.py b/browse/controllers/catchup_page.py index 70fbb85b..1da462b0 100644 --- a/browse/controllers/catchup_page.py +++ b/browse/controllers/catchup_page.py @@ -25,14 +25,13 @@ def get_catchup_page(subject_str:str, date:str)-> Response: subject, start_day, include_abs, page=_process_catchup_params(subject_str, date) #check for redirects for noncanon subjects if subject.id != subject.canonical_id: - return redirect( - url_for('catchup', + new_address=url_for('browse.catchup', subject=subject.canonical_id, date=start_day, page=page, - abs=include_abs), - HTTPStatus.MOVED_PERMANENTLY) #type: ignore - + abs=include_abs) + return {}, HTTPStatus.MOVED_PERMANENTLY, {"Location":new_address} + headers: Dict[str,str]={} headers=add_surrogate_key(headers,["catchup",f"list-{start_day.year:04d}-{start_day.month:02d}-{subject.id}"]) #get data diff --git a/tests/test_catchup.py b/tests/test_catchup.py index 5faaf569..bfde064d 100644 --- a/tests/test_catchup.py +++ b/tests/test_catchup.py @@ -551,4 +551,14 @@ def test_catchup_form_redirect(dbclient): assert 'Surrogate-Key' in resp.headers header= resp.headers['Surrogate-Key'] assert " catchup " in " "+header+" " - assert " catchup-redirect " in " "+header+" " \ No newline at end of file + assert " catchup-redirect " in " "+header+" " + +def test_catchup_alias_redirect(dbclient): + with patch('browse.controllers.catchup_page.datetime') as mock_datetime: + mock_datetime.now.return_value = datetime(2011, 2, 15) + mock_datetime.date = datetime.date + mock_datetime.strptime = datetime.strptime + resp = dbclient.get("/catchup/math.MP/2011-02-03?page=1") + assert resp.status_code ==301 + redirect_location = resp.headers.get("Location") + assert redirect_location == "/catchup/math-ph/2011-02-03?page=1&abs=False" \ No newline at end of file