From 327a9e25469248a55a3532170b7d172628382674 Mon Sep 17 00:00:00 2001 From: Kipchirchir Sigei Date: Fri, 20 May 2022 12:17:34 +0300 Subject: [PATCH 1/2] Add allow_redirects to handle url redirect when making head request Signed-off-by: Kipchirchir Sigei --- onadata/apps/main/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onadata/apps/main/forms.py b/onadata/apps/main/forms.py index 7a4afd10ea..ae0a82286e 100644 --- a/onadata/apps/main/forms.py +++ b/onadata/apps/main/forms.py @@ -410,7 +410,7 @@ def publish(self, user, id_string=None, created_by=None): name, extension = os.path.splitext(cleaned_xls_file) if extension not in VALID_FILE_EXTENSIONS and name: - response = requests.head(cleaned_url) + response = requests.head(cleaned_url, allow_redirects=True) if ( response.headers.get("content-type") in VALID_XLSFORM_CONTENT_TYPES From f3b4043f58f988f9d5a876077439e507d9b342c4 Mon Sep 17 00:00:00 2001 From: Kipchirchir Sigei Date: Fri, 20 May 2022 12:18:17 +0300 Subject: [PATCH 2/2] Add test to ensure allow_redirects is set Signed-off-by: Kipchirchir Sigei --- onadata/apps/main/tests/test_process.py | 1 + 1 file changed, 1 insertion(+) diff --git a/onadata/apps/main/tests/test_process.py b/onadata/apps/main/tests/test_process.py index 3cbee927b5..9676da1fa6 100644 --- a/onadata/apps/main/tests/test_process.py +++ b/onadata/apps/main/tests/test_process.py @@ -142,6 +142,7 @@ def test_google_url_upload(self, mock_requests): ) mock_requests.get.assert_called_with(xls_url) + mock_requests.head.assert_called_with(xls_url, allow_redirects=True) # make sure publishing the survey worked self.assertEqual(response.status_code, 200) self.assertEqual(XForm.objects.count(), pre_count + 1)