mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 05:19:24 +02:00
Fix #308: Licenses
This commit is contained in:
parent
e97f1f0e0b
commit
e5b46402f8
29 changed files with 5595 additions and 66 deletions
|
@ -4,9 +4,9 @@ import factory
|
|||
|
||||
from funkwhale_api.factories import ManyToManyFromList, registry
|
||||
from funkwhale_api.federation import factories as federation_factories
|
||||
from funkwhale_api.music import licenses
|
||||
from funkwhale_api.users import factories as users_factories
|
||||
|
||||
|
||||
SAMPLES_PATH = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
|
||||
"tests",
|
||||
|
@ -30,6 +30,29 @@ def playable_factory(field):
|
|||
return inner
|
||||
|
||||
|
||||
def deduce_from_conf(field):
|
||||
@factory.lazy_attribute
|
||||
def inner(self):
|
||||
return licenses.LICENSES_BY_ID[self.code][field]
|
||||
|
||||
return inner
|
||||
|
||||
|
||||
@registry.register
|
||||
class LicenseFactory(factory.django.DjangoModelFactory):
|
||||
code = "cc-by-4.0"
|
||||
url = deduce_from_conf("url")
|
||||
commercial = deduce_from_conf("commercial")
|
||||
redistribute = deduce_from_conf("redistribute")
|
||||
copyleft = deduce_from_conf("copyleft")
|
||||
attribution = deduce_from_conf("attribution")
|
||||
derivative = deduce_from_conf("derivative")
|
||||
|
||||
class Meta:
|
||||
model = "music.License"
|
||||
django_get_or_create = ("code",)
|
||||
|
||||
|
||||
@registry.register
|
||||
class ArtistFactory(factory.django.DjangoModelFactory):
|
||||
name = factory.Faker("name")
|
||||
|
@ -70,6 +93,15 @@ class TrackFactory(factory.django.DjangoModelFactory):
|
|||
class Meta:
|
||||
model = "music.Track"
|
||||
|
||||
@factory.post_generation
|
||||
def license(self, created, extracted, **kwargs):
|
||||
if not created:
|
||||
return
|
||||
|
||||
if extracted:
|
||||
self.license = LicenseFactory(code=extracted)
|
||||
self.save()
|
||||
|
||||
|
||||
@registry.register
|
||||
class UploadFactory(factory.django.DjangoModelFactory):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue