Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GraceDB Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Michael William Coughlin
GraceDB Server
Commits
a1b8582c
Commit
a1b8582c
authored
5 years ago
by
Tanner Prestegard
Committed by
GraceDB
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests for pipeline manage/enable/disable views
parent
8f8c6289
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gracedb/events/tests/test_views.py
+79
-0
79 additions, 0 deletions
gracedb/events/tests/test_views.py
with
79 additions
and
0 deletions
gracedb/events/tests/test_views.py
0 → 100644
+
79
−
0
View file @
a1b8582c
try
:
from
unittest
import
mock
except
ImportError
:
# python < 3
import
mock
import
pytest
from
django.urls
import
reverse
from
events.models
import
Pipeline
from
events.views
import
PipelineManageView
@pytest.mark.django_db
def
test_pipeline_manage_view
(
standard_user
,
client
):
"""
Test pipeline manage view as various classes of non-advocate user
"""
if
not
standard_user
.
is_anonymous
:
client
.
force_login
(
standard_user
)
response
=
client
.
get
(
reverse
(
'
manage-pipelines
'
))
# Expected response code by user
response_dict
=
{
'
internal.user
'
:
200
,
''
:
403
,
}
assert
response
.
status_code
==
response_dict
[
standard_user
.
username
]
# Check context
if
response
==
200
:
assert
response
.
context
[
'
user_can_manage
'
]
==
False
def
test_pipeline_manage_view_as_advocate
(
em_advocate_user
,
client
):
"""
Test pipeline manage view as EM advocate
"""
client
.
force_login
(
em_advocate_user
)
response
=
client
.
get
(
reverse
(
'
manage-pipelines
'
))
# Expected response code
assert
response
.
status_code
==
200
# Check context
assert
response
.
context
[
'
user_can_manage
'
]
==
True
@pytest.mark.parametrize
(
"
view
"
,
[
'
enable-pipeline
'
,
'
disable-pipeline
'
])
@pytest.mark.django_db
def
test_pipeline_change_views
(
view
,
standard_user
,
client
):
"""
Test pipeline enable/disable views as various classes of non-advocate user
"""
if
not
standard_user
.
is_anonymous
:
client
.
force_login
(
standard_user
)
# Create a pipeline
p
,
_
=
Pipeline
.
objects
.
get_or_create
(
name
=
'
fake_pipeline
'
)
# NOTE: get() is wired to post() in the view
response
=
client
.
get
(
reverse
(
view
,
args
=
[
p
.
pk
]))
assert
response
.
status_code
==
403
@pytest.mark.parametrize
(
"
view
"
,
[
'
enable-pipeline
'
,
'
disable-pipeline
'
])
@pytest.mark.django_db
def
test_pipeline_change_views_as_advocate
(
view
,
em_advocate_user
,
client
):
"""
Test pipeline enable/disable views as various classes of non-advocate user
"""
client
.
force_login
(
em_advocate_user
)
# Create a pipeline
p
,
_
=
Pipeline
.
objects
.
get_or_create
(
name
=
'
fake_pipeline
'
)
# NOTE: get() is wired to post() in the view
with
mock
.
patch
(
'
events.views.PIPELINE_LIST
'
,
new_callable
=
list
)
\
as
mock_pipeline_list
:
mock_pipeline_list
.
append
(
p
.
name
)
response
=
client
.
get
(
reverse
(
view
,
args
=
[
p
.
pk
]))
assert
response
.
status_code
==
302
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