|
| 1 | +import os |
| 2 | +from pprint import pprint |
| 3 | + |
| 4 | +from django.core.files.uploadedfile import SimpleUploadedFile |
1 | 5 | from model_bakery import baker
|
2 | 6 | from django.conf import settings
|
3 | 7 | from django.contrib.auth import get_user_model
|
@@ -448,6 +452,36 @@ def test_fulfilled_assets(self):
|
448 | 452 | self.assertEqual(1, len(context["fulfilled_assets"]))
|
449 | 453 | self.assertIn(asset, context["fulfilled_assets"])
|
450 | 454 |
|
| 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 | + |
451 | 485 |
|
452 | 486 | class UpdateSponsorInfoViewTests(TestCase):
|
453 | 487 |
|
|
0 commit comments