This commit is contained in:
Tim Lorsbach
2025-11-11 19:26:23 +01:00
parent b627a3850b
commit f7d88e4235
2 changed files with 31 additions and 9 deletions

View File

@ -43,11 +43,11 @@ def set_cc(apps, schema_editor):
for k, v in license_lookup.items(): for k, v in license_lookup.items():
# Set to min ID # Set to min ID
print(Packages.objects.filter(pk__in=v[1]).update(license_id=v[0])) Packages.objects.filter(pk__in=v[1]).update(license_id=v[0])
# Remove min ID # Remove min ID
v[1].remove(v[0]) v[1].remove(v[0])
# Delete Redundant License Objects # Delete Redundant License Objects
print(License.objects.filter(pk__in=v[1]).delete()) License.objects.filter(pk__in=v[1]).delete()
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -4,7 +4,14 @@ from django.test import TestCase, tag
from django.urls import reverse from django.urls import reverse
from epdb.logic import UserManager from epdb.logic import UserManager
from epdb.models import Package, UserPackagePermission, Permission, GroupPackagePermission, Group, License from epdb.models import (
Package,
UserPackagePermission,
Permission,
GroupPackagePermission,
Group,
License,
)
class PackageViewTest(TestCase): class PackageViewTest(TestCase):
@ -32,11 +39,12 @@ class PackageViewTest(TestCase):
# Create the default license set. # Create the default license set.
cc_strings = ["by", "by-nc", "by-nc-nd", "by-nc-sa", "by-nd", "by-sa"] cc_strings = ["by", "by-nc", "by-nc-nd", "by-nc-sa", "by-nd", "by-sa"]
for cc_string in cc_strings: for cc_string in cc_strings:
new_license = License() if not License.objects.filter(cc_string=cc_string).exists():
new_license.cc_string = cc_string new_license = License()
new_license.link = f"https://creativecommons.org/licenses/{cc_string}/4.0/" new_license.cc_string = cc_string
new_license.image_link = f"https://licensebuttons.net/l/{cc_string}/4.0/88x31.png" new_license.link = f"https://creativecommons.org/licenses/{cc_string}/4.0/"
new_license.save() new_license.image_link = f"https://licensebuttons.net/l/{cc_string}/4.0/88x31.png"
new_license.save()
def setUp(self): def setUp(self):
self.client.force_login(self.user1) self.client.force_login(self.user1)
@ -203,7 +211,21 @@ class PackageViewTest(TestCase):
self.client.post(package_url, {"license": cc_string}) 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 # 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) p = Package.objects.get(url=package_url)
self.assertEqual(p.license.link, f"https://creativecommons.org/licenses/{cc_string}/4.0/") 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): def test_delete_package(self):
response = self.client.post( response = self.client.post(