Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
AURA
steering
Commits
743dbeaf
Verified
Commit
743dbeaf
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
test: add factories for Notes & Users with Permissions
parent
4a46eeb8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/tests/factories.py
+29
-2
29 additions, 2 deletions
program/tests/factories.py
with
29 additions
and
2 deletions
program/tests/factories.py
+
29
−
2
View file @
743dbeaf
from
datetime
import
timedelta
from
factory
import
Sequence
from
factory
import
Sequence
,
post_generation
from
factory.django
import
DjangoModelFactory
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
Permission
,
User
from
django.db.models
import
QuerySet
from
django.utils.timezone
import
now
from
program.models
import
(
FundingCategory
,
Host
,
Image
,
License
,
Note
,
RRule
,
Schedule
,
Show
,
...
...
@@ -26,6 +28,26 @@ class CommonUserFactory(DjangoModelFactory):
username
=
Sequence
(
lambda
n
:
"
common_%d
"
%
n
)
class
UserWithPermissionsFactory
(
DjangoModelFactory
):
class
Meta
:
model
=
User
username
=
Sequence
(
lambda
n
:
"
user_with_perm%d
"
%
n
)
@post_generation
def
user_permissions
(
self
,
create
,
extracted
,
**
kwargs
):
if
not
create
:
return
if
extracted
:
if
isinstance
(
extracted
,
Permission
):
self
.
user_permissions
.
add
(
extracted
)
if
isinstance
(
extracted
,
QuerySet
):
for
permission
in
extracted
:
self
.
user_permissions
.
add
(
permission
)
class
HostFactory
(
DjangoModelFactory
):
class
Meta
:
model
=
Host
...
...
@@ -90,3 +112,8 @@ class LicenseFactory(DjangoModelFactory):
identifier
=
"
pd
"
name
=
"
Public Domain
"
class
NoteFactory
(
DjangoModelFactory
):
class
Meta
:
model
=
Note
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