forked from enviPath/enviPy
[Enhancement] Refactor of license django model (#187)
Fixes #119 Licenses are now created in the bootstrap management command. To only create the licenses use the command line argument `-ol` or `--only-licenses`. These licenses are then fetched by there `cc_string` when adding a license to a package. Co-authored-by: Liam Brydon <62733830+MyCreativityOutlet@users.noreply.github.com> Co-authored-by: jebus <lorsbach@envipath.com> Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#187 Co-authored-by: liambrydon <lbry121@aucklanduni.ac.nz> Co-committed-by: liambrydon <lbry121@aucklanduni.ac.nz>
This commit is contained in:
@ -4,7 +4,14 @@ from django.test import TestCase, tag
|
||||
from django.urls import reverse
|
||||
|
||||
from epdb.logic import UserManager
|
||||
from epdb.models import Package, UserPackagePermission, Permission, GroupPackagePermission, Group
|
||||
from epdb.models import (
|
||||
Package,
|
||||
UserPackagePermission,
|
||||
Permission,
|
||||
GroupPackagePermission,
|
||||
Group,
|
||||
License,
|
||||
)
|
||||
|
||||
|
||||
class PackageViewTest(TestCase):
|
||||
@ -29,6 +36,15 @@ class PackageViewTest(TestCase):
|
||||
add_to_group=True,
|
||||
is_active=True,
|
||||
)
|
||||
# Create the default license set.
|
||||
cc_strings = ["by", "by-nc", "by-nc-nd", "by-nc-sa", "by-nd", "by-sa"]
|
||||
for cc_string in cc_strings:
|
||||
if not License.objects.filter(cc_string=cc_string).exists():
|
||||
new_license = License()
|
||||
new_license.cc_string = cc_string
|
||||
new_license.link = f"https://creativecommons.org/licenses/{cc_string}/4.0/"
|
||||
new_license.image_link = f"https://licensebuttons.net/l/{cc_string}/4.0/88x31.png"
|
||||
new_license.save()
|
||||
|
||||
def setUp(self):
|
||||
self.client.force_login(self.user1)
|
||||
@ -188,7 +204,28 @@ class PackageViewTest(TestCase):
|
||||
self.client.post(package_url, {"license": "no-license"})
|
||||
|
||||
self.assertIsNone(p.license)
|
||||
# TODO test others
|
||||
|
||||
# Test other possible licenses
|
||||
cc_strings = ["by", "by-nc", "by-nc-nd", "by-nc-sa", "by-nd", "by-sa"]
|
||||
for cc_string in cc_strings:
|
||||
self.client.post(package_url, {"license": cc_string})
|
||||
# Without this, the instance of p doesn't have the license. However, the one retrieved with get does
|
||||
p = Package.objects.get(url=package_url)
|
||||
self.assertEqual(
|
||||
p.license.link, f"https://creativecommons.org/licenses/{cc_string}/4.0/"
|
||||
)
|
||||
|
||||
# Test again to ensure that Licenses are reused
|
||||
cc_strings = ["by", "by-nc", "by-nc-nd", "by-nc-sa", "by-nd", "by-sa"]
|
||||
for cc_string in cc_strings:
|
||||
self.client.post(package_url, {"license": cc_string})
|
||||
# Without this, the instance of p doesn't have the license. However, the one retrieved with get does
|
||||
p = Package.objects.get(url=package_url)
|
||||
self.assertEqual(
|
||||
p.license.link, f"https://creativecommons.org/licenses/{cc_string}/4.0/"
|
||||
)
|
||||
|
||||
self.assertEqual(License.objects.count(), len(cc_strings))
|
||||
|
||||
def test_delete_package(self):
|
||||
response = self.client.post(
|
||||
|
||||
Reference in New Issue
Block a user