SciPost Code Repository

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

add factories for all preprints models

parent 157940c8
No related branches found
No related tags found
No related merge requests found
......@@ -10,16 +10,17 @@ from .models import Preprint
class PreprintFactory(factory.django.DjangoModelFactory):
"""
Generate random Preprint instances.
"""
identifier_w_vn_nr = factory.Sequence(
lambda n: random_arxiv_identifier_with_version_number()
)
url = factory.lazy_attribute(
lambda o: ("https://arxiv.org/abs/%s" % o.identifier_w_vn_nr)
)
class Meta:
model = Preprint
class Params:
arXiv = factory.Trait(
identifier_w_vn_nr=random_arxiv_identifier_with_version_number(),
url=factory.LazyAttribute(
lambda self: f"https://arxiv.org/abs/{self.identifier_w_vn_nr}"
),
)
scipost = factory.Trait(
identifier_w_vn_nr=factory.Faker("numerify", text="scipost_######_#####v#"),
_file=factory.django.FileField(filename="submission.pdf"),
)
__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from django.test import TestCase
from ..factories import PreprintFactory
class TestPreprintFactory(TestCase):
def test_can_create_preprints(self):
preprint = PreprintFactory()
self.assertIsNotNone(preprint)
def test_can_create_arxiv_preprints(self):
preprint = PreprintFactory(arXiv=True)
self.assertIsNotNone(preprint)
self.assertTrue(preprint.url.startswith("https://arxiv.org/abs/"))
def test_can_create_scipost_preprints(self):
preprint = PreprintFactory(scipost=True)
self.assertIsNotNone(preprint)
self.assertTrue(preprint.identifier_w_vn_nr.startswith("scipost_"))
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