From b3e7045e66c906b7e743d3e90395cddc63b198ae Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Thu, 19 Sep 2024 12:36:56 -0500 Subject: [PATCH 1/3] fix: links are direct to assett Closes: #2577 --- templates/users/sponsorship_detail.html | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/templates/users/sponsorship_detail.html b/templates/users/sponsorship_detail.html index 447b4245c..99dd9c7da 100644 --- a/templates/users/sponsorship_detail.html +++ b/templates/users/sponsorship_detail.html @@ -114,9 +114,17 @@

Provided Assets

Assets from the PSF related to your sponsorship.



Or you can also click here to view all the assets under the same page. From 86f9f211aa3ca689f784f0c1f4f2923da1c3c9ae Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Thu, 19 Sep 2024 13:51:17 -0500 Subject: [PATCH 2/3] test: add them --- users/tests/test_views.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/users/tests/test_views.py b/users/tests/test_views.py index 83b8330f9..8b4849f60 100644 --- a/users/tests/test_views.py +++ b/users/tests/test_views.py @@ -1,3 +1,7 @@ +import os +from pprint import pprint + +from django.core.files.uploadedfile import SimpleUploadedFile from model_bakery import baker from django.conf import settings from django.contrib.auth import get_user_model @@ -448,6 +452,36 @@ def test_fulfilled_assets(self): self.assertEqual(1, len(context["fulfilled_assets"])) self.assertIn(asset, context["fulfilled_assets"]) + def test_asset_links_are_direct(self) -> None: + """Ensure that assets listed under 'Provided Assets' in `/users/sponsorships/#/` are directly accessible.""" + # Create a sponsorship with a provided file asset + cfg = baker.make( + "sponsors.ProvidedFileAssetConfiguration", + internal_name="test_provided_file_asset", + related_to="sponsorship", + ) + benefit = baker.make("sponsors.SponsorBenefit",sponsorship=self.sponsorship) + asset = cfg.create_benefit_feature(benefit) + file_content = b"This is a test file." + test_file = SimpleUploadedFile( + "test_file.pdf", + file_content, + content_type="application/pdf" + ) + asset.value = test_file + asset.save() + + # Then we can read the page + response = self.client.get(self.url) + content = response.content.decode("utf-8") + expected_asset_link = f'href="{asset.value.url}"' + + # and finally check that the asset link is ACTUALLY pointing to the asset and not the list view page + self.assertIn("View asset", content, "View asset text not found.") + self.assertIn(expected_asset_link, content, "Asset link not found in the page.") + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "users/sponsorship_detail.html") + class UpdateSponsorInfoViewTests(TestCase): From bfc2b2c064197cf348b8c569be090ab6c0c18fb1 Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Thu, 19 Sep 2024 13:54:40 -0500 Subject: [PATCH 3/3] chore: remove unused imports --- users/tests/test_views.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/users/tests/test_views.py b/users/tests/test_views.py index 8b4849f60..09ad4c17e 100644 --- a/users/tests/test_views.py +++ b/users/tests/test_views.py @@ -1,12 +1,9 @@ -import os -from pprint import pprint - from django.core.files.uploadedfile import SimpleUploadedFile from model_bakery import baker from django.conf import settings from django.contrib.auth import get_user_model from django.urls import reverse -from django.test import TestCase, override_settings +from django.test import TestCase from sponsors.forms import SponsorUpdateForm, SponsorRequiredAssetsForm from sponsors.models import Sponsorship, RequiredTextAssetConfiguration, SponsorBenefit