1
0

test_pagure_lib_plugins.py 1.9 KB

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