Skip to content

Commit 74a4b2e

Browse files
authored
Fix access to license/ app (#425)
* licenses/ will render all licenses without 500 error https://github.com/nexB/scancode.io/blob/16644a60c6dbe81fa078fc6941fbd8be817fe935/scancodeio/urls.py#L53 include function is updated Signed-off-by: lf32 <96695352+lf32@users.noreply.github.com> * Tests for getting all licenses and single license wrote test cases for licenses and moved all license urls to main urls.py Signed-off-by: lf32 <96695352+lf32@users.noreply.github.com> * Remove printing in tests Signed-off-by: lf32 <96695352+lf32@users.noreply.github.com> * Ran make valid successfully and renamed test functions * Ran `make valid` * Renamed test functions for licenses Signed-off-by: lf32 <96695352+lf32@users.noreply.github.com> * Removed Comment and corrected license path * Removed Comment * Chanded licenses/ back to license/ Signed-off-by: lf32 <96695352+lf32@users.noreply.github.com> * correct variable in license tests Signed-off-by: lf32 <96695352+lf32@users.noreply.github.com> * status code updated * added statuscode HttpResponseNotFound for unknown license * corrected license tests * override_settings for auth Signed-off-by: lf32 <96695352+lf32@users.noreply.github.com>
1 parent 40d9fdf commit 74a4b2e

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

scancodeio/licenses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from functools import lru_cache
2424

2525
from django.http import HttpResponse
26+
from django.http import HttpResponseNotFound
2627
from django.urls import path
2728
from django.urls import reverse
2829

@@ -67,7 +68,7 @@ def license_details_view(request, key):
6768
data = saneyaml.dump(licenses[key].to_dict())
6869
text = licenses[key].text
6970
except KeyError:
70-
return HttpResponse(f"License {key} not found.")
71+
return HttpResponseNotFound(f"License {key} not found.")
7172
return HttpResponse(f"<pre>{data}</pre><hr><pre>{text}</pre>")
7273

7374

scancodeio/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747
path("accounts/profile/", AccountProfileView.as_view(), name="account_profile"),
4848
]
4949

50+
5051
urlpatterns = auth_urlpatterns + [
5152
path("admin/", admin.site.urls),
5253
path("api/", include(api_router.urls)),
53-
path("license/", include((licenses.urls, "license_app"))),
54+
path("license/", include(licenses.urls)),
5455
path("", include("scanpipe.urls")),
5556
path("", RedirectView.as_view(url="project/")),
5657
]

scanpipe/tests/test_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ def test_scancodeio_auth_views_are_protected(self):
141141
("run_detail", [a_uuid]),
142142
("admin:index", None),
143143
("rq_home", None),
144-
("license_app:license_list", None),
145-
("license_app:license_details", [a_path]),
144+
("license_list", None),
145+
("license_details", [a_path]),
146146
]
147147

148148
for viewname, args in views:

scanpipe/tests/test_licenses.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# http://nexb.com and https://github.com/nexB/scancode.io
4+
# The ScanCode.io software is licensed under the Apache License version 2.0.
5+
# Data generated with ScanCode.io is provided as-is without warranties.
6+
# ScanCode is a trademark of nexB Inc.
7+
#
8+
# You may not use this software except in compliance with the License.
9+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
10+
# Unless required by applicable law or agreed to in writing, software distributed
11+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
16+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
17+
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
18+
# for any legal advice.
19+
#
20+
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
21+
# Visit https://github.com/nexB/scancode.io for support and download.
22+
23+
from unittest import mock
24+
25+
from django.test import TestCase
26+
from django.test import override_settings
27+
from django.urls import reverse
28+
29+
30+
@override_settings(SCANCODEIO_REQUIRE_AUTHENTICATION=False)
31+
class LicensesTest(TestCase):
32+
def test_license_list_view(self):
33+
url = reverse("license_list")
34+
response = self.client.get(url)
35+
self.assertEqual(response.status_code, 200)
36+
37+
def test_license_details_view(self):
38+
keys = ["apache-2.0", "abcdefg"]
39+
license_url = reverse("license_details", args=(keys[0],))
40+
dummy_license_url = reverse("license_details", args=(keys[1],))
41+
response = [self.client.get(license_url), self.client.get(dummy_license_url)]
42+
self.assertEqual(response[0].status_code, 200)
43+
self.assertEqual(response[1].status_code, 404)

0 commit comments

Comments
 (0)