SciPost Code Repository

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

add factories for all ethics models

parent caa37fdf
No related branches found
No related tags found
No related merge requests found
__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
import datetime
import random
import django
import factory
from common.faker import LazyAwareDate, LazyRandEnum, fake
from scipost.factories import ContributorFactory
from submissions.models.submission import Submission
from .models import CompetingInterest, RedFlag, SubmissionClearance
class CompetingInterestFactory(factory.django.DjangoModelFactory):
class Meta:
model = CompetingInterest
django_get_or_create = (
"profile",
"related_profile",
"nature",
"date_from",
"date_until",
)
profile = factory.SubFactory("scipost.factories.ProfileFactory")
related_profile = factory.SubFactory("scipost.factories.ProfileFactory")
declared_by = factory.LazyAttribute(
lambda self: ContributorFactory.from_profile(
profile=random.choice([self.profile, self.related_profile])
)
)
nature = LazyRandEnum(CompetingInterest.NATURE_CHOICES)
date_from = factory.Faker("date_time_this_decade")
date_until = factory.LazyAttribute(
lambda self: fake.aware.date_between(start_date=self.date_from, end_date="+1y")
)
comments = factory.Faker("text")
class SubmissionClearanceFactory(factory.django.DjangoModelFactory):
class Meta:
model = SubmissionClearance
profile = factory.SubFactory("scipost.factories.ProfileFactory")
submission = factory.SubFactory("submissions.factories.SubmissionFactory")
asserted_by = factory.SubFactory("scipost.factories.ContributorFactory")
asserted_on = LazyAwareDate("date_time_this_decade")
comments = factory.Faker("text")
class RedFlagFactory(factory.django.DjangoModelFactory):
class Meta:
model = RedFlag
abstract = True
django_get_or_create = (
"concerning_object_id",
"concerning_object_type",
"raised_by",
"raised_on",
)
description = factory.Faker("text")
raised_by = factory.SubFactory("scipost.factories.ContributorFactory")
raised_on = LazyAwareDate("date_time_this_decade")
class SubmissionRedFlagFactory(RedFlagFactory):
class Params:
submission = factory.SubFactory("submissions.factories.SubmissionFactory")
concerning_object_id = factory.SelfAttribute("submission.id")
concerning_object_type = factory.LazyAttribute(
lambda self: django.contrib.contenttypes.models.ContentType.objects.get_for_model(
self.submission
)
)
class ProfileRedFlagFactory(RedFlagFactory):
class Params:
profile = factory.SubFactory("scipost.factories.ProfileFactory")
concerning_object_id = factory.SelfAttribute("profile.id")
concerning_object_type = factory.LazyAttribute(
lambda self: django.contrib.contenttypes.models.ContentType.objects.get_for_model(
self.profile
)
)
__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from django.test import TestCase
# Create your tests here.
__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from django.test import TestCase
from ..factories import (
CompetingInterestFactory,
ProfileRedFlagFactory,
SubmissionClearanceFactory,
SubmissionRedFlagFactory,
)
class TestCompetingInterestFactory(TestCase):
def test_can_create_competing_interests(self):
competing_interest = CompetingInterestFactory()
self.assertIsNotNone(competing_interest)
def test_competing_interest_declaration_by_either_party(self):
competing_interest = CompetingInterestFactory()
self.assertIn(
competing_interest.declared_by.profile,
[competing_interest.profile, competing_interest.related_profile],
)
class TestSubmissionClearanceFactory(TestCase):
def test_can_create_submission_clearances(self):
submission_clearance = SubmissionClearanceFactory()
self.assertIsNotNone(submission_clearance)
class TestSubmissionRedFlagFactory(TestCase):
def test_can_create_submission_red_flags(self):
submission_red_flag = SubmissionRedFlagFactory()
self.assertIsNotNone(submission_red_flag)
class TestProfileRedFlagFactory(TestCase):
def test_can_create_profile_red_flags(self):
profile_red_flag = ProfileRedFlagFactory()
self.assertIsNotNone(profile_red_flag)
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