Skip to content
Snippets Groups Projects
Commit b29f7a50 authored by Jan Mach's avatar Jan Mach
Browse files

Implemented unit tests for 'hawat.blueprints.changelogs' module.

Also removed unnecessary docstrings.

(Redmine issue: #4410,#1017,#3443)
parent 1720b061
No related branches found
No related tags found
No related merge requests found
......@@ -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 &quot;%(item)s&quot;', 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),
......
#!/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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment