Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
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
geant-swd
compendium-v2
Commits
aa356de6
Commit
aa356de6
authored
1 year ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
Test observer functionality in API
parent
77af5cd9
No related branches found
No related tags found
1 merge request
!76
Comp 282 add observer role
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/conftest.py
+13
-0
13 additions, 0 deletions
test/conftest.py
test/test_response.py
+30
-0
30 additions, 0 deletions
test/test_response.py
with
43 additions
and
0 deletions
test/conftest.py
+
13
−
0
View file @
aa356de6
...
@@ -57,6 +57,19 @@ def mocked_user(app, test_survey_data, mocker):
...
@@ -57,6 +57,19 @@ def mocked_user(app, test_survey_data, mocker):
yield
user
yield
user
@pytest.fixture
def
mocked_observer_user
(
app
,
test_survey_data
,
mocker
):
with
app
.
app_context
():
user
=
User
(
email
=
'
observer123@email.local
'
,
fullname
=
'
observerfullname
'
,
oidc_sub
=
'
fakesub
'
,
roles
=
ROLES
.
observer
)
db
.
session
.
add
(
user
)
def
user_loader
(
*
args
):
return
user
mocker
.
patch
(
'
flask_login.utils._get_user
'
,
user_loader
)
@pytest.fixture
@pytest.fixture
def
test_budget_data
(
app
):
def
test_budget_data
(
app
):
with
app
.
app_context
():
with
app
.
app_context
():
...
...
This diff is collapsed.
Click to expand it.
test/test_response.py
+
30
−
0
View file @
aa356de6
...
@@ -158,3 +158,33 @@ def test_response_route_lock_prevents_other_edits(app, mocker, client, test_surv
...
@@ -158,3 +158,33 @@ def test_response_route_lock_prevents_other_edits(app, mocker, client, test_surv
assert
rv
.
status_code
==
403
assert
rv
.
status_code
==
403
result
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
result
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
assert
result
.
get
(
'
message
'
)
==
'
This survey is already locked.
'
assert
result
.
get
(
'
message
'
)
==
'
This survey is already locked.
'
def
test_response_routes_observer
(
app
,
client
,
test_survey_data
,
mocked_observer_user
):
# observers should not be able to modify surveys, but should be able to view all of them
rv
=
client
.
get
(
'
/api/survey/list
'
,
headers
=
{
'
Accept
'
:
[
'
application/json
'
]})
assert
rv
.
status_code
==
200
surveys
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
assert
surveys
# load the first survey and check that the observer can view it
rv
=
client
.
get
(
f
'
/api/response/load/
{
surveys
[
0
][
"
year
"
]
}
/nren1
'
,
headers
=
{
'
Accept
'
:
[
'
application/json
'
]})
assert
rv
.
status_code
==
200
# try to lock the first survey and check that the observer can't
rv
=
client
.
post
(
f
'
/api/response/lock/
{
surveys
[
0
][
"
year
"
]
}
/nren1
'
,
headers
=
{
'
Accept
'
:
[
'
application/json
'
]})
assert
rv
.
status_code
==
403
# try to save the first survey and check that the observer can't
rv
=
client
.
post
(
f
'
/api/response/save/
{
surveys
[
0
][
"
year
"
]
}
/nren1
'
,
headers
=
{
'
Accept
'
:
[
'
application/json
'
]})
assert
rv
.
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