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
8afb4164
Commit
8afb4164
authored
1 year ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
Fix tests
parent
3a275179
No related branches found
No related tags found
1 merge request
!56
Feature/comp 233 survey navigation
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
compendium_v2/auth/session_management.py
+11
-10
11 additions, 10 deletions
compendium_v2/auth/session_management.py
compendium_v2/routes/survey.py
+1
-1
1 addition, 1 deletion
compendium_v2/routes/survey.py
test/conftest.py
+7
-0
7 additions, 0 deletions
test/conftest.py
with
19 additions
and
11 deletions
compendium_v2/auth/session_management.py
+
11
−
10
View file @
8afb4164
from
functools
import
wraps
from
functools
import
wraps
from
sqlalchemy
import
select
from
sqlalchemy
import
select
from
flask
import
jsonify
from
flask
import
jsonify
,
current_app
from
datetime
import
datetime
from
datetime
import
datetime
from
flask_login
import
LoginManager
,
current_user
# type: ignore
from
flask_login
import
LoginManager
,
current_user
# type: ignore
from
compendium_v2.db
import
session_scope
from
compendium_v2.db
import
session_scope
...
@@ -16,15 +16,16 @@ def admin_required(func):
...
@@ -16,15 +16,16 @@ def admin_required(func):
"""
"""
def
wrapper
(
*
args
,
**
kwargs
):
def
wrapper
(
*
args
,
**
kwargs
):
if
not
current_user
.
is_authenticated
:
if
not
current_app
.
config
.
get
(
'
LOGIN_DISABLED
'
):
return
jsonify
(
success
=
False
,
if
not
current_user
.
is_authenticated
:
data
=
{
'
login_required
'
:
True
},
return
jsonify
(
success
=
False
,
message
=
'
Authorize to access this page.
'
),
401
data
=
{
'
login_required
'
:
True
},
role
=
current_user
.
roles
message
=
'
Authorize to access this page.
'
),
401
if
role
!=
ROLES
.
admin
:
role
=
current_user
.
roles
return
jsonify
(
success
=
False
,
if
role
!=
ROLES
.
admin
:
data
=
{
'
admin_required
'
:
True
},
return
jsonify
(
success
=
False
,
message
=
'
Admin privileges required to access this page.
'
),
401
data
=
{
'
admin_required
'
:
True
},
message
=
'
Admin privileges required to access this page.
'
),
401
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
...
...
This diff is collapsed.
Click to expand it.
compendium_v2/routes/survey.py
+
1
−
1
View file @
8afb4164
...
@@ -3,7 +3,7 @@ from enum import Enum
...
@@ -3,7 +3,7 @@ from enum import Enum
from
typing
import
Any
,
TypedDict
,
List
,
Dict
from
typing
import
Any
,
TypedDict
,
List
,
Dict
from
flask
import
Blueprint
,
jsonify
,
request
from
flask
import
Blueprint
,
jsonify
,
request
from
flask_login
import
login_required
from
flask_login
import
login_required
# type: ignore
from
sqlalchemy
import
select
from
sqlalchemy
import
select
from
sqlalchemy.orm
import
joinedload
,
load_only
from
sqlalchemy.orm
import
joinedload
,
load_only
...
...
This diff is collapsed.
Click to expand it.
test/conftest.py
+
7
−
0
View file @
8afb4164
...
@@ -3,9 +3,11 @@ import os
...
@@ -3,9 +3,11 @@ import os
import
pytest
import
pytest
import
random
import
random
from
flask_login
import
LoginManager
# type: ignore
import
compendium_v2
import
compendium_v2
from
compendium_v2.db
import
db
,
model
,
survey_model
from
compendium_v2.db
import
db
,
model
,
survey_model
from
compendium_v2.survey_db
import
model
as
survey_db_model
from
compendium_v2.survey_db
import
model
as
survey_db_model
from
compendium_v2.auth.session_management
import
setup_login_manager
def
_test_data_csv
(
filename
):
def
_test_data_csv
(
filename
):
...
@@ -141,6 +143,11 @@ def test_survey_data(app):
...
@@ -141,6 +143,11 @@ def test_survey_data(app):
@pytest.fixture
@pytest.fixture
def
app
(
dummy_config
):
def
app
(
dummy_config
):
app
=
compendium_v2
.
_create_app_with_db
(
dummy_config
)
app
=
compendium_v2
.
_create_app_with_db
(
dummy_config
)
app
.
config
[
'
LOGIN_DISABLED
'
]
=
True
# disable login and admin_required decorators
login_manager
=
LoginManager
()
login_manager
.
init_app
(
app
)
login_manager
.
login_view
=
'
authentication.login
'
setup_login_manager
(
login_manager
)
with
app
.
app_context
():
with
app
.
app_context
():
db
.
create_all
(
bind_key
=
None
)
db
.
create_all
(
bind_key
=
None
)
yield
app
yield
app
...
...
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