Source code for ontology.factories

__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"


import factory

from django.utils.text import slugify

from .models import Branch, AcademicField, Specialty


[docs]class BranchFactory(factory.django.DjangoModelFactory): name = factory.LazyAttribute(lambda b: "Branch %d" % b.order) slug = factory.LazyAttribute(lambda b: slugify("branch-%d" % b.order)) order = factory.Sequence(lambda n: Branch.objects.count() + 1) class Meta: model = Branch
[docs]class AcademicFieldFactory(factory.django.DjangoModelFactory): branch = factory.SubFactory(BranchFactory) name = factory.LazyAttribute(lambda b: "Field %d" % b.order) slug = factory.LazyAttribute(lambda b: slugify("field-%d" % b.order)) order = factory.Sequence(lambda n: AcademicField.objects.count() + 1) class Meta: model = AcademicField
[docs]class SpecialtyFactory(factory.django.DjangoModelFactory): acad_field = factory.SubFactory(AcademicFieldFactory) name = factory.LazyAttribute(lambda b: "Specialty %d" % b.order) slug = factory.LazyAttribute(lambda b: slugify("specialty-%d" % b.order)) order = factory.Sequence(lambda n: Specialty.objects.count() + 1) class Meta: model = Specialty