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
fc441de9
Commit
fc441de9
authored
1 year ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
add factories for all profiles models
parent
63edeb8c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scipost_django/profiles/factories.py
+75
-3
75 additions, 3 deletions
scipost_django/profiles/factories.py
scipost_django/profiles/tests/test_factories.py
+29
-0
29 additions, 0 deletions
scipost_django/profiles/tests/test_factories.py
with
104 additions
and
3 deletions
scipost_django/profiles/factories.py
+
75
−
3
View file @
fc441de9
...
...
@@ -2,17 +2,89 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__
=
"
AGPL v3
"
import
random
import
factory
from
common.faker
import
LazyRandEnum
from
common.faker
import
LazyRandEnum
,
fake
from
ontology.factories
import
SpecialtyFactory
,
TopicFactory
from
profiles.constants
import
AFFILIATION_CATEGORIES
,
PROFILE_NON_DUPLICATE_REASONS
from
scipost.constants
import
TITLE_CHOICES
from
.models
import
Profile
from
.models
import
*
class
ProfileFactory
(
factory
.
django
.
DjangoModelFactory
):
class
Meta
:
model
=
Profile
django_get_or_create
=
(
"
orcid_id
"
,)
title
=
LazyRandEnum
(
TITLE_CHOICES
)
first_name
=
factory
.
Faker
(
"
first_name
"
)
last_name
=
factory
.
Faker
(
"
last_name
"
)
orcid_id
=
factory
.
Faker
(
"
numerify
"
,
text
=
"
####-####-####-####
"
)
webpage
=
factory
.
Faker
(
"
url
"
)
acad_field
=
factory
.
SubFactory
(
"
ontology.factories.AcademicFieldFactory
"
)
@factory.post_generation
def
specialties
(
self
,
create
,
extracted
,
**
kwargs
):
if
not
create
:
return
if
extracted
:
for
specialty
in
extracted
:
self
.
specialties
.
add
(
specialty
)
else
:
self
.
specialties
.
add
(
*
SpecialtyFactory
.
create_batch
(
random
.
randint
(
1
,
3
),
acad_field
=
self
.
acad_field
)
)
@factory.post_generation
def
topics
(
self
,
create
,
extracted
,
**
kwargs
):
if
not
create
:
return
if
extracted
:
for
topic
in
extracted
:
self
.
topics
.
add
(
topic
)
else
:
self
.
topics
.
add
(
*
TopicFactory
.
create_batch
(
random
.
randint
(
1
,
3
)))
class
ProfileNonDuplicatesFactory
(
factory
.
django
.
DjangoModelFactory
):
class
Meta
:
model
=
Profile
model
=
ProfileNonDuplicates
reason
=
LazyRandEnum
(
PROFILE_NON_DUPLICATE_REASONS
)
@factory.post_generation
def
profiles
(
self
,
create
,
extracted
,
**
kwargs
):
if
not
create
:
return
if
extracted
:
for
profile
in
extracted
:
self
.
profiles
.
add
(
profile
)
else
:
self
.
profiles
.
add
(
*
ProfileFactory
.
create_batch
(
random
.
randint
(
1
,
3
)))
class
ProfileEmailFactory
(
factory
.
django
.
DjangoModelFactory
):
class
Meta
:
model
=
ProfileEmail
profile
=
factory
.
SubFactory
(
ProfileFactory
)
email
=
factory
.
Faker
(
"
email
"
)
class
AffiliationFactory
(
factory
.
django
.
DjangoModelFactory
):
class
Meta
:
model
=
Affiliation
profile
=
factory
.
SubFactory
(
ProfileFactory
)
organization
=
factory
.
SubFactory
(
"
organizations.factories.OrganizationFactory
"
)
category
=
LazyRandEnum
(
AFFILIATION_CATEGORIES
)
description
=
factory
.
Faker
(
"
sentence
"
)
date_from
=
factory
.
Faker
(
"
date_this_decade
"
)
date_until
=
factory
.
LazyAttribute
(
lambda
self
:
fake
.
aware
.
date_between
(
start_date
=
self
.
date_from
,
end_date
=
"
+1y
"
)
)
This diff is collapsed.
Click to expand it.
scipost_django/profiles/tests/test_factories.py
0 → 100644
+
29
−
0
View file @
fc441de9
__copyright__
=
"
Copyright © Stichting SciPost (SciPost Foundation)
"
__license__
=
"
AGPL v3
"
from
django.test
import
TestCase
from
..factories
import
*
class
TestProfileFactory
(
TestCase
):
def
test_can_create_profiles
(
self
):
profile
=
ProfileFactory
()
self
.
assertIsNotNone
(
profile
)
class
TestProfileNonDuplicatesFactory
(
TestCase
):
def
test_can_create_profile_non_duplicates
(
self
):
profile_non_duplicate
=
ProfileNonDuplicatesFactory
()
self
.
assertIsNotNone
(
profile_non_duplicate
)
class
TestProfileEmailFactory
(
TestCase
):
def
test_can_create_profile_emails
(
self
):
profile_email
=
ProfileEmailFactory
()
self
.
assertIsNotNone
(
profile_email
)
class
TestAffiliationFactory
(
TestCase
):
def
test_can_create_affiliations
(
self
):
affiliation
=
AffiliationFactory
()
self
.
assertIsNotNone
(
affiliation
)
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