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(0, os.path.join(os.path.dirname(
  12. os.path.abspath(__file__)), '..'))
  13. import pagure.hooks
  14. import pagure.lib.plugins
  15. import tests
  16. class EnabledForAll(pagure.hooks.BaseHook):
  17. name = "EnabledForAll"
  18. @classmethod
  19. def is_enabled_for(cls, project):
  20. return True
  21. class DisabledForAll(pagure.hooks.BaseHook):
  22. name = "DisabledForAll"
  23. # disabled for all is the default
  24. class PagureLibtests_plugins(tests.Modeltests):
  25. """
  26. Test the pagure.lib.plugins module
  27. """
  28. maxDiff = None
  29. @patch("pagure.lib.plugins.load")
  30. def test_plugin_is_enabled_for(self, load):
  31. """ Test the is_enabled_for method of plugins is properly
  32. handled by pagure.lib.plugins.get_enabled_plugins.
  33. """
  34. tests.create_projects(self.session)
  35. project = pagure.lib.query._get_project(self.session, "test")
  36. load.return_value = [EnabledForAll]
  37. self.assertEqual(
  38. pagure.lib.plugins.get_enabled_plugins(project),
  39. [(EnabledForAll, None)]
  40. )
  41. load.return_value = [DisabledForAll]
  42. self.assertEqual(
  43. pagure.lib.plugins.get_enabled_plugins(project),
  44. []
  45. )
  46. @patch("pagure.lib.plugins.load")
  47. def test_get_plugin_names(self, load):
  48. """ Test the get_plugin_names method with plugins that don't
  49. have backref.
  50. """
  51. load.return_value = [EnabledForAll]
  52. self.assertEqual(pagure.lib.plugins.get_plugin_names(), [])
  53. self.assertEqual(
  54. pagure.lib.plugins.get_plugin_names(without_backref=True),
  55. ['EnabledForAll']
  56. )