Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mentat Test 3
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
Mentat Test 3
Commits
b29f7a50
Commit
b29f7a50
authored
4 years ago
by
Jan Mach
Browse files
Options
Downloads
Patches
Plain Diff
Implemented unit tests for 'hawat.blueprints.changelogs' module.
Also removed unnecessary docstrings. (Redmine issue:
#4410
,
#1017
,
#3443
)
parent
1720b061
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
lib/hawat/blueprints/changelogs/__init__.py
+1
-41
1 addition, 41 deletions
lib/hawat/blueprints/changelogs/__init__.py
lib/hawat/blueprints/changelogs/test/__init__.py
+65
-0
65 additions, 0 deletions
lib/hawat/blueprints/changelogs/test/__init__.py
with
66 additions
and
41 deletions
lib/hawat/blueprints/changelogs/__init__.py
+
1
−
41
View file @
b29f7a50
...
...
@@ -9,9 +9,6 @@
"""
Description
-----------
This pluggable module provides access to item changelogs.
"""
...
...
@@ -20,15 +17,9 @@ __author__ = "Jan Mach <jan.mach@cesnet.cz>"
__credits__
=
"
Pavel Kácha <pavel.kacha@cesnet.cz>, Andrea Kropáčová <andrea.kropacova@cesnet.cz>
"
#
# Flask related modules.
#
import
flask
from
flask_babel
import
lazy_gettext
#
# Custom modules.
#
from
mentat.datatype.sqldb
import
ItemChangeLogModel
import
vial.acl
...
...
@@ -54,33 +45,24 @@ class SearchView(HTMLMixin, SQLAlchemyMixin, BaseSearchView): # pylint: disable
@classmethod
def
get_menu_title
(
cls
,
**
kwargs
):
"""
*Implementation* of :py:func:`vial.view.BaseView.get_menu_title`.
"""
return
lazy_gettext
(
'
Changelogs
'
)
@classmethod
def
get_view_title
(
cls
,
**
kwargs
):
"""
*Implementation* of :py:func:`vial.view.BaseView.get_view_title`.
"""
return
lazy_gettext
(
'
Search item changelogs
'
)
#---------------------------------------------------------------------------
@property
def
dbmodel
(
self
):
"""
*Implementation* of :py:func:`vial.view.mixin.SQLAlchemyMixin.dbmodel`.
"""
return
ItemChangeLogModel
@staticmethod
def
get_search_form
(
request_args
):
"""
*Interface implementation* of :py:func:`vial.view.BaseSearchView.get_search_form`.
"""
return
ItemChangeLogSearchForm
(
request_args
,
meta
=
{
'
csrf
'
:
False
})
@staticmethod
def
build_query
(
query
,
model
,
form_args
):
"""
*Interface implementation* of :py:func:`vial.view.BaseSearchView.build_query`.
"""
# Adjust query based on lower time boudary selection.
if
'
dt_from
'
in
form_args
and
form_args
[
'
dt_from
'
]:
query
=
query
.
filter
(
model
.
createtime
>=
form_args
[
'
dt_from
'
])
...
...
@@ -106,7 +88,6 @@ class SearchView(HTMLMixin, SQLAlchemyMixin, BaseSearchView): # pylint: disable
@classmethod
def
get_context_action_menu
(
cls
):
"""
*Implementation* of :py:func:`vial.view.ItemListView.get_context_action_menu`.
"""
context_action_menu
=
super
().
get_context_action_menu
()
context_action_menu
.
add_entry
(
'
submenu
'
,
...
...
@@ -156,33 +137,24 @@ class ShowView(HTMLMixin, SQLAlchemyMixin, ItemShowView):
@classmethod
def
get_menu_title
(
cls
,
**
kwargs
):
"""
*Implementation* of :py:func:`vial.view.BaseView.get_menu_title`.
"""
return
lazy_gettext
(
'
Show item changelog record
'
)
@classmethod
def
get_menu_legend
(
cls
,
**
kwargs
):
"""
*Interface implementation* of :py:func:`vial.view.BaseView.get_menu_legend`.
"""
return
lazy_gettext
(
'
View details of item changelog record "%(item)s"
'
,
item
=
str
(
kwargs
[
'
item
'
]))
@classmethod
def
get_view_title
(
cls
,
**
kwargs
):
"""
*Implementation* of :py:func:`vial.view.BaseView.get_view_title`.
"""
return
lazy_gettext
(
'
Show item changelog record details
'
)
#---------------------------------------------------------------------------
@property
def
dbmodel
(
self
):
"""
*Implementation* of :py:func:`vial.view.mixin.SQLAlchemyMixin.dbmodel`.
"""
return
ItemChangeLogModel
@classmethod
def
get_breadcrumbs_menu
(
cls
):
# pylint: disable=locally-disabled,unused-argument
"""
Get breadcrumbs menu.
"""
action_menu
=
vial
.
menu
.
Menu
()
action_menu
.
add_entry
(
'
endpoint
'
,
...
...
@@ -206,25 +178,13 @@ class ShowView(HTMLMixin, SQLAlchemyMixin, ItemShowView):
class
ItemChangeLogsBlueprint
(
VialBlueprint
):
"""
Hawat pluggable module - changelogs.
"""
"""
Pluggable module - changelogs.
"""
@classmethod
def
get_module_title
(
cls
):
"""
*Implementation* of :py:func:`vial.app.VialBlueprint.get_module_title`.
"""
return
lazy_gettext
(
'
Item changelog record pluggable module
'
)
def
register_app
(
self
,
app
):
"""
*Callback method*. Will be called from :py:func:`hawat.base.HawatApp.register_blueprint`
method and can be used to customize the Flask application object. Possible
use cases:
* application menu customization
:param hawat.base.HawatApp app: Flask application to be customized.
"""
app
.
menu_main
.
add_entry
(
'
view
'
,
'
admin.{}
'
.
format
(
BLUEPRINT_NAME
),
...
...
This diff is collapsed.
Click to expand it.
lib/hawat/blueprints/changelogs/test/__init__.py
0 → 100644
+
65
−
0
View file @
b29f7a50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# This file is part of Mentat system (https://mentat.cesnet.cz/).
#
# Copyright (C) since 2011 CESNET, z.s.p.o (http://www.ces.net/)
# Use of this source is governed by the MIT license, see LICENSE file.
#-------------------------------------------------------------------------------
"""
Unit tests for :py:mod:`hawat.blueprints.changelogs`.
"""
import
unittest
import
vial.const
import
vial.test
import
vial.db
from
hawat.test
import
BaseAppTestCase
class
ChangeLogsSearchTestCase
(
BaseAppTestCase
):
"""
Class for testing ``changelogs.search`` endpoint.
"""
def
_attempt_fail
(
self
):
self
.
assertGetURL
(
'
/changelogs/search
'
,
403
)
def
_attempt_succeed
(
self
):
self
.
assertGetURL
(
'
/changelogs/search
'
,
200
)
@vial.test.do_as_user_decorator
(
vial
.
const
.
ROLE_USER
)
def
test_01_as_user
(
self
):
"""
Test access as user ``user``.
"""
self
.
_attempt_fail
()
@vial.test.do_as_user_decorator
(
vial
.
const
.
ROLE_DEVELOPER
)
def
test_02_as_developer
(
self
):
"""
Test access as user ``developer``.
"""
self
.
_attempt_fail
()
@vial.test.do_as_user_decorator
(
vial
.
const
.
ROLE_MAINTAINER
)
def
test_03_as_maintainer
(
self
):
"""
Test access as user ``maintainer``.
"""
self
.
_attempt_succeed
()
@vial.test.do_as_user_decorator
(
vial
.
const
.
ROLE_ADMIN
)
def
test_04_as_admin
(
self
):
"""
Test access as user ``admin``.
"""
self
.
_attempt_succeed
()
#-------------------------------------------------------------------------------
if
__name__
==
"
__main__
"
:
unittest
.
main
()
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