Skip to content
Merged
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
53 changes: 53 additions & 0 deletions tests/unit/packaging/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from warehouse.packaging import views

from ...common.db.accounts import UserFactory
from ...common.db.classifiers import ClassifierFactory
from ...common.db.packaging import (
ProjectFactory, ReleaseFactory, FileFactory, RoleFactory,
)
Expand Down Expand Up @@ -131,4 +132,56 @@ def test_detail_renders(self, db_request):
(r.version, r.created) for r in reversed(releases)
],
"maintainers": sorted(users, key=lambda u: u.username.lower()),
"license": None
}

def test_license_from_classifier(self, db_request):
"""A license label is added when a license classifier exists."""
other_classifier = ClassifierFactory.create(
classifier="Some :: Random :: Classifier")
classifier = ClassifierFactory.create(
classifier="License :: OSI Approved :: BSD License")
release = ReleaseFactory.create(
_classifiers=[other_classifier, classifier],
license="Will not be used")

result = views.release_detail(release, db_request)

assert result["license"] == "BSD License"

def test_license_with_no_classifier(self, db_request):
"""With no classifier, a license is used from metadata."""
release = ReleaseFactory.create(license="MIT License")

result = views.release_detail(release, db_request)

assert result["license"] == "MIT License"

def test_multiline_license(self, db_request):
"""When license metadata is longer than one line, the first is used."""
release = ReleaseFactory.create(
license="Multiline License\nhow terrible")

result = views.release_detail(release, db_request)

assert result["license"] == "Multiline License"

def test_no_license(self, db_request):
"""With no license classifier or metadata, no license is in context."""
release = ReleaseFactory.create()

result = views.release_detail(release, db_request)

assert result["license"] is None

def test_multiple_licenses_from_classifiers(self, db_request):
"""A license label is added when multiple license classifiers exist."""
license_1 = ClassifierFactory.create(
classifier="License :: OSI Approved :: BSD License")
license_2 = ClassifierFactory.create(
classifier="License :: OSI Approved :: MIT License")
release = ReleaseFactory.create(_classifiers=[license_1, license_2])

result = views.release_detail(release, db_request)

assert result["license"] == "BSD License, MIT License"
12 changes: 12 additions & 0 deletions warehouse/packaging/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,22 @@ def release_detail(release, request):
)
]

# Get the license from the classifiers or metadata, preferring classifiers.
license = None
if release.license:
# Make a best effort when the entire license text is given
# by using the first line only.
license = release.license.split('\n')[0]
license_classifiers = [c.split(" :: ")[-1] for c in release.classifiers
if c.startswith("License")]
if license_classifiers:
license = ', '.join(license_classifiers)

return {
"project": project,
"release": release,
"files": release.files.all(),
"all_releases": all_releases,
"maintainers": maintainers,
"license": license,
}
7 changes: 0 additions & 7 deletions warehouse/static/sass/blocks/_package-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@
}

&__license {
padding-top: $spacing-unit / 2;
float: right;
font-style: italic;

@media only screen and (max-width: $tablet){
padding-top: 0;
float: none;
}
}

&__name {
Expand Down
4 changes: 3 additions & 1 deletion warehouse/templates/packaging/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ <h3 class="package-snippet__title"><a href="{{ request.route_path('packaging.pro
{% block content %}
<section class="banner">
<div class="package-header">
<p class="package-header__license">License: <a href="TODO">TODO</a></p>
<h1 class="package-header__name">{{ release.project.name }} {{ release.version }}</h1>
<p class="package-header__description">{% if release.summary %}{{ release.summary }}{% endif %}</p>
<p class="package-header__pip-instructions">
Expand All @@ -70,6 +69,9 @@ <h1 class="package-header__name">{{ release.project.name }} {{ release.version }
<span class="sr-only">Copy PIP instructions<span>
</a>
</p>
{% if license %}
<p class="package-header__license">License: {{ license }}</p>
{% endif %}
</div>
</section>

Expand Down