mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-03 22:19:16 +02:00
Fixed #54: Now use pytest everywhere \o/
This commit is contained in:
parent
a7758395ee
commit
099cdfa99c
65 changed files with 1466 additions and 1467 deletions
30
api/funkwhale_api/factories.py
Normal file
30
api/funkwhale_api/factories.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import factory
|
||||
import persisting_theory
|
||||
|
||||
|
||||
class FactoriesRegistry(persisting_theory.Registry):
|
||||
look_into = 'factories'
|
||||
|
||||
def prepare_name(self, data, name=None):
|
||||
return name or data._meta.model._meta.label
|
||||
|
||||
|
||||
registry = FactoriesRegistry()
|
||||
|
||||
|
||||
def ManyToManyFromList(field_name):
|
||||
"""
|
||||
To automate the pattern described in
|
||||
http://factoryboy.readthedocs.io/en/latest/recipes.html#simple-many-to-many-relationship
|
||||
"""
|
||||
|
||||
@factory.post_generation
|
||||
def inner(self, create, extracted, **kwargs):
|
||||
if not create:
|
||||
return
|
||||
|
||||
if extracted:
|
||||
field = getattr(self, field_name)
|
||||
field.add(*extracted)
|
||||
|
||||
return inner
|
Loading…
Add table
Add a link
Reference in a new issue