Blame tests/test_pagure_lib_plugins.py

Slavek Kabrda 370e67
# coding=utf-8
Slavek Kabrda 370e67
"""
Slavek Kabrda 370e67
 (c) 2015-2018 - Copyright Red Hat Inc
Slavek Kabrda 370e67
Slavek Kabrda 370e67
 Authors:
Slavek Kabrda 370e67
   Slavek Kabrda <bkabrda@redhat.com></bkabrda@redhat.com>
Slavek Kabrda 370e67
Slavek Kabrda 370e67
"""
Slavek Kabrda 370e67
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Slavek Kabrda 370e67
Slavek Kabrda 370e67
import os
Slavek Kabrda 370e67
import sys
Slavek Kabrda 370e67
Slavek Kabrda 370e67
from mock import patch
Slavek Kabrda 370e67
Slavek Kabrda 370e67
sys.path.insert(0, os.path.join(os.path.dirname(
Slavek Kabrda 370e67
    os.path.abspath(__file__)), '..'))
Slavek Kabrda 370e67
Slavek Kabrda 370e67
import pagure.hooks
Slavek Kabrda 370e67
import pagure.lib.plugins
Slavek Kabrda 370e67
import tests
Slavek Kabrda 370e67
Slavek Kabrda 370e67
Slavek Kabrda 370e67
class EnabledForAll(pagure.hooks.BaseHook):
Slavek Kabrda 370e67
    name = "EnabledForAll"
Slavek Kabrda 370e67
Slavek Kabrda 370e67
    @classmethod
Slavek Kabrda 370e67
    def is_enabled_for(cls, project):
Slavek Kabrda 370e67
        return True
Slavek Kabrda 370e67
Slavek Kabrda 370e67
class DisabledForAll(pagure.hooks.BaseHook):
Slavek Kabrda 370e67
    name = "DisabledForAll"
Slavek Kabrda 370e67
    # disabled for all is the default
Slavek Kabrda 370e67
Slavek Kabrda 370e67
class PagureLibtests_plugins(tests.Modeltests):
Slavek Kabrda 370e67
    """
Slavek Kabrda 370e67
    Test the pagure.lib.plugins module
Slavek Kabrda 370e67
    """
Slavek Kabrda 370e67
Slavek Kabrda 370e67
    maxDiff = None
Slavek Kabrda 370e67
Slavek Kabrda 370e67
    @patch("pagure.lib.plugins.load")
Slavek Kabrda 370e67
    def test_plugin_is_enabled_for(self, load):
Slavek Kabrda 370e67
        """ Test the is_enabled_for method of plugins is properly
Slavek Kabrda 370e67
        handled by pagure.lib.plugins.get_enabled_plugins.
Slavek Kabrda 370e67
        """
Slavek Kabrda 370e67
        tests.create_projects(self.session)
Slavek Kabrda 370e67
        project = pagure.lib.query._get_project(self.session, "test")
Slavek Kabrda 370e67
Slavek Kabrda 370e67
        load.return_value = [EnabledForAll]
Slavek Kabrda 370e67
        self.assertEqual(
Slavek Kabrda 370e67
            pagure.lib.plugins.get_enabled_plugins(project),
Slavek Kabrda 370e67
            [(EnabledForAll, None)]
Slavek Kabrda 370e67
        )
Slavek Kabrda 370e67
Slavek Kabrda 370e67
        load.return_value = [DisabledForAll]
Slavek Kabrda 370e67
        self.assertEqual(
Slavek Kabrda 370e67
            pagure.lib.plugins.get_enabled_plugins(project),
Slavek Kabrda 370e67
            []
Slavek Kabrda 370e67
        )
Slavek Kabrda 370e67
Slavek Kabrda 370e67
    @patch("pagure.lib.plugins.load")
Slavek Kabrda 370e67
    def test_get_plugin_names(self, load):
Slavek Kabrda 370e67
        """ Test the get_plugin_names method with plugins that don't
Slavek Kabrda 370e67
        have backref.
Slavek Kabrda 370e67
        """
Slavek Kabrda 370e67
        load.return_value = [EnabledForAll]
Slavek Kabrda 370e67
        self.assertEqual(pagure.lib.plugins.get_plugin_names(), [])
Slavek Kabrda 370e67
        self.assertEqual(
Slavek Kabrda 370e67
            pagure.lib.plugins.get_plugin_names(without_backref=True),
Slavek Kabrda 370e67
            ['EnabledForAll']
Slavek Kabrda 370e67
        )