Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: links are direct to asset #2593

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions templates/users/sponsorship_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ <h3>Provided Assets</h3>
<p><small>Assets from the PSF related to your sponsorship.</small></p>
<br/>
<ul>
{% for asset in provided_assets %}
<li><b>{{ asset.label }}</b>: <a href="{{ asset.user_view_url }}">View asset</a>.</li>
{% endfor %}
{% for asset in provided_assets %}
<li><b>{{ asset.label }}</b>:
{% if asset.polymorphic_ctype.name == "Provided File" %}
<a href="{{ asset.value.url }}">View asset</a>
{% elif asset.polymorphic_ctype.name == "Provided Text" %}
<pre>{{ asset.value|urlize }}</pre>
{% else %}
<a href="{{ asset.value }}">View asset</a>
{% endif %}
</li>
{% endfor %}
</ul>
<br/>
<small>Or you can also <a href="{% url 'users:view_provided_sponsorship_assets' sponsorship.pk %}">click here</a> to view all the assets under the same page.</small>
Expand Down
33 changes: 32 additions & 1 deletion users/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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
Expand Down Expand Up @@ -448,6 +449,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):

Expand Down