SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SciPost
SciPost
Commits
2dfc33a3
Commit
2dfc33a3
authored
1 year ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
add factories for all theses models
parent
00e14b8b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scipost_django/theses/factories.py
+6
-24
6 additions, 24 deletions
scipost_django/theses/factories.py
scipost_django/theses/tests/test_factories.py
+11
-0
11 additions, 0 deletions
scipost_django/theses/tests/test_factories.py
with
17 additions
and
24 deletions
scipost_django/theses/factories.py
+
6
−
24
View file @
2dfc33a3
...
@@ -9,10 +9,12 @@ from ontology.models import AcademicField, Specialty
...
@@ -9,10 +9,12 @@ from ontology.models import AcademicField, Specialty
from
scipost.constants
import
SCIPOST_APPROACHES
from
scipost.constants
import
SCIPOST_APPROACHES
from
scipost.models
import
Contributor
from
scipost.models
import
Contributor
from
.models
import
ThesisLink
from
.models
import
*
from
.forms
import
VetThesisLinkForm
from
.forms
import
VetThesisLinkForm
from
.constants
import
THESIS_TYPES
from
.constants
import
THESIS_TYPES
from
common.faker
import
LazyRandEnum
,
fake
class
BaseThesisLinkFactory
(
factory
.
django
.
DjangoModelFactory
):
class
BaseThesisLinkFactory
(
factory
.
django
.
DjangoModelFactory
):
class
Meta
:
class
Meta
:
...
@@ -23,34 +25,17 @@ class BaseThesisLinkFactory(factory.django.DjangoModelFactory):
...
@@ -23,34 +25,17 @@ class BaseThesisLinkFactory(factory.django.DjangoModelFactory):
vetted_by
=
factory
.
SubFactory
(
"
scipost.factories.ContributorFactory
"
)
vetted_by
=
factory
.
SubFactory
(
"
scipost.factories.ContributorFactory
"
)
vetted
=
True
vetted
=
True
type
=
factory
.
Iterator
(
THESIS_TYPES
,
getter
=
lambda
c
:
c
[
0
]
)
type
=
LazyRandEnum
(
THESIS_TYPES
)
acad_field
=
factory
.
SubFactory
(
"
ontology.factories.AcademicFieldFactory
"
)
acad_field
=
factory
.
SubFactory
(
"
ontology.factories.AcademicFieldFactory
"
)
approaches
=
factory
.
Iterator
(
approaches
=
LazyRandEnum
(
SCIPOST_APPROACHES
,
repeat
=
2
)
SCIPOST_APPROACHES
,
getter
=
lambda
c
:
[
c
[
0
],
],
)
title
=
factory
.
Faker
(
"
sentence
"
)
title
=
factory
.
Faker
(
"
sentence
"
)
pub_link
=
factory
.
Faker
(
"
uri
"
)
pub_link
=
factory
.
Faker
(
"
uri
"
)
author
=
factory
.
Faker
(
"
name
"
)
author
=
factory
.
Faker
(
"
name
"
)
supervisor
=
factory
.
Faker
(
"
name
"
)
supervisor
=
factory
.
Faker
(
"
name
"
)
institution
=
factory
.
Faker
(
"
company
"
)
institution
=
factory
.
Faker
(
"
company
"
)
defense_date
=
fa
ctory
.
Faker
(
"
date_this_decade
"
)
defense_date
=
fa
ke
.
aware
.
date_this_decade
(
)
abstract
=
factory
.
Faker
(
"
paragraph
"
)
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
@factory.post_generation
def
add_specialties
(
self
,
create
,
extracted
,
**
kwargs
):
def
add_specialties
(
self
,
create
,
extracted
,
**
kwargs
):
if
create
:
if
create
:
...
@@ -66,9 +51,6 @@ class BaseThesisLinkFactory(factory.django.DjangoModelFactory):
...
@@ -66,9 +51,6 @@ class BaseThesisLinkFactory(factory.django.DjangoModelFactory):
# A list of groups were passed in, use them
# A list of groups were passed in, use them
for
contributor
in
extracted
:
for
contributor
in
extracted
:
self
.
author_as_cont
.
add
(
contributor
)
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
):
class
ThesisLinkFactory
(
BaseThesisLinkFactory
):
...
...
This diff is collapsed.
Click to expand it.
scipost_django/theses/tests/test_factories.py
0 → 100644
+
11
−
0
View file @
2dfc33a3
__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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment