Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
ots
hypha
Commits
0c9c7b98
Commit
0c9c7b98
authored
7 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
Add a factory to build the submission
parent
f8e67ffe
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
opentech/apply/funds/tests/factories/models.py
+48
-4
48 additions, 4 deletions
opentech/apply/funds/tests/factories/models.py
opentech/apply/funds/tests/test_models.py
+8
-0
8 additions, 0 deletions
opentech/apply/funds/tests/test_models.py
with
56 additions
and
4 deletions
opentech/apply/funds/tests/factories/models.py
+
48
−
4
View file @
0c9c7b98
...
...
@@ -5,6 +5,7 @@ import wagtail_factories
from
opentech.apply.funds.models
import
(
AbstractRelatedForm
,
ApplicationSubmission
,
ApplicationForm
,
FundType
,
FundForm
,
...
...
@@ -23,6 +24,7 @@ __all__ = [
'
FundTypeFactory
'
,
'
FundFormFactory
'
,
'
ApplicationFormFactory
'
,
'
ApplicationSubmissionFactory
'
,
'
RoundFactory
'
,
'
RoundFormFactory
'
,
'
LabFactory
'
,
...
...
@@ -30,6 +32,15 @@ __all__ = [
]
def
build_form
(
prefix
=
''
):
if
prefix
:
prefix
+=
'
__
'
return
{
f
'
{
prefix
}
form_fields__
{
i
}
__
{
field
}
__
'
:
''
for
i
,
field
in
enumerate
(
blocks
.
CustomFormFieldsFactory
.
factories
.
keys
())
}
class
FundTypeFactory
(
wagtail_factories
.
PageFactory
):
class
Meta
:
model
=
FundType
...
...
@@ -43,10 +54,7 @@ class FundTypeFactory(wagtail_factories.PageFactory):
@factory.post_generation
def
forms
(
self
,
create
,
extracted
,
**
kwargs
):
if
create
:
fields
=
{
f
'
form__form_fields__
{
i
}
__
{
field
}
__
'
:
''
for
i
,
field
in
enumerate
(
blocks
.
CustomFormFieldsFactory
.
factories
.
keys
())
}
fields
=
build_form
(
prefix
=
'
form
'
)
fields
.
update
(
**
kwargs
)
for
_
in
range
(
len
(
self
.
workflow_class
.
stage_classes
)):
# Generate a form based on all defined fields on the model
...
...
@@ -109,3 +117,39 @@ class LabFormFactory(AbstractRelatedFormFactory):
class
Meta
:
model
=
LabForm
lab
=
factory
.
SubFactory
(
LabFactory
,
parent
=
None
)
class
ApplicationSubmissionFactory
(
factory
.
DjangoModelFactory
):
class
Meta
:
model
=
ApplicationSubmission
form_fields
=
blocks
.
CustomFormFieldsFactory
page
=
factory
.
SubFactory
(
FundTypeFactory
)
round
=
factory
.
SubFactory
(
RoundFactory
)
@classmethod
def
_generate
(
cls
,
strat
,
params
):
params
.
update
(
**
build_form
())
return
super
().
_generate
(
strat
,
params
)
@classmethod
def
_create
(
cls
,
model
,
*
args
,
**
kwargs
):
# Make sure we have form_data so no error
kwargs
[
'
form_data
'
]
=
{}
return
super
().
_create
(
model
,
*
args
,
**
kwargs
)
@factory.post_generation
def
form_data
(
self
,
create
,
extracted
,
**
kwargs
):
if
not
extracted
:
# Ids are added but are not available in the cached version
self
.
refresh_from_db
()
form_data
=
{}
for
field
in
self
.
form_fields
:
try
:
answer
=
kwargs
[
field
.
block_type
]
except
KeyError
:
answer
=
''
form_data
[
field
.
id
]
=
answer
self
.
form_data
=
form_data
self
.
save
()
This diff is collapsed.
Click to expand it.
opentech/apply/funds/tests/test_models.py
+
8
−
0
View file @
0c9c7b98
...
...
@@ -14,6 +14,7 @@ from opentech.apply.funds.workflow import SingleStage
from
.factories
import
(
ApplicationFormFactory
,
ApplicationSubmissionFactory
,
CustomFormFieldsFactory
,
FundTypeFactory
,
LabFactory
,
...
...
@@ -311,3 +312,10 @@ class TestFormSubmission(TestCase):
# "Thank you for your submission" and "Account Creation"
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
self
.
assertEqual
(
mail
.
outbox
[
0
].
to
[
0
],
self
.
email
)
class
TestApplicationSubmission
(
TestCase
):
def
test_can_get_required_block_names
(
self
):
email
=
'
test@test.com
'
submission
=
ApplicationSubmissionFactory
(
form_data__email
=
email
)
self
.
assertEqual
(
submission
.
email
,
email
)
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