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
aa1518dc
Commit
aa1518dc
authored
6 years ago
by
Dan Braghis
Browse files
Options
Downloads
Patches
Plain Diff
Add basic tests
parent
f0d64bf9
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/determinations/tests/factories.py
+39
-0
39 additions, 0 deletions
opentech/apply/determinations/tests/factories.py
opentech/apply/determinations/tests/test_views.py
+105
-0
105 additions, 0 deletions
opentech/apply/determinations/tests/test_views.py
with
144 additions
and
0 deletions
opentech/apply/determinations/tests/factories.py
0 → 100644
+
39
−
0
View file @
aa1518dc
import
factory
from
opentech.apply.funds.tests.factories
import
ApplicationSubmissionFactory
from
..models
import
Determination
,
APPROVED
,
UNDETERMINED
,
UNAPPROVED
from
..views
import
get_form_for_stage
class
DeterminationDataFactory
(
factory
.
DictFactory
):
@classmethod
def
_build
(
cls
,
model_class
,
*
args
,
**
kwargs
):
submission
=
kwargs
.
pop
(
'
submission
'
)
form
=
get_form_for_stage
(
submission
)(
request
=
None
,
submission
=
None
)
form_fields
=
{}
for
field_name
,
field
in
form
.
fields
.
items
():
form_fields
[
field_name
]
=
0
form_fields
.
update
(
**
kwargs
)
return
super
().
_build
(
model_class
,
*
args
,
**
form_fields
)
class
DeterminationFactory
(
factory
.
DjangoModelFactory
):
class
Meta
:
model
=
Determination
class
Params
:
submitted
=
factory
.
Trait
(
determination
=
APPROVED
,
is_draft
=
False
)
approved
=
factory
.
Trait
(
determination
=
APPROVED
)
rejected
=
factory
.
Trait
(
determination
=
UNAPPROVED
)
not_draft
=
factory
.
Trait
(
is_draft
=
False
)
submission
=
factory
.
SubFactory
(
ApplicationSubmissionFactory
)
author
=
factory
.
SelfAttribute
(
'
submission.lead
'
)
determination
=
UNDETERMINED
determination_message
=
factory
.
Faker
(
'
sentence
'
)
determination_data
=
factory
.
Dict
({
'
submission
'
:
factory
.
SelfAttribute
(
'
..submission
'
)},
dict_factory
=
DeterminationDataFactory
)
is_draft
=
True
This diff is collapsed.
Click to expand it.
opentech/apply/determinations/tests/test_views.py
0 → 100644
+
105
−
0
View file @
aa1518dc
from
django.test
import
TestCase
,
RequestFactory
from
django.urls
import
reverse
from
opentech.apply.users.tests.factories
import
StaffFactory
,
UserFactory
from
.factories
import
DeterminationFactory
from
opentech.apply.funds.tests.factories
import
ApplicationSubmissionFactory
class
BaseTestCase
(
TestCase
):
url_name
=
''
user_factory
=
None
def
setUp
(
self
):
self
.
factory
=
RequestFactory
()
self
.
user
=
self
.
user_factory
()
self
.
client
.
force_login
(
self
.
user
)
def
url
(
self
,
instance
,
view_name
=
'
detail
'
):
full_url_name
=
self
.
url_name
.
format
(
view_name
)
url
=
reverse
(
full_url_name
,
kwargs
=
self
.
get_kwargs
(
instance
))
request
=
self
.
factory
.
get
(
url
,
secure
=
True
)
return
request
.
build_absolute_uri
()
def
get_page
(
self
,
instance
,
view_name
=
'
detail
'
):
return
self
.
client
.
get
(
self
.
url
(
instance
,
view_name
),
secure
=
True
,
follow
=
True
)
def
post_page
(
self
,
instance
,
data
,
view_name
=
'
detail
'
):
return
self
.
client
.
post
(
self
.
url
(
instance
,
view_name
),
data
,
secure
=
True
,
follow
=
True
)
def
refresh
(
self
,
instance
):
return
instance
.
__class__
.
objects
.
get
(
id
=
instance
.
id
)
class
StaffDeterminationsTestCase
(
BaseTestCase
):
user_factory
=
StaffFactory
url_name
=
'
funds:submissions:determinations:{}
'
def
get_kwargs
(
self
,
instance
):
return
{
'
pk
'
:
instance
.
id
,
'
submission_pk
'
:
instance
.
submission
.
id
}
def
test_can_access_determination
(
self
):
submission
=
ApplicationSubmissionFactory
(
status
=
'
in_discussion
'
)
determination
=
DeterminationFactory
(
submission
=
submission
,
author
=
self
.
user
,
not_draft
=
True
)
response
=
self
.
get_page
(
determination
)
self
.
assertContains
(
response
,
determination
.
submission
.
title
)
self
.
assertContains
(
response
,
self
.
user
.
full_name
)
self
.
assertContains
(
response
,
reverse
(
'
funds:submissions:detail
'
,
kwargs
=
{
'
pk
'
:
submission
.
id
}))
class
DeterminationFormTestCase
(
BaseTestCase
):
user_factory
=
StaffFactory
url_name
=
'
funds:submissions:determinations:{}
'
def
get_kwargs
(
self
,
instance
):
return
{
'
submission_pk
'
:
instance
.
id
}
def
test_can_access_form_if_lead
(
self
):
submission
=
ApplicationSubmissionFactory
(
status
=
'
in_discussion
'
,
lead
=
self
.
user
)
response
=
self
.
get_page
(
submission
,
'
form
'
)
self
.
assertContains
(
response
,
submission
.
title
)
self
.
assertContains
(
response
,
reverse
(
'
funds:submissions:detail
'
,
kwargs
=
{
'
pk
'
:
submission
.
id
}))
def
test_cannot_access_form_if_not_lead
(
self
):
submission
=
ApplicationSubmissionFactory
(
status
=
'
in_discussion
'
)
response
=
self
.
get_page
(
submission
,
'
form
'
)
self
.
assertContains
(
response
,
submission
.
title
)
self
.
assertContains
(
response
,
reverse
(
'
funds:submissions:detail
'
,
kwargs
=
{
'
pk
'
:
submission
.
id
}))
def
test_cant_access_wrong_status
(
self
):
submission
=
ApplicationSubmissionFactory
()
response
=
self
.
get_page
(
submission
,
'
form
'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_cant_resubmit_determination
(
self
):
submission
=
ApplicationSubmissionFactory
(
status
=
'
in_discussion
'
,
lead
=
self
.
user
)
determination
=
DeterminationFactory
(
submission
=
submission
,
author
=
self
.
user
,
submitted
=
True
)
response
=
self
.
post_page
(
submission
,
{
'
data
'
:
'
value
'
,
'
determination
'
:
determination
.
determination
},
'
form
'
)
self
.
assertTrue
(
response
.
context
[
'
has_determination_response
'
])
self
.
assertContains
(
response
,
'
You have already added a determination for this submission
'
)
def
test_can_edit_draft_determination
(
self
):
submission
=
ApplicationSubmissionFactory
(
status
=
'
in_discussion
'
,
lead
=
self
.
user
)
determination
=
DeterminationFactory
(
submission
=
submission
,
author
=
self
.
user
)
response
=
self
.
post_page
(
submission
,
{
'
data
'
:
'
value
'
,
'
determination
'
:
determination
.
determination
},
'
form
'
)
self
.
assertFalse
(
response
.
context
[
'
has_determination_response
'
])
self
.
assertEqual
(
response
.
context
[
'
title
'
],
'
Update Determination draft
'
)
def
test_cannot_edit_draft_determination_if_not_lead
(
self
):
submission
=
ApplicationSubmissionFactory
(
status
=
'
in_discussion
'
)
determination
=
DeterminationFactory
(
submission
=
submission
,
author
=
self
.
user
)
response
=
self
.
post_page
(
submission
,
{
'
data
'
:
'
value
'
,
'
determination
'
:
determination
.
determination
},
'
form
'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
class
UserDeterminationFormTestCase
(
BaseTestCase
):
user_factory
=
UserFactory
url_name
=
'
funds:submissions:determinations:{}
'
def
get_kwargs
(
self
,
instance
):
return
{
'
submission_pk
'
:
instance
.
id
}
def
test_cant_access_form
(
self
):
submission
=
ApplicationSubmissionFactory
(
status
=
'
in_discussion
'
)
response
=
self
.
get_page
(
submission
,
'
form
'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
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