test_pagure_lib_plugins.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # coding=utf-8
  2. """
  3. (c) 2015-2018 - Copyright Red Hat Inc
  4. Authors:
  5. Slavek Kabrda <bkabrda@redhat.com>
  6. """
  7. from __future__ import unicode_literals, absolute_import
  8. import os
  9. import sys
  10. from mock import patch
  11. sys.path.insert(
  12. 0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
  13. )
  14. import pagure.hooks
  15. import pagure.lib.plugins
  16. import tests
  17. class EnabledForAll(pagure.hooks.BaseHook):
  18. name = "EnabledForAll"
  19. @classmethod
  20. def is_enabled_for(cls, project):
  21. return True
  22. class DisabledForAll(pagure.hooks.BaseHook):
  23. name = "DisabledForAll"
  24. # disabled for all is the default
  25. class PagureLibtests_plugins(tests.Modeltests):
  26. """
  27. Test the pagure.lib.plugins module
  28. """
  29. maxDiff = None
  30. @patch("pagure.lib.plugins.load")
  31. def test_plugin_is_enabled_for(self, load):
  32. """Test the is_enabled_for method of plugins is properly
  33. handled by pagure.lib.plugins.get_enabled_plugins.
  34. """
  35. tests.create_projects(self.session)
  36. project = pagure.lib.query._get_project(self.session, "test")
  37. load.return_value = [EnabledForAll]
  38. self.assertEqual(
  39. pagure.lib.plugins.get_enabled_plugins(project),
  40. [(EnabledForAll, None)],
  41. )
  42. load.return_value = [DisabledForAll]
  43. self.assertEqual(pagure.lib.plugins.get_enabled_plugins(project), [])
  44. @patch("pagure.lib.plugins.load")
  45. def test_get_plugin_names(self, load):
  46. """Test the get_plugin_names method with plugins that don't
  47. have backref.
  48. """
  49. load.return_value = [EnabledForAll]
  50. self.assertEqual(pagure.lib.plugins.get_plugin_names(), [])
  51. self.assertEqual(
  52. pagure.lib.plugins.get_plugin_names(without_backref=True),
  53. ["EnabledForAll"],
  54. )