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():
# 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
v[1].remove(v[0])
# 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):

View File

@ -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, License
from epdb.models import (
Package,
UserPackagePermission,
Permission,
GroupPackagePermission,
Group,
License,
)
class PackageViewTest(TestCase):
@ -32,6 +39,7 @@ class PackageViewTest(TestCase):
# 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/"
@ -203,7 +211,21 @@ class PackageViewTest(TestCase):
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(
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(