SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 2dfc33a3 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

add factories for all theses models

parent 00e14b8b
No related branches found
No related tags found
No related merge requests found
......@@ -9,10 +9,12 @@ from ontology.models import AcademicField, Specialty
from scipost.constants import SCIPOST_APPROACHES
from scipost.models import Contributor
from .models import ThesisLink
from .models import *
from .forms import VetThesisLinkForm
from .constants import THESIS_TYPES
from common.faker import LazyRandEnum, fake
class BaseThesisLinkFactory(factory.django.DjangoModelFactory):
class Meta:
......@@ -23,34 +25,17 @@ class BaseThesisLinkFactory(factory.django.DjangoModelFactory):
vetted_by = factory.SubFactory("scipost.factories.ContributorFactory")
vetted = True
type = factory.Iterator(THESIS_TYPES, getter=lambda c: c[0])
type = LazyRandEnum(THESIS_TYPES)
acad_field = factory.SubFactory("ontology.factories.AcademicFieldFactory")
approaches = factory.Iterator(
SCIPOST_APPROACHES,
getter=lambda c: [
c[0],
],
)
approaches = LazyRandEnum(SCIPOST_APPROACHES, repeat=2)
title = factory.Faker("sentence")
pub_link = factory.Faker("uri")
author = factory.Faker("name")
supervisor = factory.Faker("name")
institution = factory.Faker("company")
defense_date = factory.Faker("date_this_decade")
defense_date = fake.aware.date_this_decade()
abstract = factory.Faker("paragraph")
@classmethod
def create(cls, **kwargs):
if AcademicField.objects.count() < 5:
from ontology.factories import AcademicFieldactory
AcademicFieldFactory.create_batch(5)
if Specialty.objects.count() < 5:
from ontology.factories import SpecialtyFactory
SpecialtyFactory.create_batch(5)
return super().create(**kwargs)
@factory.post_generation
def add_specialties(self, create, extracted, **kwargs):
if create:
......@@ -66,9 +51,6 @@ class BaseThesisLinkFactory(factory.django.DjangoModelFactory):
# A list of groups were passed in, use them
for contributor in extracted:
self.author_as_cont.add(contributor)
elif factory.Faker("boolean"):
contributor = Contributor.objects.order_by("?").first()
self.author_as_cont.add(contributor)
class ThesisLinkFactory(BaseThesisLinkFactory):
......
__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from django.test import TestCase
from ..factories import *
class TestThesisLinkFactory(TestCase):
def test_can_create_thesis_links(self):
thesis_link = ThesisLinkFactory()
self.assertIsNotNone(thesis_link)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment