refactor of license django model #119

This commit is contained in:
Liam Brydon
2025-11-10 14:51:44 +13:00
parent e26d5a21e3
commit 42b1e77fb9
7 changed files with 45 additions and 25 deletions

View File

@ -4,7 +4,7 @@ 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):
@ -30,6 +30,14 @@ class PackageViewTest(TestCase):
is_active=True,
)
cc_strings = ["by", "by-nc", "by-nc-nd", "by-nc-sa", "by-nd", "by-sa"]
for cc_string in cc_strings:
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 +196,13 @@ class PackageViewTest(TestCase):
self.client.post(package_url, {"license": "no-license"})
self.assertIsNone(p.license)
# TODO test others
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/")
def test_delete_package(self):
response = self.client.post(