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
eb8f0bd2
Commit
eb8f0bd2
authored
6 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
GH-858: Add tests to cover posting data
parent
2987f0f0
No related branches found
Branches containing commit
Tags
v1.34.5
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/views/test_batch_progress.py
+110
-0
110 additions, 0 deletions
opentech/apply/funds/tests/views/test_batch_progress.py
opentech/apply/utils/views.py
+4
-1
4 additions, 1 deletion
opentech/apply/utils/views.py
with
114 additions
and
1 deletion
opentech/apply/funds/tests/views/test_batch_progress.py
0 → 100644
+
110
−
0
View file @
eb8f0bd2
from
unittest
import
mock
from
opentech.apply.funds.models
import
ApplicationSubmission
from
opentech.apply.funds.tests.factories
import
(
ApplicationSubmissionFactory
,
InvitedToProposalFactory
,
)
from
opentech.apply.users.tests.factories
import
(
ReviewerFactory
,
StaffFactory
,
UserFactory
,
)
from
opentech.apply.utils.testing.tests
import
BaseViewTestCase
class
BaseBatchProgressViewTestCase
(
BaseViewTestCase
):
url_name
=
'
funds:submissions:{}
'
base_view_name
=
'
list
'
def
data
(
self
,
action
,
submissions
):
return
{
'
form-submitted-batch_progress_form
'
:
'
Update
'
,
'
action
'
:
action
,
'
submissions
'
:
'
,
'
.
join
([
str
(
submission
.
id
)
for
submission
in
submissions
]),
}
class
StaffTestCase
(
BaseBatchProgressViewTestCase
):
user_factory
=
StaffFactory
def
test_can_progress_application
(
self
):
submission
=
ApplicationSubmissionFactory
()
action
=
'
open-review
'
self
.
post_page
(
data
=
self
.
data
(
action
,
[
submission
]))
submission
=
self
.
refresh
(
submission
)
self
.
assertEqual
(
submission
.
status
,
'
internal_review
'
)
def
test_can_progress_multiple_applications
(
self
):
submissions
=
ApplicationSubmissionFactory
.
create_batch
(
3
)
action
=
'
open-review
'
self
.
post_page
(
data
=
self
.
data
(
action
,
submissions
))
self
.
assertCountEqual
(
[
self
.
refresh
(
submission
).
status
for
submission
in
submissions
],
[
'
internal_review
'
]
*
3
,
)
def
test_cant_progress_in_incorrect_state
(
self
):
submission
=
ApplicationSubmissionFactory
()
action
=
'
close-review
'
self
.
post_page
(
data
=
self
.
data
(
action
,
[
submission
]))
submission
=
self
.
refresh
(
submission
)
self
.
assertEqual
(
submission
.
status
,
'
in_discussion
'
)
def
test_can_progress_one_in_mixed_state
(
self
):
bad_submission
=
ApplicationSubmissionFactory
()
good_submission
=
ApplicationSubmissionFactory
(
status
=
'
internal_review
'
)
action
=
'
close-review
'
self
.
post_page
(
data
=
self
.
data
(
action
,
[
good_submission
,
bad_submission
]))
good_submission
=
self
.
refresh
(
good_submission
)
bad_submission
=
self
.
refresh
(
bad_submission
)
self
.
assertEqual
(
bad_submission
.
status
,
'
in_discussion
'
)
self
.
assertEqual
(
good_submission
.
status
,
'
post_review_discussion
'
)
def
test_can_progress_different_states
(
self
):
submission
=
ApplicationSubmissionFactory
()
other_submission
=
InvitedToProposalFactory
()
action
=
'
open-review
'
self
.
post_page
(
data
=
self
.
data
(
action
,
[
submission
,
other_submission
]))
submission
=
self
.
refresh
(
submission
)
other_submission
=
self
.
refresh
(
other_submission
)
self
.
assertEqual
(
submission
.
status
,
'
internal_review
'
)
self
.
assertEqual
(
other_submission
.
status
,
'
proposal_internal_review
'
)
@mock.patch
(
'
opentech.apply.funds.views.messenger
'
)
def
test_messenger_not_called_with_failed
(
self
,
patched
):
submission
=
ApplicationSubmissionFactory
()
action
=
'
close-review
'
self
.
post_page
(
data
=
self
.
data
(
action
,
[
submission
]))
patched
.
assert_called_once
()
_
,
_
,
kwargs
=
patched
.
mock_calls
[
0
]
self
.
assertQuerysetEqual
(
kwargs
[
'
submissions
'
],
ApplicationSubmission
.
objects
.
none
())
@mock.patch
(
'
opentech.apply.funds.views.messenger
'
)
def
test_messenger_with_submission_in_review
(
self
,
patched
):
submission
=
ApplicationSubmissionFactory
()
action
=
'
open-review
'
self
.
post_page
(
data
=
self
.
data
(
action
,
[
submission
]))
self
.
assertEqual
(
patched
.
call_count
,
2
)
_
,
_
,
kwargs
=
patched
.
mock_calls
[
0
]
self
.
assertCountEqual
(
kwargs
[
'
submissions
'
],
[
submission
])
_
,
_
,
kwargs
=
patched
.
mock_calls
[
1
]
self
.
assertCountEqual
(
kwargs
[
'
submissions
'
],
[
submission
])
class
ReivewersTestCase
(
BaseBatchProgressViewTestCase
):
user_factory
=
ReviewerFactory
def
test_cant_post_to_page
(
self
):
response
=
self
.
post_page
()
self
.
assertEqual
(
response
.
status_code
,
405
)
class
ApplicantTestCase
(
BaseBatchProgressViewTestCase
):
user_factory
=
UserFactory
def
test_cant_access_page_to_page
(
self
):
response
=
self
.
post_page
()
self
.
assertEqual
(
response
.
status_code
,
403
)
This diff is collapsed.
Click to expand it.
opentech/apply/utils/views.py
+
4
−
1
View file @
eb8f0bd2
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.decorators
import
login_required
from
django.forms.models
import
ModelForm
from
django.forms.models
import
ModelForm
from
django.http
import
HttpResponseForbidden
from
django.utils.decorators
import
method_decorator
from
django.utils.decorators
import
method_decorator
from
django.views
import
defaults
from
django.views
import
defaults
from
django.views.generic
import
View
from
django.views.generic
import
View
...
@@ -34,7 +35,9 @@ class ViewDispatcher(View):
...
@@ -34,7 +35,9 @@ class ViewDispatcher(View):
elif
self
.
reviewer_check
(
request
):
elif
self
.
reviewer_check
(
request
):
view
=
self
.
reviewer_view
view
=
self
.
reviewer_view
return
view
.
as_view
()(
request
,
*
args
,
**
kwargs
)
if
view
:
return
view
.
as_view
()(
request
,
*
args
,
**
kwargs
)
return
HttpResponseForbidden
()
class
DelegatableBase
(
ContextMixin
):
class
DelegatableBase
(
ContextMixin
):
...
...
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