Skip to content

Commit 86f9f21

Browse files
committed
test: add them
1 parent b3e7045 commit 86f9f21

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

users/tests/test_views.py

+34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import os
2+
from pprint import pprint
3+
4+
from django.core.files.uploadedfile import SimpleUploadedFile
15
from model_bakery import baker
26
from django.conf import settings
37
from django.contrib.auth import get_user_model
@@ -448,6 +452,36 @@ def test_fulfilled_assets(self):
448452
self.assertEqual(1, len(context["fulfilled_assets"]))
449453
self.assertIn(asset, context["fulfilled_assets"])
450454

455+
def test_asset_links_are_direct(self) -> None:
456+
"""Ensure that assets listed under 'Provided Assets' in `/users/sponsorships/#/` are directly accessible."""
457+
# Create a sponsorship with a provided file asset
458+
cfg = baker.make(
459+
"sponsors.ProvidedFileAssetConfiguration",
460+
internal_name="test_provided_file_asset",
461+
related_to="sponsorship",
462+
)
463+
benefit = baker.make("sponsors.SponsorBenefit",sponsorship=self.sponsorship)
464+
asset = cfg.create_benefit_feature(benefit)
465+
file_content = b"This is a test file."
466+
test_file = SimpleUploadedFile(
467+
"test_file.pdf",
468+
file_content,
469+
content_type="application/pdf"
470+
)
471+
asset.value = test_file
472+
asset.save()
473+
474+
# Then we can read the page
475+
response = self.client.get(self.url)
476+
content = response.content.decode("utf-8")
477+
expected_asset_link = f'href="{asset.value.url}"'
478+
479+
# and finally check that the asset link is ACTUALLY pointing to the asset and not the list view page
480+
self.assertIn("View asset", content, "View asset text not found.")
481+
self.assertIn(expected_asset_link, content, "Asset link not found in the page.")
482+
self.assertEqual(response.status_code, 200)
483+
self.assertTemplateUsed(response, "users/sponsorship_detail.html")
484+
451485

452486
class UpdateSponsorInfoViewTests(TestCase):
453487

0 commit comments

Comments
 (0)